Skip to content

Commit 7cadd12

Browse files
committed
tests models
1 parent 76dffd5 commit 7cadd12

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

services/web/server/tests/unit/isolated/test_users_models.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
3+
# pylint: disable=unused-variable
4+
# pylint: disable=too-many-arguments
5+
16
from copy import deepcopy
27
from datetime import UTC, datetime
38
from pprint import pformat
@@ -10,6 +15,7 @@
1015
from pydantic import BaseModel
1116
from servicelib.rest_constants import RESPONSE_MODEL_POLICY
1217
from simcore_postgres_database.models.users import UserRole
18+
from simcore_service_webserver.users._models import ProfilePrivacyGet
1319
from simcore_service_webserver.users.schemas import ProfileGet, ThirdPartyToken
1420

1521

@@ -39,45 +45,46 @@ def test_user_models_examples(
3945
assert model_array_enveloped.error is None
4046

4147

42-
def test_profile_get_expiration_date(faker: Faker):
43-
fake_expiration = datetime.now(UTC)
44-
48+
@pytest.fixture
49+
def fake_profile_get(faker: Faker) -> ProfileGet:
4550
fake_profile: dict[str, Any] = faker.simple_profile()
51+
first, last = fake_profile["name"].rsplit(maxsplit=1)
4652

47-
profile = ProfileGet(
53+
return ProfileGet(
4854
id=faker.pyint(),
55+
first_name=first,
56+
last_name=last,
4957
user_name=fake_profile["username"],
5058
login=fake_profile["mail"],
51-
role=UserRole.ADMIN,
52-
expiration_date=fake_expiration.date(),
59+
role="USER",
60+
privacy=ProfilePrivacyGet(hide_fullname=True, hide_email=True),
5361
preferences={},
5462
)
5563

64+
65+
def test_profile_get_expiration_date(fake_profile_get: ProfileGet):
66+
fake_expiration = datetime.now(UTC)
67+
68+
profile = fake_profile_get.model_copy(
69+
update={"expiration_date": fake_expiration.date()}
70+
)
71+
5672
assert fake_expiration.date() == profile.expiration_date
5773

5874
body = jsonable_encoder(profile.model_dump(exclude_unset=True, by_alias=True))
5975
assert body["expirationDate"] == fake_expiration.date().isoformat()
6076

6177

62-
def test_auto_compute_gravatar(faker: Faker):
78+
def test_auto_compute_gravatar__deprecated(fake_profile_get: ProfileGet):
6379

64-
fake_profile: dict[str, Any] = faker.simple_profile()
65-
first_name, last_name = fake_profile["name"].rsplit(maxsplit=1)
66-
67-
profile = ProfileGet(
68-
id=faker.pyint(),
69-
user_name=fake_profile["username"],
70-
first_name=first_name,
71-
last_name=last_name,
72-
login=fake_profile["mail"],
73-
role="USER",
74-
preferences={},
75-
)
80+
profile = fake_profile_get.model_copy()
7681

7782
envelope = Envelope[Any](data=profile)
7883
data = envelope.model_dump(**RESPONSE_MODEL_POLICY)["data"]
7984

80-
assert data["gravatar_id"]
85+
assert (
86+
"gravatar_id" not in data
87+
), f"{ProfileGet.model_fields['gravatar_id'].deprecated=}"
8188
assert data["id"] == profile.id
8289
assert data["first_name"] == profile.first_name
8390
assert data["last_name"] == profile.last_name
@@ -107,6 +114,7 @@ def test_parsing_output_of_get_user_profile():
107114
"last_name": "",
108115
"role": "Guest",
109116
"gravatar_id": "9d5e02c75fcd4bce1c8861f219f7f8a5",
117+
"privacy": {"hide_email": True, "hide_fullname": False},
110118
"groups": {
111119
"me": {
112120
"gid": 2,

0 commit comments

Comments
 (0)