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
Use mocked_session_get by default
One can still define a separate responder function here, but since this is the
only response defined for the tests thus far, this seems like a reasonable default.
  • Loading branch information
james-gray committed Apr 2, 2020
commit 990c82c866fc70bc343762031ca7658f10d977ed
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def mock_client_session_class(request):
"""

httputils.client_session = request.cls.mock_client_session = mock.AsyncMock()
httputils.client_session.get = mocked_session_get
try:
yield
finally:
Expand All @@ -94,6 +95,7 @@ async def mock_client_session():
"""

httputils.client_session = mock.AsyncMock()
httputils.client_session.get = mocked_session_get
try:
yield httputils.client_session
finally:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_csbs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from app.services.location import csbs
from tests.conftest import mocked_session_get


def mocked_csbs_requests_get(*args, **kwargs):
Expand All @@ -28,7 +27,6 @@ def read_file(self):

@pytest.mark.asyncio
async def test_get_locations(mock_client_session):
mock_client_session.get = mocked_session_get
data = await csbs.get_locations()

assert isinstance(data, list)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from app import location
from app.services.location import jhu
from tests.conftest import mocked_session_get
from tests.conftest import mocked_strptime_isoformat

DATETIME_STRING = "2020-03-17T10:23:22.505550"
Expand All @@ -16,7 +15,6 @@ async def test_get_locations(mock_datetime, mock_client_session):
mock_datetime.utcnow.return_value.isoformat.return_value = DATETIME_STRING
mock_datetime.strptime.side_effect = mocked_strptime_isoformat

mock_client_session.get = mocked_session_get
output = await jhu.get_locations()

assert isinstance(output, list)
Expand Down
12 changes: 0 additions & 12 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pytest
from async_asgi_testclient import TestClient

from .conftest import mocked_session_get
from .conftest import mocked_strptime_isoformat
from .test_jhu import DATETIME_STRING
from app.main import APP
Expand Down Expand Up @@ -34,8 +33,6 @@ def read_file_v1(self, state):
@mock.patch("app.services.location.jhu.datetime")
async def test_root_api(self, mock_datetime):
"""Validate that / returns a 200 and is not a redirect."""
self.mock_client_session.get = mocked_session_get

response = await self.asgi_client.get("/")

assert response.status_code == 200
Expand All @@ -45,7 +42,6 @@ async def test_root_api(self, mock_datetime):
async def test_v1_confirmed(self, mock_datetime):
mock_datetime.utcnow.return_value.isoformat.return_value = self.date
mock_datetime.strptime.side_effect = mocked_strptime_isoformat
self.mock_client_session.get = mocked_session_get

state = "confirmed"
expected_json_output = self.read_file_v1(state=state)
Expand All @@ -58,7 +54,6 @@ async def test_v1_confirmed(self, mock_datetime):
async def test_v1_deaths(self, mock_datetime):
mock_datetime.utcnow.return_value.isoformat.return_value = self.date
mock_datetime.strptime.side_effect = mocked_strptime_isoformat
self.mock_client_session.get = mocked_session_get

state = "deaths"
expected_json_output = self.read_file_v1(state=state)
Expand All @@ -71,7 +66,6 @@ async def test_v1_deaths(self, mock_datetime):
async def test_v1_recovered(self, mock_datetime):
mock_datetime.utcnow.return_value.isoformat.return_value = self.date
mock_datetime.strptime.side_effect = mocked_strptime_isoformat
self.mock_client_session.get = mocked_session_get

state = "recovered"
expected_json_output = self.read_file_v1(state=state)
Expand All @@ -84,7 +78,6 @@ async def test_v1_recovered(self, mock_datetime):
async def test_v1_all(self, mock_datetime):
mock_datetime.utcnow.return_value.isoformat.return_value = self.date
mock_datetime.strptime.side_effect = mocked_strptime_isoformat
self.mock_client_session.get = mocked_session_get

state = "all"
expected_json_output = self.read_file_v1(state=state)
Expand All @@ -97,7 +90,6 @@ async def test_v1_all(self, mock_datetime):
async def test_v2_latest(self, mock_datetime):
mock_datetime.utcnow.return_value.isoformat.return_value = DATETIME_STRING
mock_datetime.strptime.side_effect = mocked_strptime_isoformat
self.mock_client_session.get = mocked_session_get

state = "latest"
response = await self.asgi_client.get(f"/v2/{state}")
Expand All @@ -111,7 +103,6 @@ async def test_v2_latest(self, mock_datetime):
async def test_v2_locations(self, mock_datetime):
mock_datetime.utcnow.return_value.isoformat.return_value = DATETIME_STRING
mock_datetime.strptime.side_effect = mocked_strptime_isoformat
self.mock_client_session.get = mocked_session_get

state = "locations"
response = await self.asgi_client.get("/v2/{}".format(state))
Expand All @@ -128,7 +119,6 @@ async def test_v2_locations(self, mock_datetime):
async def test_v2_locations_id(self, mock_datetime):
mock_datetime.utcnow.return_value.isoformat.return_value = DATETIME_STRING
mock_datetime.strptime.side_effect = mocked_strptime_isoformat
self.mock_client_session.get = mocked_session_get

state = "locations"
test_id = 1
Expand Down Expand Up @@ -158,7 +148,6 @@ async def test_v2_locations_id(self, mock_datetime):
],
)
async def test_locations_status_code(async_api_client, query_params, expected_status, mock_client_session):
mock_client_session.get = mocked_session_get
response = await async_api_client.get("/v2/locations", query_string=query_params)

print(f"GET {response.url}\n{response}")
Expand All @@ -179,7 +168,6 @@ async def test_locations_status_code(async_api_client, query_params, expected_st
],
)
async def test_latest(async_api_client, query_params, mock_client_session):
mock_client_session.get = mocked_session_get
response = await async_api_client.get("/v2/latest", query_string=query_params)

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