Skip to content

Commit 0600152

Browse files
authored
[Fix] Test user APIs (#609)
1 parent 59d1eb6 commit 0600152

File tree

2 files changed

+84
-3
lines changed

2 files changed

+84
-3
lines changed

descope/management/user.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def invite(
250250
additional_login_ids: Optional[List[str]] = None,
251251
sso_app_ids: Optional[List[str]] = None,
252252
template_id: str = "",
253+
test: bool = False,
253254
) -> dict:
254255
"""
255256
Create a new user and invite them via an email / text message.
@@ -278,7 +279,7 @@ def invite(
278279
role_names,
279280
user_tenants,
280281
True,
281-
False,
282+
test,
282283
picture,
283284
custom_attributes,
284285
verified_email,
@@ -346,6 +347,7 @@ def update(
346347
verified_phone: Optional[bool] = None,
347348
additional_login_ids: Optional[List[str]] = None,
348349
sso_app_ids: Optional[List[str]] = None,
350+
test: bool = False,
349351
) -> dict:
350352
"""
351353
Update an existing user with the given various fields. IMPORTANT: All parameters are used as overrides
@@ -367,6 +369,7 @@ def update(
367369
picture (str): Optional url for user picture
368370
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
369371
sso_app_ids (List[str]): Optional, list of SSO applications IDs to be associated with the user.
372+
test (bool, optional): Set to True to update a test user. Defaults to False.
370373
371374
Return value (dict):
372375
Return dict in the format
@@ -391,7 +394,7 @@ def update(
391394
family_name,
392395
role_names,
393396
user_tenants,
394-
False,
397+
test,
395398
picture,
396399
custom_attributes,
397400
verified_email,
@@ -420,6 +423,7 @@ def patch(
420423
verified_email: Optional[bool] = None,
421424
verified_phone: Optional[bool] = None,
422425
sso_app_ids: Optional[List[str]] = None,
426+
test: bool = False,
423427
) -> dict:
424428
"""
425429
Patches an existing user with the given various fields. Only the given fields will be used to update the user.
@@ -439,6 +443,7 @@ def patch(
439443
picture (str): Optional url for user picture
440444
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
441445
sso_app_ids (List[str]): Optional, list of SSO applications IDs to be associated with the user.
446+
test (bool, optional): Set to True to update a test user. Defaults to False.
442447
443448
Return value (dict):
444449
Return dict in the format
@@ -465,6 +470,7 @@ def patch(
465470
verified_email,
466471
verified_phone,
467472
sso_app_ids,
473+
test,
468474
),
469475
pswd=self._auth.management_key,
470476
)
@@ -1936,6 +1942,7 @@ def _compose_patch_body(
19361942
verified_email: Optional[bool],
19371943
verified_phone: Optional[bool],
19381944
sso_app_ids: Optional[List[str]],
1945+
test: bool = False,
19391946
) -> dict:
19401947
res: dict[str, Any] = {
19411948
"loginId": login_id,
@@ -1966,4 +1973,6 @@ def _compose_patch_body(
19661973
res["verifiedPhone"] = verified_phone
19671974
if sso_app_ids is not None:
19681975
res["ssoAppIds"] = sso_app_ids
1976+
if test:
1977+
res["test"] = test
19691978
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)