Skip to content

Commit c6009da

Browse files
committed
Fix check_resource_model if resource_models was created from schemas
1 parent 69e4f02 commit c6009da

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

scim2_client/client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,18 @@ def get_resource_model(self, name: str) -> Optional[type[Resource]]:
183183
def check_resource_model(
184184
self, resource_model: type[Resource], payload=None
185185
) -> None:
186+
# We need to check the actual schema names, comapring the class
187+
# types does not work because if the resource_models are
188+
# discovered. The classes might differ:
189+
# <class 'scim2_models.rfc7643.user.User'> vs <class 'scim2_models.rfc7643.schema.User'>
190+
schema_to_check = resource_model.model_fields["schemas"].default[0]
191+
for element in self.resource_models:
192+
schema = element.model_fields["schemas"].default[0]
193+
if schema_to_check == schema:
194+
return
195+
186196
if (
187-
resource_model not in self.resource_models
188-
and resource_model not in CONFIG_RESOURCES
197+
resource_model not in CONFIG_RESOURCES
189198
):
190199
raise SCIMRequestError(
191200
f"Unknown resource type: '{resource_model}'", source=payload

tests/test_discovery.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@ def test_discovery_resource_types_multiple_extensions(server):
8888
scim_client.discover()
8989
assert scim_client.get_resource_model("User")
9090
assert scim_client.get_resource_model("Group")
91+
92+
# Try to create a user to see if discover filled everything correctly
93+
user_request = User[Union[EnterpriseUser, OtherExtension]](user_name="bjensen@example.com")
94+
scim_client.create(user_request)

0 commit comments

Comments
 (0)