diff --git a/pydantic_scim2/group.py b/pydantic_scim2/group.py index f648ad2..91a6f85 100644 --- a/pydantic_scim2/group.py +++ b/pydantic_scim2/group.py @@ -6,6 +6,8 @@ from pydantic import ConfigDict from pydantic import Field +from .resource import Resource + class GroupMember(BaseModel): model_config = ConfigDict(populate_by_name=True) @@ -19,12 +21,11 @@ class GroupMember(BaseModel): ) -class Group(BaseModel): - id: Optional[str] = None +class Group(Resource): + schemas: List[str] = ["urn:ietf:params:scim:schemas:core:2.0:Group"] displayName: str = Field( ..., description="A human-readable name for the Group. REQUIRED." ) members: Optional[List[GroupMember]] = Field( None, description="A list of members of the Group." ) - schemas: List[str] = {"urn:ietf:params:scim:schemas:core:2.0:Group"} diff --git a/tests/test_models.py b/tests/test_models.py index 382e7b1..9d5d142 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,9 +1,11 @@ import datetime +import pytest from pydantic import AnyUrl from pydantic_scim2 import AddressKind from pydantic_scim2 import EmailKind +from pydantic_scim2 import Group from pydantic_scim2 import ImKind from pydantic_scim2 import PhoneNumberKind from pydantic_scim2 import PhotoKind @@ -138,3 +140,36 @@ def test_full_user(full_user_payload): obj.meta.location == "https://example.com/v2/Users/2819c223-7f76-453a-919d-413861904646" ) + + +@pytest.mark.skip +def test_enterprise_user(full_enterprise_payload): ... + + +def test_group(group_payload): + obj = Group.model_validate(group_payload) + assert obj.schemas == ["urn:ietf:params:scim:schemas:core:2.0:Group"] + assert obj.id == "e9e30dba-f08f-4109-8486-d5c6a331660a" + assert obj.displayName == "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.resourceType == "Group" + assert obj.meta.created == datetime.datetime( + 2010, 1, 23, 4, 56, 22, tzinfo=datetime.timezone.utc + ) + assert obj.meta.lastModified == 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" + )