Skip to content

Commit

Permalink
tests: model loading and serialization tests factorization
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed May 26, 2024
1 parent 1cfe175 commit 2b903b0
Show file tree
Hide file tree
Showing 43 changed files with 564 additions and 849 deletions.
File renamed without changes.
147 changes: 147 additions & 0 deletions tests/test_enterprise_user.py
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"
"EzARBgNVBAgMCkNhbG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"+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
)
43 changes: 43 additions & 0 deletions tests/test_group.py
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
)
8 changes: 4 additions & 4 deletions tests/test_responses.py → tests/test_list_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_user_response(load_sample):
resource_payload = load_sample("rfc7643-8.1-minimal_user_payload.json")
resource_payload = load_sample("rfc7643-8.1-user-minimal.json")
payload = {
"totalResults": 1,
"itemsPerPage": 10,
Expand All @@ -20,7 +20,7 @@ def test_user_response(load_sample):


def test_enterprise_user_response(load_sample):
resource_payload = load_sample("rfc7643-8.3-enterprise_user.json")
resource_payload = load_sample("rfc7643-8.3-user-enterprise_user.json")
payload = {
"totalResults": 1,
"itemsPerPage": 10,
Expand Down Expand Up @@ -66,8 +66,8 @@ def test_service_provider_configuration_response(load_sample):
def test_resource_type_response(load_sample):
"""https://datatracker.ietf.org/doc/html/rfc7644#section-4"""

user_resource_type_payload = load_sample("rfc7643-8.6-user_resource_type.json")
group_resource_type_payload = load_sample("rfc7643-8.6-group_resource_type.json")
user_resource_type_payload = load_sample("rfc7643-8.6-resource_type-user.json")
group_resource_type_payload = load_sample("rfc7643-8.6-resource_type-group.json")
payload = {
"totalResults": 2,
"itemsPerPage": 10,
Expand Down
Loading

0 comments on commit 2b903b0

Please sign in to comment.