Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Dec 17, 2024
1 parent 32b0ea4 commit 55542e0
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion services/web/server/tests/unit/with_dbs/03/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import functools
import sys
from collections.abc import AsyncIterable
from copy import deepcopy
from http import HTTPStatus
from typing import Any, AsyncIterable
from typing import Any
from unittest.mock import MagicMock, Mock

import pytest
Expand Down Expand Up @@ -76,6 +77,23 @@ async def private_user(client: TestClient) -> AsyncIterable[UserInfoDict]:
yield usr


@pytest.fixture
async def semi_private_user(client: TestClient) -> AsyncIterable[UserInfoDict]:
assert client.app
async with NewUser(
app=client.app,
user_data={
"name": "maxwell",
"first_name": "James",
"last_name": "Maxwell",
"email": "[email protected]",
"privacy_hide_email": True,
"privacy_hide_fullname": False, # <--
},
) as usr:
yield usr


@pytest.fixture
async def public_user(client: TestClient) -> AsyncIterable[UserInfoDict]:
assert client.app
Expand All @@ -102,6 +120,7 @@ async def test_search_users(
client: TestClient,
user_role: UserRole,
public_user: UserInfoDict,
semi_private_user: UserInfoDict,
private_user: UserInfoDict,
):
assert client.app
Expand All @@ -110,6 +129,23 @@ async def test_search_users(
assert private_user["id"] != logged_user["id"]
assert public_user["id"] != logged_user["id"]

# SEARCH by partial first_name
partial_name = "james"
assert partial_name in private_user.get("first_name", "").lower()
assert partial_name in semi_private_user.get("first_name", "").lower()

url = client.app.router["search_users"].url_for()
resp = await client.post(f"{url}", json={"match": partial_name})
data, _ = await assert_status(resp, status.HTTP_200_OK)

found = TypeAdapter(list[UserGet]).validate_python(data)
assert found
assert len(found) == 1
assert semi_private_user["name"] == found[0].user_name
assert found[0].first_name == semi_private_user.get("first_name")
assert found[0].last_name == semi_private_user.get("first_name")
assert found[0].email is None

# SEARCH by partial email
partial_email = "@find.m"
assert partial_email in private_user["email"]
Expand Down

0 comments on commit 55542e0

Please sign in to comment.