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
Update test_csbs to handle asyncio
  • Loading branch information
james-gray committed Apr 2, 2020
commit 3bfc94eff8caa84291507e3f24caf90003dfd06c
13 changes: 9 additions & 4 deletions tests/test_csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import app
from app.services.location import csbs
from tests.fixtures import mock_client_session
from tests.fixtures import mocked_session_get


def mocked_csbs_requests_get(*args, **kwargs):
Expand All @@ -21,17 +23,20 @@ def read_file(self):
"""
Mock HTTP GET-method and return text from file
"""
filepath = "tests/example_data/sample_covid19_county.csv"
filepath = "tests/example_data/covid19_county.csv"
print("Try to read {}".format(filepath))
with open(filepath, "r") as file:
return file.read()

return FakeRequestsGetResponse()


@mock.patch("app.services.location.csbs.requests.get", side_effect=mocked_csbs_requests_get)
def test_get_locations(mock_request_get):
data = csbs.get_locations()
@pytest.mark.asyncio
async def test_get_locations():
async with mock_client_session() as mocked_client_session:
mocked_client_session.get = mocked_session_get
data = await csbs.get_locations()

assert isinstance(data, list)

# check to see that Unknown/Unassigned has been filtered
Expand Down