Skip to content

Commit 1834e83

Browse files
committed
new tests
1 parent 8d088c1 commit 1834e83

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

services/web/server/tests/unit/with_dbs/03/test_users.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
import functools
99
import sys
10+
from collections.abc import AsyncIterable
1011
from copy import deepcopy
1112
from http import HTTPStatus
12-
from typing import Any, AsyncIterable
13+
from typing import Any
1314
from unittest.mock import MagicMock, Mock
1415

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

7879

80+
@pytest.fixture
81+
async def semi_private_user(client: TestClient) -> AsyncIterable[UserInfoDict]:
82+
assert client.app
83+
async with NewUser(
84+
app=client.app,
85+
user_data={
86+
"name": "maxwell",
87+
"first_name": "James",
88+
"last_name": "Maxwell",
89+
"email": "[email protected]",
90+
"privacy_hide_email": True,
91+
"privacy_hide_fullname": False, # <--
92+
},
93+
) as usr:
94+
yield usr
95+
96+
7997
@pytest.fixture
8098
async def public_user(client: TestClient) -> AsyncIterable[UserInfoDict]:
8199
assert client.app
@@ -102,6 +120,7 @@ async def test_search_users(
102120
client: TestClient,
103121
user_role: UserRole,
104122
public_user: UserInfoDict,
123+
semi_private_user: UserInfoDict,
105124
private_user: UserInfoDict,
106125
):
107126
assert client.app
@@ -110,6 +129,23 @@ async def test_search_users(
110129
assert private_user["id"] != logged_user["id"]
111130
assert public_user["id"] != logged_user["id"]
112131

132+
# SEARCH by partial first_name
133+
partial_name = "james"
134+
assert partial_name in private_user.get("first_name", "").lower()
135+
assert partial_name in semi_private_user.get("first_name", "").lower()
136+
137+
url = client.app.router["search_users"].url_for()
138+
resp = await client.post(f"{url}", json={"match": partial_name})
139+
data, _ = await assert_status(resp, status.HTTP_200_OK)
140+
141+
found = TypeAdapter(list[UserGet]).validate_python(data)
142+
assert found
143+
assert len(found) == 1
144+
assert semi_private_user["name"] == found[0].user_name
145+
assert found[0].first_name == semi_private_user.get("first_name")
146+
assert found[0].last_name == semi_private_user.get("first_name")
147+
assert found[0].email is None
148+
113149
# SEARCH by partial email
114150
partial_email = "@find.m"
115151
assert partial_email in private_user["email"]

0 commit comments

Comments
 (0)