Skip to content

Commit

Permalink
fix: ResourceType missing attributes and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed May 24, 2024
1 parent 8f181b8 commit c3b2f36
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pydantic_scim2/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ class Meta(BaseModel):
sub-attributes:
"""

resourceType: str
resourceType: Optional[str] = None
"""The name of the resource type of the resource.
This attribute has a mutability of "readOnly" and "caseExact" as
"true".
"""

created: datetime
created: Optional[datetime] = None
"""The "DateTime" that the resource was added to the service provider.
This attribute MUST be a DateTime.
"""

lastModified: datetime
lastModified: Optional[datetime] = None
"""The most recent DateTime that the details of this resource were updated
at the service provider.
If this resource has never been modified since its initial creation,
the value MUST be the same as the value of "created".
"""

location: str
location: Optional[str] = None
"""The URI of the resource being returned.
This value MUST be the same as the "Content-Location" HTTP response
header (see Section 3.1.4.2 of [RFC7231]).
"""

version: str
version: Optional[str] = None
"""The version of the resource being returned.
This value must be the same as the entity-tag (ETag) HTTP response
Expand Down
52 changes: 51 additions & 1 deletion pydantic_scim2/resource_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from pydantic import ConfigDict
from pydantic import Field

from .resource import Meta
from .resource import Resource


class SchemaExtension(BaseModel):
model_config = ConfigDict(extra="allow")
Expand All @@ -19,9 +22,56 @@ class SchemaExtension(BaseModel):
)


class ResourceType(BaseModel):
class ResourceType(Resource):
model_config = ConfigDict(extra="allow")

# Each SCIM resource (Users, Groups, etc.) includes the following
# common attributes. With the exception of the "ServiceProviderConfig"
# and "ResourceType" server discovery endpoints and their associated
# resources, these attributes MUST be defined for all resources,
# including any extended resource types.

id: Optional[str] = None
"""A unique identifier for a SCIM resource as defined by the service
provider.
Each representation of the resource MUST include a non-empty "id"
value. This identifier MUST be unique across the SCIM service
provider's entire set of resources. It MUST be a stable, non-
reassignable identifier that does not change when the same resource
is returned in subsequent requests. The value of the "id" attribute
is always issued by the service provider and MUST NOT be specified
by the client. The string "bulkId" is a reserved keyword and MUST
NOT be used within any unique identifier value. The attribute
characteristics are "caseExact" as "true", a mutability of
"readOnly", and a "returned" characteristic of "always". See
Section 9 for additional considerations regarding privacy.
"""

externalId: Optional[str] = None
"""A String that is an identifier for the resource as defined by the
provisioning client.
The "externalId" may simplify identification of a resource between
the provisioning client and the service provider by allowing the
client to use a filter to locate the resource with an identifier
from the provisioning domain, obviating the need to store a local
mapping between the provisioning domain's identifier of the resource
and the identifier used by the service provider. Each resource MAY
include a non-empty "externalId" value. The value of the
"externalId" attribute is always issued by the provisioning client
and MUST NOT be specified by the service provider. The service
provider MUST always interpret the externalId as scoped to the
provisioning domain. While the server does not enforce uniqueness,
it is assumed that the value's uniqueness is controlled by the
client setting the value. See Section 9 for additional
considerations regarding privacy. This attribute has "caseExact" as
"true" and a mutability of "readWrite". This attribute is OPTIONAL.
"""

meta: Optional[Meta] = None
"""A complex attribute containing resource metadata."""

id: Optional[str] = Field(
None,
description="The resource type's server unique id. May be the same as the 'name' attribute.",
Expand Down
28 changes: 28 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pydantic_scim2 import ImKind
from pydantic_scim2 import PhoneNumberKind
from pydantic_scim2 import PhotoKind
from pydantic_scim2 import ResourceType
from pydantic_scim2 import ServiceProviderConfiguration
from pydantic_scim2 import User

Expand Down Expand Up @@ -233,3 +234,30 @@ def test_service_provider_configuration(service_provider_configuration_payload):
2011, 5, 13, 4, 42, 34, tzinfo=datetime.timezone.utc
)
assert obj.meta.version == 'W\\/"3694e05e9dff594"'


def test_resource_type(resource_type_payload):
obj = ResourceType.model_validate(resource_type_payload[0])

assert obj.schemas == ["urn:ietf:params:scim:schemas:core:2.0:ResourceType"]
assert obj.id == "User"
assert obj.name == "User"
assert obj.endpoint == "/Users"
assert obj.description == "User Account"
assert obj.schema_ == AnyUrl("urn:ietf:params:scim:schemas:core:2.0:User")
assert obj.schemaExtensions[0].schema_ == AnyUrl(
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"
)
assert obj.schemaExtensions[0].required is True
assert obj.meta.location == "https://example.com/v2/ResourceTypes/User"
assert obj.meta.resourceType == "ResourceType"

obj = ResourceType.model_validate(resource_type_payload[1])
assert obj.schemas == ["urn:ietf:params:scim:schemas:core:2.0:ResourceType"]
assert obj.id == "Group"
assert obj.name == "Group"
assert obj.endpoint == "/Groups"
assert obj.description == "Group"
assert obj.schema_ == AnyUrl("urn:ietf:params:scim:schemas:core:2.0:Group")
assert obj.meta.location == "https://example.com/v2/ResourceTypes/Group"
assert obj.meta.resourceType == "ResourceType"

0 comments on commit c3b2f36

Please sign in to comment.