Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysyngsun committed Jan 29, 2025
1 parent 333d675 commit 95e058c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 11 additions & 0 deletions scim/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ def parse_path_and_values(

return super().parse_path_and_values(path, value)

def validate_email(self, *args, **kwargs):
print("validate_email")
print((args, kwargs))
result = super().validate_email(*args, **kwargs)
return result

def handle_replace(
self,
path: Optional[AttrPath],
Expand All @@ -219,11 +225,16 @@ def handle_replace(
All operations happen within an atomic transaction.
"""

if not isinstance(value, dict):
print("not a dict")
print((path, value))
# Restructure for use in loop below.
value = {path: value}

print(value)
for nested_path, nested_value in (value or {}).items():
print((nested_path, nested_value))
if nested_path.first_path in self.ATTR_MAP:
setattr(
self.obj, self.ATTR_MAP.get(nested_path.first_path), nested_value
Expand Down
14 changes: 10 additions & 4 deletions scim/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import operator
import random
from functools import reduce
from types import SimpleNamespace

from anys import ANY_STR
Expand Down Expand Up @@ -141,7 +142,7 @@ def _user_to_scim_payload(user):
"schemas": [djs_constants.SchemaURI.USER],
"emails": [{"value": user.email, "primary": True}],
"userName": user.username,
"emailOptIn": user.profile.email_optin,
"emailOptIn": 1 if user.profile.email_optin else 0,
"fullName": user.profile.name,
"name": {
"givenName": user.first_name,
Expand All @@ -162,8 +163,8 @@ def _user_to_scim_payload(user):
USER_FIELDS_TO_SCIM: dict[str, Callable] = {
"username": lambda value: {"userName": value},
"email": lambda value: {"emails": [{"value": value, "primary": True}]},
"first_name": lambda value: {"profile": {"givenName": value}},
"last_name": lambda value: {"profile": {"familyName": value}},
"first_name": lambda value: {"name": {"givenName": value}},
"last_name": lambda value: {"name": {"familyName": value}},
"profile.email_optin": lambda value: {"emailOptIn": 1 if value else 0},
"profile.name": lambda value: {"fullName": value},
}
Expand Down Expand Up @@ -239,7 +240,11 @@ def _expected_patch_value(field):
"Operations": [
{
"op": "replace",
"value": always_merger.merge(*field_updates)
"value": reduce(
always_merger.merge,
field_updates,
{}
)
}
],
},
Expand Down Expand Up @@ -383,6 +388,7 @@ def test_bulk_post(staff_client, bulk_test_data):
}

for operation in bulk_test_data.operations:
print(operation.payload)
assert (
results_by_bulk_id[operation.payload["bulkId"]]
== operation.expected_response
Expand Down

0 comments on commit 95e058c

Please sign in to comment.