|
| 1 | +# pylint: disable=redefined-outer-name |
| 2 | +# pylint: disable=unused-argument |
| 3 | +# pylint: disable=unused-variable |
| 4 | +# pylint: disable=too-many-arguments |
| 5 | + |
1 | 6 | from copy import deepcopy |
2 | 7 | from datetime import UTC, datetime |
3 | 8 | from pprint import pformat |
|
10 | 15 | from pydantic import BaseModel |
11 | 16 | from servicelib.rest_constants import RESPONSE_MODEL_POLICY |
12 | 17 | from simcore_postgres_database.models.users import UserRole |
| 18 | +from simcore_service_webserver.users._models import ProfilePrivacyGet |
13 | 19 | from simcore_service_webserver.users.schemas import ProfileGet, ThirdPartyToken |
14 | 20 |
|
15 | 21 |
|
@@ -39,45 +45,46 @@ def test_user_models_examples( |
39 | 45 | assert model_array_enveloped.error is None |
40 | 46 |
|
41 | 47 |
|
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: |
45 | 50 | fake_profile: dict[str, Any] = faker.simple_profile() |
| 51 | + first, last = fake_profile["name"].rsplit(maxsplit=1) |
46 | 52 |
|
47 | | - profile = ProfileGet( |
| 53 | + return ProfileGet( |
48 | 54 | id=faker.pyint(), |
| 55 | + first_name=first, |
| 56 | + last_name=last, |
49 | 57 | user_name=fake_profile["username"], |
50 | 58 | 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), |
53 | 61 | preferences={}, |
54 | 62 | ) |
55 | 63 |
|
| 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 | + |
56 | 72 | assert fake_expiration.date() == profile.expiration_date |
57 | 73 |
|
58 | 74 | body = jsonable_encoder(profile.model_dump(exclude_unset=True, by_alias=True)) |
59 | 75 | assert body["expirationDate"] == fake_expiration.date().isoformat() |
60 | 76 |
|
61 | 77 |
|
62 | | -def test_auto_compute_gravatar(faker: Faker): |
| 78 | +def test_auto_compute_gravatar__deprecated(fake_profile_get: ProfileGet): |
63 | 79 |
|
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() |
76 | 81 |
|
77 | 82 | envelope = Envelope[Any](data=profile) |
78 | 83 | data = envelope.model_dump(**RESPONSE_MODEL_POLICY)["data"] |
79 | 84 |
|
80 | | - assert data["gravatar_id"] |
| 85 | + assert ( |
| 86 | + "gravatar_id" not in data |
| 87 | + ), f"{ProfileGet.model_fields['gravatar_id'].deprecated=}" |
81 | 88 | assert data["id"] == profile.id |
82 | 89 | assert data["first_name"] == profile.first_name |
83 | 90 | assert data["last_name"] == profile.last_name |
@@ -107,6 +114,7 @@ def test_parsing_output_of_get_user_profile(): |
107 | 114 | "last_name": "", |
108 | 115 | "role": "Guest", |
109 | 116 | "gravatar_id": "9d5e02c75fcd4bce1c8861f219f7f8a5", |
| 117 | + "privacy": {"hide_email": True, "hide_fullname": False}, |
110 | 118 | "groups": { |
111 | 119 | "me": { |
112 | 120 | "gid": 2, |
|
0 commit comments