Skip to content

Commit d4f19cf

Browse files
committed
split tests
1 parent 6a60b04 commit d4f19cf

File tree

4 files changed

+534
-455
lines changed

4 files changed

+534
-455
lines changed

services/web/server/src/simcore_service_webserver/users/_users_rest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from contextlib import suppress
33

44
from aiohttp import web
5+
from common_library.users_enums import AccountRequestStatus
56
from models_library.api_schemas_webserver.users import (
67
MyProfileGet,
78
MyProfilePatch,
@@ -178,8 +179,9 @@ async def list_users_for_admin(request: web.Request) -> web.Response:
178179

179180
users, total_count = await _users_service.list_users_as_admin(
180181
request.app,
181-
filter_account_request_status={"PENDING": AccountRequestStatus.PENDING}.get(
182-
query_params.status or ""
182+
product_name=req_ctx.product_name,
183+
filter_account_request_status=(
184+
AccountRequestStatus(query_params.status) if query_params.status else None
183185
),
184186
pagination_limit=query_params.limit,
185187
pagination_offset=query_params.offset,
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# pylint: disable=protected-access
2+
# pylint: disable=redefined-outer-name
3+
# pylint: disable=too-many-arguments
4+
# pylint: disable=too-many-statements
5+
# pylint: disable=unused-argument
6+
# pylint: disable=unused-variable
7+
8+
9+
import sys
10+
from copy import deepcopy
11+
from typing import Any
12+
13+
import pytest
14+
from faker import Faker
15+
from models_library.api_schemas_webserver.auth import AccountRequestInfo
16+
from pytest_simcore.helpers.faker_factories import random_pre_registration_details
17+
from simcore_service_webserver.users._common.schemas import (
18+
MAX_BYTES_SIZE_EXTRAS,
19+
PreRegisteredUserGet,
20+
)
21+
22+
23+
@pytest.fixture
24+
def account_request_form(faker: Faker) -> dict[str, Any]:
25+
# This is AccountRequestInfo.form
26+
form = {
27+
"firstName": faker.first_name(),
28+
"lastName": faker.last_name(),
29+
"email": faker.email(),
30+
"phone": faker.phone_number(),
31+
"company": faker.company(),
32+
# billing info
33+
"address": faker.address().replace("\n", ", "),
34+
"city": faker.city(),
35+
"postalCode": faker.postcode(),
36+
"country": faker.country(),
37+
# extras
38+
"application": faker.word(),
39+
"description": faker.sentence(),
40+
"hear": faker.word(),
41+
"privacyPolicy": True,
42+
"eula": True,
43+
}
44+
45+
# keeps in sync fields from example and this fixture
46+
assert set(form) == set(AccountRequestInfo.model_json_schema()["example"]["form"])
47+
return form
48+
49+
50+
@pytest.mark.parametrize(
51+
"institution_key",
52+
[
53+
"institution",
54+
"companyName",
55+
"company",
56+
"university",
57+
"universityName",
58+
],
59+
)
60+
def test_preuserprofile_parse_model_from_request_form_data(
61+
account_request_form: dict[str, Any],
62+
institution_key: str,
63+
):
64+
data = deepcopy(account_request_form)
65+
data[institution_key] = data.pop("company")
66+
data["comment"] = "extra comment"
67+
68+
# pre-processors
69+
pre_user_profile = PreRegisteredUserGet(**data)
70+
71+
print(pre_user_profile.model_dump_json(indent=1))
72+
73+
# institution aliases
74+
assert pre_user_profile.institution == account_request_form["company"]
75+
76+
# extras
77+
assert {
78+
"application",
79+
"description",
80+
"hear",
81+
"privacyPolicy",
82+
"eula",
83+
"comment",
84+
} == set(pre_user_profile.extras)
85+
assert pre_user_profile.extras["comment"] == "extra comment"
86+
87+
88+
def test_preuserprofile_parse_model_without_extras(
89+
account_request_form: dict[str, Any],
90+
):
91+
required = {
92+
f.alias or f_name
93+
for f_name, f in PreRegisteredUserGet.model_fields.items()
94+
if f.is_required()
95+
}
96+
data = {k: account_request_form[k] for k in required}
97+
assert not PreRegisteredUserGet(**data).extras
98+
99+
100+
def test_preuserprofile_max_bytes_size_extras_limits(faker: Faker):
101+
data = random_pre_registration_details(faker)
102+
data_size = sys.getsizeof(data["extras"])
103+
104+
assert data_size < MAX_BYTES_SIZE_EXTRAS
105+
106+
107+
@pytest.mark.parametrize(
108+
"given_name", ["PEDrO-luis", "pedro luis", " pedro LUiS ", "pedro lUiS "]
109+
)
110+
def test_preuserprofile_pre_given_names(
111+
given_name: str,
112+
account_request_form: dict[str, Any],
113+
):
114+
account_request_form["firstName"] = given_name
115+
account_request_form["lastName"] = given_name
116+
117+
pre_user_profile = PreRegisteredUserGet(**account_request_form)
118+
print(pre_user_profile.model_dump_json(indent=1))
119+
assert pre_user_profile.first_name in ["Pedro-Luis", "Pedro Luis"]
120+
assert pre_user_profile.first_name == pre_user_profile.last_name

0 commit comments

Comments
 (0)