Skip to content

Commit ff10399

Browse files
committed
@GitHK review: add defaults
1 parent 8d07aff commit ff10399

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

packages/models-library/src/models_library/api_schemas_webserver/users.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class UserAccountGet(OutputSchema):
381381

382382
# user status
383383
registered: bool
384-
status: UserStatus | None
384+
status: UserStatus | None = None
385385
products: Annotated[
386386
list[ProductName] | None,
387387
Field(
@@ -393,11 +393,11 @@ class UserAccountGet(OutputSchema):
393393
user_id: Annotated[
394394
UserID | None,
395395
Field(description="Unique identifier of the user if an account was created"),
396-
]
396+
] = None
397397
user_name: Annotated[
398398
UserNameID | None,
399399
Field(description="Username of the user if an account was created"),
400-
]
400+
] = None
401401
user_primary_group_id: Annotated[
402402
PrimaryGroupID | None,
403403
Field(
@@ -406,7 +406,7 @@ class UserAccountGet(OutputSchema):
406406
alias="groupId",
407407
# SEE https://github.com/ITISFoundation/osparc-simcore/pull/8358#issuecomment-3279491740
408408
),
409-
]
409+
] = None
410410

411411
@field_validator("status")
412412
@classmethod

services/web/server/tests/unit/with_dbs/03/invitations/test_users_accounts_rest_registration.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ async def test_search_and_pre_registration(
231231
):
232232
assert client.app
233233

234+
# NOTE: listing of user accounts drops nullable fields to avoid lengthy responses (even if they have no defaults)
235+
# therefore they are reconstructed here from http response payloads
236+
nullable_fields = {
237+
name: None
238+
for name, field in UserAccountGet.model_fields.items()
239+
if is_nullable(field)
240+
}
241+
234242
# ONLY in `users` and NOT `users_pre_registration_details`
235243
resp = await client.get(
236244
"/v0/admin/user-accounts:search", params={"email": logged_user["email"]}
@@ -240,12 +248,6 @@ async def test_search_and_pre_registration(
240248
found, _ = await assert_status(resp, status.HTTP_200_OK)
241249
assert len(found) == 1
242250

243-
nullable_fields = {
244-
name: None
245-
for name, field in UserAccountGet.model_fields.items()
246-
if is_nullable(field)
247-
}
248-
249251
got = UserAccountGet.model_validate({**nullable_fields, **found[0]})
250252
expected = {
251253
"first_name": logged_user.get("first_name"),
@@ -263,7 +265,7 @@ async def test_search_and_pre_registration(
263265
"status": UserStatus.ACTIVE,
264266
"user_id": logged_user["id"],
265267
"user_name": logged_user["name"],
266-
"user_primary_group_id": logged_user.get("primary_group_id"),
268+
"user_primary_group_id": logged_user.get("primary_gid"),
267269
}
268270
assert got.model_dump(include=set(expected)) == expected
269271

@@ -281,8 +283,8 @@ async def test_search_and_pre_registration(
281283
)
282284
found, _ = await assert_status(resp, status.HTTP_200_OK)
283285
assert len(found) == 1
284-
got = UserAccountGet(**found[0], state=None, status=None)
285286

287+
got = UserAccountGet.model_validate({**nullable_fields, **found[0]})
286288
assert got.model_dump(include={"registered", "status"}) == {
287289
"registered": False,
288290
"status": None,
@@ -305,7 +307,8 @@ async def test_search_and_pre_registration(
305307
)
306308
found, _ = await assert_status(resp, status.HTTP_200_OK)
307309
assert len(found) == 1
308-
got = UserAccountGet(**found[0], state=None)
310+
311+
got = UserAccountGet.model_validate({**nullable_fields, **found[0]})
309312
assert got.model_dump(include={"registered", "status"}) == {
310313
"registered": True,
311314
"status": new_user["status"],

0 commit comments

Comments
 (0)