Skip to content

Commit c385103

Browse files
authored
Create and invite with verified attributes (#278)
+ test related to descope/etc#3834
1 parent a753d81 commit c385103

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

descope/management/user.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def create(
2222
user_tenants: List[AssociatedTenant] = None,
2323
picture: str = None,
2424
custom_attributes: dict = None,
25+
verified_email: bool = None,
26+
verified_phone: bool = None,
2527
) -> dict:
2628
"""
2729
Create a new user. Users can have any number of optional fields, including email, phone number and authorization.
@@ -62,6 +64,8 @@ def create(
6264
False,
6365
picture,
6466
custom_attributes,
67+
verified_email,
68+
verified_phone,
6569
),
6670
pswd=self._auth.management_key,
6771
)
@@ -77,6 +81,8 @@ def create_test_user(
7781
user_tenants: List[AssociatedTenant] = None,
7882
picture: str = None,
7983
custom_attributes: dict = None,
84+
verified_email: bool = None,
85+
verified_phone: bool = None,
8086
) -> dict:
8187
"""
8288
Create a new test user.
@@ -119,6 +125,8 @@ def create_test_user(
119125
True,
120126
picture,
121127
custom_attributes,
128+
verified_email,
129+
verified_phone,
122130
),
123131
pswd=self._auth.management_key,
124132
)
@@ -134,6 +142,8 @@ def invite(
134142
user_tenants: List[AssociatedTenant] = None,
135143
picture: str = None,
136144
custom_attributes: dict = None,
145+
verified_email: bool = None,
146+
verified_phone: bool = None,
137147
) -> dict:
138148
"""
139149
Create a new user and invite them via an email message.
@@ -162,6 +172,8 @@ def invite(
162172
False,
163173
picture,
164174
custom_attributes,
175+
verified_email,
176+
verified_phone,
165177
),
166178
pswd=self._auth.management_key,
167179
)
@@ -957,6 +969,8 @@ def _compose_create_body(
957969
test: bool,
958970
picture: str,
959971
custom_attributes: dict,
972+
verified_email: bool = None,
973+
verified_phone: bool = None,
960974
) -> dict:
961975
body = User._compose_update_body(
962976
login_id,
@@ -970,6 +984,10 @@ def _compose_create_body(
970984
custom_attributes,
971985
)
972986
body["invite"] = invite
987+
if verified_email is not None:
988+
body["verifiedEmail"] = verified_email
989+
if verified_phone is not None:
990+
body["verifiedPhone"] = verified_phone
973991
return body
974992

975993
@staticmethod

tests/management/test_user.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,57 @@ def test_create(self):
8686
timeout=DEFAULT_TIMEOUT_SECONDS,
8787
)
8888

89+
def test_create_with_verified_parameters(self):
90+
# Test success flow with verified email and phone
91+
with patch("requests.post") as mock_post:
92+
network_resp = mock.Mock()
93+
network_resp.ok = True
94+
network_resp.json.return_value = json.loads("""{"user": {"id": "u1"}}""")
95+
mock_post.return_value = network_resp
96+
resp = self.client.mgmt.user.create(
97+
login_id="name@mail.com",
98+
email="name@mail.com",
99+
display_name="Name",
100+
user_tenants=[
101+
AssociatedTenant("tenant1"),
102+
AssociatedTenant("tenant2", ["role1", "role2"]),
103+
],
104+
picture="https://test.com",
105+
custom_attributes={"ak": "av"},
106+
verified_email=True,
107+
verified_phone=False,
108+
)
109+
user = resp["user"]
110+
self.assertEqual(user["id"], "u1")
111+
mock_post.assert_called_with(
112+
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_create_path}",
113+
headers={
114+
**common.default_headers,
115+
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
116+
},
117+
params=None,
118+
json={
119+
"loginId": "name@mail.com",
120+
"email": "name@mail.com",
121+
"phone": None,
122+
"displayName": "Name",
123+
"roleNames": [],
124+
"userTenants": [
125+
{"tenantId": "tenant1", "roleNames": []},
126+
{"tenantId": "tenant2", "roleNames": ["role1", "role2"]},
127+
],
128+
"test": False,
129+
"picture": "https://test.com",
130+
"customAttributes": {"ak": "av"},
131+
"invite": False,
132+
"verifiedEmail": True,
133+
"verifiedPhone": False,
134+
},
135+
allow_redirects=False,
136+
verify=True,
137+
timeout=DEFAULT_TIMEOUT_SECONDS,
138+
)
139+
89140
def test_create_test_user(self):
90141
# Test failed flows
91142
with patch("requests.post") as mock_post:

0 commit comments

Comments
 (0)