Skip to content

Commit

Permalink
tests: Group model test
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed May 24, 2024
1 parent 3a1d9b4 commit dc48100
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pydantic_scim2/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"}
35 changes: 35 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
)

0 comments on commit dc48100

Please sign in to comment.