-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: model loading and serialization tests factorization
- Loading branch information
Showing
43 changed files
with
564 additions
and
849 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import datetime | ||
|
||
from pydantic import AnyUrl | ||
|
||
from pydantic_scim2 import Address | ||
from pydantic_scim2 import Email | ||
from pydantic_scim2 import Im | ||
from pydantic_scim2 import PhoneNumber | ||
from pydantic_scim2 import Photo | ||
from pydantic_scim2 import User | ||
|
||
|
||
def test_enterprise_user(load_sample): | ||
payload = load_sample("rfc7643-8.3-user-enterprise_user.json") | ||
obj = User.model_validate(payload) | ||
|
||
assert obj.schemas == [ | ||
"urn:ietf:params:scim:schemas:core:2.0:User", | ||
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", | ||
] | ||
assert obj.id == "2819c223-7f76-453a-919d-413861904646" | ||
assert obj.external_id == "701984" | ||
assert obj.user_name == "[email protected]" | ||
assert obj.name | ||
assert obj.name.formatted == "Ms. Barbara J Jensen, III" | ||
assert obj.name.family_name == "Jensen" | ||
assert obj.name.given_name == "Barbara" | ||
assert obj.name.middle_name == "Jane" | ||
assert obj.name.honorific_prefix == "Ms." | ||
assert obj.name.honorific_suffix == "III" | ||
assert obj.display_name == "Babs Jensen" | ||
assert obj.nick_name == "Babs" | ||
assert obj.profile_url == AnyUrl("https://login.example.com/bjensen") | ||
assert obj.emails[0].value == "[email protected]" | ||
assert obj.emails[0].type == Email.Type.work | ||
assert obj.emails[0].primary is True | ||
assert obj.emails[1].value == "[email protected]" | ||
assert obj.emails[1].type == Email.Type.home | ||
assert obj.addresses[0].type == Address.Type.work | ||
assert obj.addresses[0].street_address == "100 Universal City Plaza" | ||
assert obj.addresses[0].locality == "Hollywood" | ||
assert obj.addresses[0].region == "CA" | ||
assert obj.addresses[0].postal_code == "91608" | ||
assert obj.addresses[0].country == "USA" | ||
assert ( | ||
obj.addresses[0].formatted | ||
== "100 Universal City Plaza\nHollywood, CA 91608 USA" | ||
) | ||
assert obj.addresses[0].primary is True | ||
assert obj.addresses[1].type == Address.Type.home | ||
assert obj.addresses[1].street_address == "456 Hollywood Blvd" | ||
assert obj.addresses[1].locality == "Hollywood" | ||
assert obj.addresses[1].region == "CA" | ||
assert obj.addresses[1].postal_code == "91608" | ||
assert obj.addresses[1].country == "USA" | ||
assert obj.addresses[1].formatted == "456 Hollywood Blvd\nHollywood, CA 91608 USA" | ||
assert obj.phone_numbers[0].value == "555-555-5555" | ||
assert obj.phone_numbers[0].type == PhoneNumber.Type.work | ||
assert obj.phone_numbers[1].value == "555-555-4444" | ||
assert obj.phone_numbers[1].type == PhoneNumber.Type.mobile | ||
assert obj.ims[0].value == "someaimhandle" | ||
assert obj.ims[0].type == Im.Type.aim | ||
assert obj.photos[0].value == AnyUrl( | ||
"https://photos.example.com/profilephoto/72930000000Ccne/F" | ||
) | ||
assert obj.photos[0].type == Photo.Type.photo | ||
assert obj.photos[1].value == AnyUrl( | ||
"https://photos.example.com/profilephoto/72930000000Ccne/T" | ||
) | ||
assert obj.photos[1].type == Photo.Type.thumbnail | ||
assert obj.user_type == "Employee" | ||
assert obj.title == "Tour Guide" | ||
assert obj.preferred_language == "en-US" | ||
assert obj.locale == "en-US" | ||
assert obj.timezone == "America/Los_Angeles" | ||
assert obj.active is True | ||
assert obj.password == "t1meMa$heen" | ||
assert obj.groups[0].value == "e9e30dba-f08f-4109-8486-d5c6a331660a" | ||
assert obj.groups[0].ref == AnyUrl( | ||
"https://example.com/v2/Groups/e9e30dba-f08f-4109-8486-d5c6a331660a" | ||
) | ||
assert obj.groups[0].display == "Tour Guides" | ||
assert obj.groups[1].value == "fc348aa8-3835-40eb-a20b-c726e15c55b5" | ||
assert obj.groups[1].ref == AnyUrl( | ||
"https://example.com/v2/Groups/fc348aa8-3835-40eb-a20b-c726e15c55b5" | ||
) | ||
assert obj.groups[1].display == "Employees" | ||
assert obj.groups[2].value == "71ddacd2-a8e7-49b8-a5db-ae50d0a5bfd7" | ||
assert obj.groups[2].ref == AnyUrl( | ||
"https://example.com/v2/Groups/71ddacd2-a8e7-49b8-a5db-ae50d0a5bfd7" | ||
) | ||
assert obj.groups[2].display == "US Employees" | ||
assert obj.x509_certificates[0].value == ( | ||
"MIIDQzCCAqygAwIBAgICEAAwDQYJKoZIhvcNAQEFBQAwTjELMAkGA1UEBhMCVVMx" | ||
"EzARBgNVBAgMCkNhbGlmb3JuaWExFDASBgNVBAoMC2V4YW1wbGUuY29tMRQwEgYD" | ||
"VQQDDAtleGFtcGxlLmNvbTAeFw0xMTEwMjIwNjI0MzFaFw0xMjEwMDQwNjI0MzFa" | ||
"MH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRQwEgYDVQQKDAtl" | ||
"eGFtcGxlLmNvbTEhMB8GA1UEAwwYTXMuIEJhcmJhcmEgSiBKZW5zZW4gSUlJMSIw" | ||
"IAYJKoZIhvcNAQkBFhNiamVuc2VuQGV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0B" | ||
"AQEFAAOCAQ8AMIIBCgKCAQEA7Kr+Dcds/JQ5GwejJFcBIP682X3xpjis56AK02bc" | ||
"1FLgzdLI8auoR+cC9/Vrh5t66HkQIOdA4unHh0AaZ4xL5PhVbXIPMB5vAPKpzz5i" | ||
"PSi8xO8SL7I7SDhcBVJhqVqr3HgllEG6UClDdHO7nkLuwXq8HcISKkbT5WFTVfFZ" | ||
"zidPl8HZ7DhXkZIRtJwBweq4bvm3hM1Os7UQH05ZS6cVDgweKNwdLLrT51ikSQG3" | ||
"DYrl+ft781UQRIqxgwqCfXEuDiinPh0kkvIi5jivVu1Z9QiwlYEdRbLJ4zJQBmDr" | ||
"SGTMYn4lRc2HgHO4DqB/bnMVorHB0CC6AV1QoFK4GPe1LwIDAQABo3sweTAJBgNV" | ||
"HRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZp" | ||
"Y2F0ZTAdBgNVHQ4EFgQU8pD0U0vsZIsaA16lL8En8bx0F/gwHwYDVR0jBBgwFoAU" | ||
"dGeKitcaF7gnzsNwDx708kqaVt0wDQYJKoZIhvcNAQEFBQADgYEAA81SsFnOdYJt" | ||
"Ng5Tcq+/ByEDrBgnusx0jloUhByPMEVkoMZ3J7j1ZgI8rAbOkNngX8+pKfTiDz1R" | ||
"C4+dx8oU6Za+4NJXUjlL5CvV6BEYb1+QAEJwitTVvxB/A67g42/vzgAtoRUeDov1" | ||
"+GFiBZ+GNF/cAYKcMtGcrs2i97ZkJMo=" | ||
) | ||
assert obj.meta.resource_type == "User" | ||
assert obj.meta.created == datetime.datetime( | ||
2010, 1, 23, 4, 56, 22, tzinfo=datetime.timezone.utc | ||
) | ||
assert obj.meta.last_modified == datetime.datetime( | ||
2011, 5, 13, 4, 42, 34, tzinfo=datetime.timezone.utc | ||
) | ||
assert obj.meta.version == 'W\\/"3694e05e9dff591"' | ||
assert ( | ||
obj.meta.location | ||
== "https://example.com/v2/Users/2819c223-7f76-453a-919d-413861904646" | ||
) | ||
|
||
# TODO: implement assertions for this | ||
# "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": { | ||
# "employeeNumber": "701984", | ||
# "costCenter": "4130", | ||
# "organization": "Universal Studios", | ||
# "division": "Theme Park", | ||
# "department": "Tour Operations", | ||
# "manager": { | ||
# "value": "26118915-6090-4610-87e4-49d8ca9f808d", | ||
# # TODO: relative URL are not supported by pydantic. Is this an error in the spec? | ||
# #"$ref": "../Users/26118915-6090-4610-87e4-49d8ca9f808d", | ||
# "$ref": "https://example.com/v2/Users/26118915-6090-4610-87e4-49d8ca9f808d", | ||
# "displayName": "John Smith", | ||
# }, | ||
# }, | ||
|
||
assert ( | ||
obj.model_dump( | ||
exclude_none=True, exclude_unset=True, by_alias=True, mode="json" | ||
) | ||
== payload | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import datetime | ||
|
||
from pydantic import AnyUrl | ||
|
||
from pydantic_scim2 import Group | ||
|
||
|
||
def test_group(load_sample): | ||
payload = load_sample("rfc7643-8.4-group.json") | ||
obj = Group.model_validate(payload) | ||
|
||
assert obj.schemas == ["urn:ietf:params:scim:schemas:core:2.0:Group"] | ||
assert obj.id == "e9e30dba-f08f-4109-8486-d5c6a331660a" | ||
assert obj.display_name == "Tour Guides" | ||
assert obj.members[0].value == "2819c223-7f76-453a-919d-413861904646" | ||
assert obj.members[0].ref == AnyUrl( | ||
"https://example.com/v2/Users/2819c223-7f76-453a-919d-413861904646" | ||
) | ||
assert obj.members[0].display == "Babs Jensen" | ||
assert obj.members[1].value == "902c246b-6245-4190-8e05-00816be7344a" | ||
assert obj.members[1].ref == AnyUrl( | ||
"https://example.com/v2/Users/902c246b-6245-4190-8e05-00816be7344a" | ||
) | ||
assert obj.members[1].display == "Mandy Pepperidge" | ||
assert obj.meta.resource_type == "Group" | ||
assert obj.meta.created == datetime.datetime( | ||
2010, 1, 23, 4, 56, 22, tzinfo=datetime.timezone.utc | ||
) | ||
assert obj.meta.last_modified == datetime.datetime( | ||
2011, 5, 13, 4, 42, 34, tzinfo=datetime.timezone.utc | ||
) | ||
assert obj.meta.version == 'W\\/"3694e05e9dff592"' | ||
assert ( | ||
obj.meta.location | ||
== "https://example.com/v2/Groups/e9e30dba-f08f-4109-8486-d5c6a331660a" | ||
) | ||
|
||
assert ( | ||
obj.model_dump( | ||
exclude_none=True, exclude_unset=True, by_alias=True, mode="json" | ||
) | ||
== payload | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.