Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add an async_api_client pytest fixture
  • Loading branch information
james-gray committed Apr 2, 2020
commit 0e827fb37308edf6d01cac364d1ada868ae899e3
11 changes: 10 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
"""
import pytest
from fastapi.testclient import TestClient
from async_asgi_testclient import TestClient as AsyncTestClient

from app.main import APP


@pytest.fixture
def api_client():
"""
Returns a TestClient.
Returns a fastapi.testclient.TestClient.
The test client uses the requests library for making http requests.
"""
return TestClient(APP)


@pytest.fixture
async def async_api_client():
"""
Returns an async_asgi_testclient.TestClient.
"""
return AsyncTestClient(APP)
10 changes: 4 additions & 6 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ async def test_v2_locations_id(self, mock_datetime):
({"source": "jhu", "country_code": "US"}, 404),
],
)
async def test_locations_status_code(query_params, expected_status):
api_client = TestClient(APP)
async def test_locations_status_code(async_api_client, query_params, expected_status):
async with mock_client_session() as mocked_client_session:
mocked_client_session.get = mocked_session_get
response = await api_client.get("/v2/locations", query_string=query_params)
response = await async_api_client.get("/v2/locations", query_string=query_params)

print(f"GET {response.url}\n{response}")
print(f"\tjson:\n{pf(response.json())[:1000]}\n\t...")
Expand All @@ -174,11 +173,10 @@ async def test_locations_status_code(query_params, expected_status):
{"source": "jhu", "timelines": True},
],
)
async def test_latest(query_params):
api_client = TestClient(APP)
async def test_latest(async_api_client, query_params):
async with mock_client_session() as mocked_client_session:
mocked_client_session.get = mocked_session_get
response = await api_client.get("/v2/latest", query_string=query_params)
response = await async_api_client.get("/v2/latest", query_string=query_params)

print(f"GET {response.url}\n{response}")

Expand Down