|
| 1 | +# pylint: disable=protected-access |
1 | 2 | # pylint: disable=redefined-outer-name
|
| 3 | +# pylint: disable=too-many-arguments |
2 | 4 | # pylint: disable=unused-argument
|
3 | 5 | # pylint: disable=unused-variable
|
4 |
| -# pylint: disable=too-many-arguments |
5 | 6 |
|
6 |
| -import itertools |
7 |
| -from copy import deepcopy |
8 | 7 | from datetime import UTC, datetime
|
9 | 8 | from typing import Any
|
10 | 9 |
|
|
16 | 15 | MyProfilePrivacyGet,
|
17 | 16 | )
|
18 | 17 | from models_library.generics import Envelope
|
19 |
| -from models_library.users import UserThirdPartyToken |
20 | 18 | from models_library.utils.fastapi_encoders import jsonable_encoder
|
21 |
| -from pydantic import BaseModel |
22 |
| -from pytest_simcore.pydantic_models import ( |
23 |
| - assert_validation_model, |
24 |
| - iter_model_examples_in_class, |
25 |
| -) |
26 | 19 | from servicelib.rest_constants import RESPONSE_MODEL_POLICY
|
27 |
| -from simcore_postgres_database.models.users import UserRole |
| 20 | +from simcore_postgres_database import utils_users |
28 | 21 | from simcore_service_webserver.users._common.models import ToUserUpdateDB
|
29 | 22 |
|
30 | 23 |
|
31 |
| -@pytest.mark.parametrize( |
32 |
| - "model_cls, example_name, example_data", |
33 |
| - itertools.chain( |
34 |
| - iter_model_examples_in_class(MyProfileGet), |
35 |
| - iter_model_examples_in_class(UserThirdPartyToken), |
36 |
| - ), |
37 |
| -) |
38 |
| -def test_user_models_examples( |
39 |
| - model_cls: type[BaseModel], example_name: str, example_data: Any |
40 |
| -): |
41 |
| - model_instance = assert_validation_model( |
42 |
| - model_cls, example_name=example_name, example_data=example_data |
43 |
| - ) |
44 |
| - |
45 |
| - model_enveloped = Envelope[model_cls].from_data( |
46 |
| - model_instance.model_dump(by_alias=True) |
47 |
| - ) |
48 |
| - model_array_enveloped = Envelope[list[model_cls]].from_data( |
49 |
| - [ |
50 |
| - model_instance.model_dump(by_alias=True), |
51 |
| - model_instance.model_dump(by_alias=True), |
52 |
| - ] |
53 |
| - ) |
54 |
| - |
55 |
| - assert model_enveloped.error is None |
56 |
| - assert model_array_enveloped.error is None |
57 |
| - |
58 |
| - |
59 | 24 | @pytest.fixture
|
60 | 25 | def fake_profile_get(faker: Faker) -> MyProfileGet:
|
61 | 26 | fake_profile: dict[str, Any] = faker.simple_profile()
|
@@ -104,18 +69,6 @@ def test_auto_compute_gravatar__deprecated(fake_profile_get: MyProfileGet):
|
104 | 69 | assert data["preferences"] == profile.preferences
|
105 | 70 |
|
106 | 71 |
|
107 |
| -@pytest.mark.parametrize("user_role", [u.name for u in UserRole]) |
108 |
| -def test_profile_get_role(user_role: str): |
109 |
| - for example in MyProfileGet.model_json_schema()["examples"]: |
110 |
| - data = deepcopy(example) |
111 |
| - data["role"] = user_role |
112 |
| - m1 = MyProfileGet(**data) |
113 |
| - |
114 |
| - data["role"] = UserRole(user_role) |
115 |
| - m2 = MyProfileGet(**data) |
116 |
| - assert m1 == m2 |
117 |
| - |
118 |
| - |
119 | 72 | def test_parsing_output_of_get_user_profile():
|
120 | 73 | result_from_db_query_and_composition = {
|
121 | 74 | "id": 1,
|
@@ -185,3 +138,12 @@ def test_mapping_update_models_from_rest_to_db():
|
185 | 138 | "name": "foo1234",
|
186 | 139 | "privacy_hide_fullname": False,
|
187 | 140 | }
|
| 141 | + |
| 142 | + |
| 143 | +def test_utils_user_generates_valid_myprofile_patch(): |
| 144 | + username = utils_users. _generate_username_from_email( "[email protected]") # noqa: SLF001 |
| 145 | + |
| 146 | + MyProfilePatch.model_validate({"userName": username}) |
| 147 | + MyProfilePatch.model_validate( |
| 148 | + {"userName": utils_users.generate_alternative_username(username)} |
| 149 | + ) |
0 commit comments