Skip to content

Commit 2fac593

Browse files
committed
fix: add status field to create_test_user, matching create()
create() got an optional status parameter in 2.12.0 but create_test_user() was missed, leaving the two interfaces out of sync.
1 parent 7443c8b commit 2fac593

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

descope/management/user.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def create_test_user(
109109
invite_url: Optional[str] = None,
110110
additional_login_ids: Optional[List[str]] = None,
111111
sso_app_ids: Optional[List[str]] = None,
112+
status: Optional[str] = None,
112113
) -> dict:
113114
"""
114115
Create a new test user.
@@ -127,6 +128,7 @@ def create_test_user(
127128
picture (str): Optional url for user picture
128129
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
129130
sso_app_ids (List[str]): Optional, list of SSO applications IDs to be associated with the user.
131+
status (str): Optional status field. Can be one of: "enabled", "disabled", "invited", "expired".
130132
131133
Return value (dict):
132134
Return dict in the format
@@ -136,6 +138,7 @@ def create_test_user(
136138
Raise:
137139
AuthException: raised if create operation fails
138140
"""
141+
UserBase._validate_status(status)
139142
role_names = [] if role_names is None else role_names
140143
user_tenants = [] if user_tenants is None else user_tenants
141144

@@ -162,6 +165,7 @@ def create_test_user(
162165
None,
163166
additional_login_ids,
164167
sso_app_ids,
168+
status=status,
165169
),
166170
)
167171
return response.json()

descope/management/user_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ async def create_test_user(
113113
invite_url: Optional[str] = None,
114114
additional_login_ids: Optional[List[str]] = None,
115115
sso_app_ids: Optional[List[str]] = None,
116+
status: Optional[str] = None,
116117
) -> dict:
117118
"""
118119
Create a new test user.
@@ -131,6 +132,7 @@ async def create_test_user(
131132
picture (str): Optional url for user picture
132133
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
133134
sso_app_ids (List[str]): Optional, list of SSO applications IDs to be associated with the user.
135+
status (str): Optional status field. Can be one of: "enabled", "disabled", "invited", "expired".
134136
135137
Return value (dict):
136138
Return dict in the format
@@ -140,6 +142,7 @@ async def create_test_user(
140142
Raise:
141143
AuthException: raised if create operation fails
142144
"""
145+
UserBase._validate_status(status)
143146
role_names = [] if role_names is None else role_names
144147
user_tenants = [] if user_tenants is None else user_tenants
145148

@@ -166,6 +169,7 @@ async def create_test_user(
166169
None,
167170
additional_login_ids,
168171
sso_app_ids,
172+
status=status,
169173
),
170174
)
171175
return response.json()

tests/management/test_user.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ async def test_create_test_user(self, client_factory):
142142
with pytest.raises(AuthException):
143143
await client.invoke(client.mgmt.user.create("valid-id"))
144144

145+
with pytest.raises(AuthException) as exc_info:
146+
await client.invoke(client.mgmt.user.create_test_user("valid-id", status="invalid_status"))
147+
assert "Invalid status value: invalid_status" in str(exc_info.value)
148+
145149
# Test success flow
146150
with client.mock_mgmt_post(make_response({"user": {"id": "u1"}})) as mock_post:
147151
resp = await client.invoke(
@@ -154,6 +158,7 @@ async def test_create_test_user(self, client_factory):
154158
AssociatedTenant("tenant2", ["role1", "role2"]),
155159
],
156160
custom_attributes={"ak": "av"},
161+
status="disabled",
157162
)
158163
)
159164
user = resp["user"]
@@ -184,6 +189,7 @@ async def test_create_test_user(self, client_factory):
184189
"invite": False,
185190
"additionalLoginIds": None,
186191
"ssoAppIDs": None,
192+
"status": "disabled",
187193
},
188194
follow_redirects=False,
189195
)

0 commit comments

Comments
 (0)