Skip to content

Commit ef62fb1

Browse files
authored
Return user response in update/patch user (#500)
1 parent 393ac69 commit ef62fb1

File tree

2 files changed

+75
-51
lines changed

2 files changed

+75
-51
lines changed

descope/management/user.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def update(
326326
verified_phone: Optional[bool] = None,
327327
additional_login_ids: Optional[List[str]] = None,
328328
sso_app_ids: Optional[List[str]] = None,
329-
):
329+
) -> dict:
330330
"""
331331
Update an existing user with the given various fields. IMPORTANT: All parameters are used as overrides
332332
to the existing user. Empty fields will override populated fields. Use carefully.
@@ -348,13 +348,18 @@ def update(
348348
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
349349
sso_app_ids (List[str]): Optional, list of SSO applications IDs to be associated with the user.
350350
351+
Return value (dict):
352+
Return dict in the format
353+
{"user": {}}
354+
Containing the updated user information.
355+
351356
Raise:
352357
AuthException: raised if update operation fails
353358
"""
354359
role_names = [] if role_names is None else role_names
355360
user_tenants = [] if user_tenants is None else user_tenants
356361

357-
self._auth.do_post(
362+
response = self._auth.do_post(
358363
MgmtV1.user_update_path,
359364
User._compose_update_body(
360365
login_id,
@@ -377,6 +382,7 @@ def update(
377382
),
378383
pswd=self._auth.management_key,
379384
)
385+
return response.json()
380386

381387
def patch(
382388
self,
@@ -394,7 +400,7 @@ def patch(
394400
verified_email: Optional[bool] = None,
395401
verified_phone: Optional[bool] = None,
396402
sso_app_ids: Optional[List[str]] = None,
397-
):
403+
) -> dict:
398404
"""
399405
Patches an existing user with the given various fields. Only the given fields will be used to update the user.
400406
@@ -414,10 +420,15 @@ def patch(
414420
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
415421
sso_app_ids (List[str]): Optional, list of SSO applications IDs to be associated with the user.
416422
423+
Return value (dict):
424+
Return dict in the format
425+
{"user": {}}
426+
Containing the patched user information.
427+
417428
Raise:
418429
AuthException: raised if patch operation fails
419430
"""
420-
self._auth.do_patch(
431+
response = self._auth.do_patch(
421432
MgmtV1.user_patch_path,
422433
User._compose_patch_body(
423434
login_id,
@@ -437,6 +448,7 @@ def patch(
437448
),
438449
pswd=self._auth.management_key,
439450
)
451+
return response.json()
440452

441453
def delete(
442454
self,

tests/management/test_user.py

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,20 @@ def test_update(self):
445445

446446
# Test success flow
447447
with patch("requests.post") as mock_post:
448-
mock_post.return_value.ok = True
449-
self.assertIsNone(
450-
self.client.mgmt.user.update(
451-
"id",
452-
display_name="new-name",
453-
role_names=["domain.com"],
454-
picture="https://test.com",
455-
custom_attributes={"ak": "av"},
456-
sso_app_ids=["app1", "app2"],
457-
)
448+
network_resp = mock.Mock()
449+
network_resp.ok = True
450+
network_resp.json.return_value = json.loads("""{"user": {"id": "u1"}}""")
451+
mock_post.return_value = network_resp
452+
resp = self.client.mgmt.user.update(
453+
"id",
454+
display_name="new-name",
455+
role_names=["domain.com"],
456+
picture="https://test.com",
457+
custom_attributes={"ak": "av"},
458+
sso_app_ids=["app1", "app2"],
458459
)
460+
user = resp["user"]
461+
self.assertEqual(user["id"], "u1")
459462
mock_post.assert_called_with(
460463
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_update_path}",
461464
headers={
@@ -482,12 +485,15 @@ def test_update(self):
482485
)
483486
# Test success flow with verified flags
484487
with patch("requests.post") as mock_post:
485-
mock_post.return_value.ok = True
486-
self.assertIsNone(
487-
self.client.mgmt.user.update(
488-
"id", verified_email=True, verified_phone=False
489-
)
488+
network_resp = mock.Mock()
489+
network_resp.ok = True
490+
network_resp.json.return_value = json.loads("""{"user": {"id": "u1"}}""")
491+
mock_post.return_value = network_resp
492+
resp = self.client.mgmt.user.update(
493+
"id", verified_email=True, verified_phone=False
490494
)
495+
user = resp["user"]
496+
self.assertEqual(user["id"], "u1")
491497
mock_post.assert_called_with(
492498
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_update_path}",
493499
headers={
@@ -528,21 +534,24 @@ def test_patch(self):
528534

529535
# Test success flow with some params set
530536
with patch("requests.patch") as mock_patch:
531-
mock_patch.return_value.ok = True
532-
self.assertIsNone(
533-
self.client.mgmt.user.patch(
534-
"id",
535-
display_name="new-name",
536-
email=None,
537-
phone=None,
538-
given_name=None,
539-
role_names=["domain.com"],
540-
user_tenants=None,
541-
picture="https://test.com",
542-
custom_attributes={"ak": "av"},
543-
sso_app_ids=["app1", "app2"],
544-
)
537+
network_resp = mock.Mock()
538+
network_resp.ok = True
539+
network_resp.json.return_value = json.loads("""{"user": {"id": "u1"}}""")
540+
mock_patch.return_value = network_resp
541+
resp = self.client.mgmt.user.patch(
542+
"id",
543+
display_name="new-name",
544+
email=None,
545+
phone=None,
546+
given_name=None,
547+
role_names=["domain.com"],
548+
user_tenants=None,
549+
picture="https://test.com",
550+
custom_attributes={"ak": "av"},
551+
sso_app_ids=["app1", "app2"],
545552
)
553+
user = resp["user"]
554+
self.assertEqual(user["id"], "u1")
546555
mock_patch.assert_called_with(
547556
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_patch_path}",
548557
headers={
@@ -564,25 +573,28 @@ def test_patch(self):
564573
)
565574
# Test success flow with other params
566575
with patch("requests.patch") as mock_patch:
567-
mock_patch.return_value.ok = True
568-
self.assertIsNone(
569-
self.client.mgmt.user.patch(
570-
"id",
571-
572-
phone="+123456789",
573-
given_name="given",
574-
middle_name="middle",
575-
family_name="family",
576-
role_names=None,
577-
user_tenants=[
578-
AssociatedTenant("tenant1"),
579-
AssociatedTenant("tenant2", ["role1", "role2"]),
580-
],
581-
custom_attributes=None,
582-
verified_email=True,
583-
verified_phone=False,
584-
)
576+
network_resp = mock.Mock()
577+
network_resp.ok = True
578+
network_resp.json.return_value = json.loads("""{"user": {"id": "u1"}}""")
579+
mock_patch.return_value = network_resp
580+
resp = self.client.mgmt.user.patch(
581+
"id",
582+
583+
phone="+123456789",
584+
given_name="given",
585+
middle_name="middle",
586+
family_name="family",
587+
role_names=None,
588+
user_tenants=[
589+
AssociatedTenant("tenant1"),
590+
AssociatedTenant("tenant2", ["role1", "role2"]),
591+
],
592+
custom_attributes=None,
593+
verified_email=True,
594+
verified_phone=False,
585595
)
596+
user = resp["user"]
597+
self.assertEqual(user["id"], "u1")
586598
mock_patch.assert_called_with(
587599
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_patch_path}",
588600
headers={

0 commit comments

Comments
 (0)