Skip to content

Commit e3f68eb

Browse files
committed
test user api
1 parent 59d1eb6 commit e3f68eb

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

descope/management/user.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def update(
346346
verified_phone: Optional[bool] = None,
347347
additional_login_ids: Optional[List[str]] = None,
348348
sso_app_ids: Optional[List[str]] = None,
349+
test: bool = False,
349350
) -> dict:
350351
"""
351352
Update an existing user with the given various fields. IMPORTANT: All parameters are used as overrides
@@ -367,6 +368,7 @@ def update(
367368
picture (str): Optional url for user picture
368369
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
369370
sso_app_ids (List[str]): Optional, list of SSO applications IDs to be associated with the user.
371+
test (bool, optional): Set to True to update a test user. Defaults to False.
370372
371373
Return value (dict):
372374
Return dict in the format
@@ -391,7 +393,7 @@ def update(
391393
family_name,
392394
role_names,
393395
user_tenants,
394-
False,
396+
test,
395397
picture,
396398
custom_attributes,
397399
verified_email,
@@ -420,6 +422,7 @@ def patch(
420422
verified_email: Optional[bool] = None,
421423
verified_phone: Optional[bool] = None,
422424
sso_app_ids: Optional[List[str]] = None,
425+
test: bool = False,
423426
) -> dict:
424427
"""
425428
Patches an existing user with the given various fields. Only the given fields will be used to update the user.
@@ -439,6 +442,7 @@ def patch(
439442
picture (str): Optional url for user picture
440443
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
441444
sso_app_ids (List[str]): Optional, list of SSO applications IDs to be associated with the user.
445+
test (bool, optional): Set to True to update a test user. Defaults to False.
442446
443447
Return value (dict):
444448
Return dict in the format
@@ -465,6 +469,7 @@ def patch(
465469
verified_email,
466470
verified_phone,
467471
sso_app_ids,
472+
test,
468473
),
469474
pswd=self._auth.management_key,
470475
)
@@ -1936,6 +1941,7 @@ def _compose_patch_body(
19361941
verified_email: Optional[bool],
19371942
verified_phone: Optional[bool],
19381943
sso_app_ids: Optional[List[str]],
1944+
test: bool = False,
19391945
) -> dict:
19401946
res: dict[str, Any] = {
19411947
"loginId": login_id,
@@ -1966,4 +1972,6 @@ def _compose_patch_body(
19661972
res["verifiedPhone"] = verified_phone
19671973
if sso_app_ids is not None:
19681974
res["ssoAppIds"] = sso_app_ids
1975+
if test:
1976+
res["test"] = test
19691977
return res

tests/management/test_user.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,9 @@ def test_generate_sign_up_embedded_link(self):
24192419
with patch("requests.post") as mock_post:
24202420
mock_post.return_value.ok = False
24212421
self.assertRaises(
2422-
AuthException, self.client.mgmt.user.generate_sign_up_embedded_link, "login-id"
2422+
AuthException,
2423+
self.client.mgmt.user.generate_sign_up_embedded_link,
2424+
"login-id",
24232425
)
24242426

24252427
# Test success flow
@@ -2519,3 +2521,73 @@ def test_history(self):
25192521
params=None,
25202522
timeout=DEFAULT_TIMEOUT_SECONDS,
25212523
)
2524+
2525+
def test_update_test_user(self):
2526+
with patch("requests.post") as mock_post:
2527+
network_resp = mock.Mock()
2528+
network_resp.ok = True
2529+
network_resp.json.return_value = json.loads('{"user": {"id": "u1"}}')
2530+
mock_post.return_value = network_resp
2531+
resp = self.client.mgmt.user.update(
2532+
"id",
2533+
display_name="test-user",
2534+
test=True,
2535+
)
2536+
user = resp["user"]
2537+
self.assertEqual(user["id"], "u1")
2538+
mock_post.assert_called_with(
2539+
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_update_path}",
2540+
headers={
2541+
**common.default_headers,
2542+
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
2543+
"x-descope-project-id": self.dummy_project_id,
2544+
},
2545+
params=None,
2546+
json={
2547+
"loginId": "id",
2548+
"email": None,
2549+
"phone": None,
2550+
"displayName": "test-user",
2551+
"roleNames": [],
2552+
"userTenants": [],
2553+
"test": True,
2554+
"picture": None,
2555+
"customAttributes": None,
2556+
"additionalLoginIds": None,
2557+
"ssoAppIDs": None,
2558+
},
2559+
allow_redirects=False,
2560+
verify=True,
2561+
timeout=DEFAULT_TIMEOUT_SECONDS,
2562+
)
2563+
2564+
def test_patch_test_user(self):
2565+
with patch("requests.patch") as mock_patch:
2566+
network_resp = mock.Mock()
2567+
network_resp.ok = True
2568+
network_resp.json.return_value = json.loads('{"user": {"id": "u1"}}')
2569+
mock_patch.return_value = network_resp
2570+
resp = self.client.mgmt.user.patch(
2571+
"id",
2572+
display_name="test-user",
2573+
test=True,
2574+
)
2575+
user = resp["user"]
2576+
self.assertEqual(user["id"], "u1")
2577+
mock_patch.assert_called_with(
2578+
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_patch_path}",
2579+
headers={
2580+
**common.default_headers,
2581+
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
2582+
"x-descope-project-id": self.dummy_project_id,
2583+
},
2584+
params=None,
2585+
json={
2586+
"loginId": "id",
2587+
"displayName": "test-user",
2588+
"test": True,
2589+
},
2590+
allow_redirects=False,
2591+
verify=True,
2592+
timeout=DEFAULT_TIMEOUT_SECONDS,
2593+
)

0 commit comments

Comments
 (0)