|
18 | 18 | from aiopg.sa.connection import SAConnection |
19 | 19 | from faker import Faker |
20 | 20 | from models_library.api_schemas_webserver.auth import AccountRequestInfo |
21 | | -from models_library.api_schemas_webserver.users import MyProfileGet, UserForAdminGet |
| 21 | +from models_library.api_schemas_webserver.users import ( |
| 22 | + MyProfileGet, |
| 23 | + UserForAdminGet, |
| 24 | + UserGet, |
| 25 | +) |
22 | 26 | from models_library.generics import Envelope |
23 | 27 | from psycopg2 import OperationalError |
| 28 | +from pydantic import TypeAdapter |
24 | 29 | from pytest_simcore.helpers.assert_checks import assert_status |
25 | 30 | from pytest_simcore.helpers.faker_factories import ( |
26 | 31 | DEFAULT_TEST_PASSWORD, |
@@ -54,6 +59,40 @@ def app_environment( |
54 | 59 | ) |
55 | 60 |
|
56 | 61 |
|
| 62 | +@pytest.mark.parametrize("user_role", [UserRole.USER]) |
| 63 | +async def test_get_and_search_public_users( |
| 64 | + user: UserInfoDict, |
| 65 | + logged_user: UserInfoDict, |
| 66 | + client: TestClient, |
| 67 | + user_role: UserRole, |
| 68 | +): |
| 69 | + assert client.app |
| 70 | + assert user_role == logged_user["role"] |
| 71 | + other_user = user |
| 72 | + |
| 73 | + assert other_user["id"] != logged_user["id"] |
| 74 | + |
| 75 | + # GET user |
| 76 | + url = client.app.router["get_user"].url_for(user_id=f'{other_user["id"]}') |
| 77 | + resp = await client.get(f"{url}") |
| 78 | + data, _ = await assert_status(resp, status.HTTP_200_OK) |
| 79 | + |
| 80 | + got = UserGet.model_validate(data) |
| 81 | + assert got.user_id == other_user["id"] |
| 82 | + assert got.user_name == other_user["name"] |
| 83 | + |
| 84 | + # SEARCH user |
| 85 | + partial_email = other_user["email"][:-5] |
| 86 | + url = client.app.router["search_users"].url_for().with_query(match=partial_email) |
| 87 | + resp = await client.post(f"{url}") |
| 88 | + data, _ = await assert_status(resp, status.HTTP_200_OK) |
| 89 | + |
| 90 | + found = TypeAdapter(list[UserGet]).validate_python(data) |
| 91 | + assert found |
| 92 | + assert len(found) == 1 |
| 93 | + assert found[0] == got |
| 94 | + |
| 95 | + |
57 | 96 | @pytest.mark.parametrize( |
58 | 97 | "user_role,expected", |
59 | 98 | [ |
|
0 commit comments