22from typing import Annotated
33from typing import Optional
44
5- import pytest
6-
75from scim2_models .annotations import Required
86from scim2_models .annotations import Returned
97from scim2_models .attributes import ComplexAttribute
1513from scim2_models .rfc7643 .resource import Resource
1614from scim2_models .rfc7643 .user import User
1715from scim2_models .rfc7644 .error import Error
18- from scim2_models .scim_object import validate_attribute_urn
16+ from scim2_models .urn import validate_attribute_urn
1917
2018
2119class Sub (ComplexAttribute ):
@@ -74,32 +72,18 @@ def test_validate_attribute_urn():
7472 validate_attribute_urn ("urn:example:2.0:Foo:bar" , Foo )
7573 == "urn:example:2.0:Foo:bar"
7674 )
77- assert (
78- validate_attribute_urn ("urn:example:2.0:Foo:bar" , User , resource_types = [Foo ])
79- == "urn:example:2.0:Foo:bar"
80- )
8175
8276 assert validate_attribute_urn ("sub" , Foo ) == "urn:example:2.0:Foo:sub"
8377 assert (
8478 validate_attribute_urn ("urn:example:2.0:Foo:sub" , Foo )
8579 == "urn:example:2.0:Foo:sub"
8680 )
87- assert (
88- validate_attribute_urn ("urn:example:2.0:Foo:sub" , User , resource_types = [Foo ])
89- == "urn:example:2.0:Foo:sub"
90- )
9181
9282 assert validate_attribute_urn ("sub.always" , Foo ) == "urn:example:2.0:Foo:sub.always"
9383 assert (
9484 validate_attribute_urn ("urn:example:2.0:Foo:sub.always" , Foo )
9585 == "urn:example:2.0:Foo:sub.always"
9686 )
97- assert (
98- validate_attribute_urn (
99- "urn:example:2.0:Foo:sub.always" , User , resource_types = [Foo ]
100- )
101- == "urn:example:2.0:Foo:sub.always"
102- )
10387
10488 assert validate_attribute_urn ("snakeCase" , Foo ) == "urn:example:2.0:Foo:snakeCase"
10589 assert (
@@ -111,37 +95,18 @@ def test_validate_attribute_urn():
11195 validate_attribute_urn ("urn:example:2.0:MyExtension:baz" , Foo [MyExtension ])
11296 == "urn:example:2.0:MyExtension:baz"
11397 )
98+
99+ assert validate_attribute_urn ("urn:InvalidResource:bar" , Foo ) is None
100+
101+ assert validate_attribute_urn ("urn:example:2.0:Foo:invalid" , Foo ) is None
102+
103+ assert validate_attribute_urn ("bar.invalid" , Foo ) is None
104+
114105 assert (
115- validate_attribute_urn (
116- "urn:example:2.0:MyExtension:baz" , resource_types = [Foo [MyExtension ]]
117- )
118- == "urn:example:2.0:MyExtension:baz"
106+ validate_attribute_urn ("urn:example:2.0:MyExtension:invalid" , Foo [MyExtension ])
107+ is None
119108 )
120109
121- with pytest .raises (ValueError , match = "No default schema and relative URN" ):
122- validate_attribute_urn ("bar" , resource_types = [Foo ])
123-
124- with pytest .raises (
125- ValueError , match = "No resource matching schema 'urn:InvalidResource'"
126- ):
127- validate_attribute_urn ("urn:InvalidResource:bar" , Foo )
128-
129- with pytest .raises (
130- ValueError , match = "No resource matching schema 'urn:example:2.0:Foo'"
131- ):
132- validate_attribute_urn ("urn:example:2.0:Foo:bar" )
133-
134- with pytest .raises (
135- ValueError , match = "Model 'Foo' has no attribute named 'invalid'"
136- ):
137- validate_attribute_urn ("urn:example:2.0:Foo:invalid" , Foo )
138-
139- with pytest .raises (
140- ValueError ,
141- match = "Attribute 'bar' is not a complex attribute, and cannot have a 'invalid' sub-attribute" ,
142- ):
143- validate_attribute_urn ("bar.invalid" , Foo )
144-
145110
146111def test_payload_attribute_case_sensitivity ():
147112 """RFC7643 §2.1 indicates that attribute names should be case insensitive.
0 commit comments