Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrycw committed Mar 1, 2024
1 parent 05e90d2 commit 629770c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ async def search_users_ilike(
name: Annotated[str | None, Query(max_length=50)] = None,
):
client = await services.aget(AsyncIOClient)
result = await search_users_by_name_ilike_qry.search_users_by_name_ilike(
return await search_users_by_name_ilike_qry.search_users_by_name_ilike(
client, name=name
)
return result


################################
Expand Down
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def gen_event():
return lambda: TestEventData()


@pytest.fixture
@pytest.fixture(scope="session", autouse=True)
def test_app():
"""request 1 app(1 EdgeDB client) is enough per session"""
yield make_app(t_lifespan)


@pytest.fixture
@pytest.fixture(scope="session", autouse=True)
def test_client(test_app):
"""request 1 web client is enough per session"""
with TestClient(test_app) as client:
yield client

Expand Down
34 changes: 34 additions & 0 deletions tests/test_draft_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from http import HTTPStatus

from edgedb.asyncio_client import AsyncIOClient

from .lifespan import t_lifespan


################################
# Good cases
################################
def test_search_users_ilike_all(test_db_client, test_client):
search_user_ilike_url = "/users/search"
return_value = ["Jerry", "Mike", "Julia", "David", "Paul"]
test_db_client.query.return_value = return_value
t_lifespan.registry.register_value(AsyncIOClient, test_db_client)

response = test_client.get(search_user_ilike_url)
resp_json = response.json()

assert response.status_code == HTTPStatus.OK
assert set(resp_json) == set(return_value)


def test_search_users_ilike_filter(test_db_client, test_client):
search_user_ilike_url = "/users/search"
return_value = ["Jerry", "Julia"]
test_db_client.query.return_value = return_value
t_lifespan.registry.register_value(AsyncIOClient, test_db_client)

response = test_client.get(search_user_ilike_url, params={"name": "j"})
resp_json = response.json()

assert response.status_code == HTTPStatus.OK
assert set(resp_json) == set(return_value)
2 changes: 0 additions & 2 deletions tests/test_events.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from http import HTTPStatus

import edgedb
Expand Down
2 changes: 0 additions & 2 deletions tests/test_health.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from http import HTTPStatus


Expand Down

0 comments on commit 629770c

Please sign in to comment.