diff --git a/Pipfile b/Pipfile index d5097194..be7444e3 100644 --- a/Pipfile +++ b/Pipfile @@ -5,6 +5,8 @@ verify_ssl = true [dev-packages] async-asgi-testclient = "*" +async_generator = "*" +asyncmock = "*" bandit = "*" black = "==19.10b0" coveralls = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 500275a9..8b71e7cd 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "71ab11be8ac956d1b6ebb10f6bbd7496331b749cfaf1f540536321c5ad328e40" + "sha256": "72d35102ae55e8201c5f3f950096e40b4ff279fcb9c5a009f1e25f8778f83808" }, "pipfile-spec": 6, "requires": { @@ -313,6 +313,22 @@ "index": "pypi", "version": "==1.4.4" }, + "async-generator": { + "hashes": [ + "sha256:01c7bf666359b4967d2cda0000cc2e4af16a0ae098cbffcb8472fb9e8ad6585b", + "sha256:6ebb3d106c12920aaae42ccb6f787ef5eefdcdd166ea3d628fa8476abe712144" + ], + "index": "pypi", + "version": "==1.10" + }, + "asyncmock": { + "hashes": [ + "sha256:c251889d542e98fe5f7ece2b5b8643b7d62b50a5657d34a4cbce8a1d5170d750", + "sha256:fd8bc4e7813251a8959d1140924ccba3adbbc7af885dba7047c67f73c0b664b1" + ], + "index": "pypi", + "version": "==0.4.2" + }, "attrs": { "hashes": [ "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c", @@ -478,6 +494,13 @@ ], "version": "==0.6.1" }, + "mock": { + "hashes": [ + "sha256:3f9b2c0196c60d21838f307f5825a7b86b678cedc58ab9e50a8988187b4d81e0", + "sha256:dd33eb70232b6118298d516bbcecd26704689c386594f0f3c4f13867b2c56f72" + ], + "version": "==4.0.2" + }, "more-itertools": { "hashes": [ "sha256:5dd8bcf33e5f9513ffa06d5ad33d78f31e1931ac9a18f33d37e77a180d393a7c", diff --git a/app/services/location/csbs.py b/app/services/location/csbs.py index dbd8d82d..8487c387 100644 --- a/app/services/location/csbs.py +++ b/app/services/location/csbs.py @@ -3,6 +3,7 @@ from datetime import datetime from asyncache import cached + from cachetools import TTLCache from ...coordinates import Coordinates diff --git a/app/services/location/jhu.py b/app/services/location/jhu.py index 316de367..269292ab 100644 --- a/app/services/location/jhu.py +++ b/app/services/location/jhu.py @@ -3,6 +3,7 @@ from datetime import datetime from asyncache import cached + from cachetools import TTLCache from ...coordinates import Coordinates diff --git a/tests/conftest.py b/tests/conftest.py index fe58a6b9..99ce7b96 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,15 +5,27 @@ """ import datetime import os -from contextlib import asynccontextmanager -from unittest import mock import pytest from async_asgi_testclient import TestClient as AsyncTestClient -from fastapi.testclient import TestClient from app.main import APP from app.utils import httputils +from fastapi.testclient import TestClient + +try: + from unittest.mock import AsyncMock +except ImportError: + # Python 3.7 backwards compat + from asyncmock import AsyncMock + +try: + from contextlib import asynccontextmanager +except ImportError: + # Python 3.6 backwards compat + from async_generator import asynccontextmanager + + @pytest.fixture @@ -80,7 +92,7 @@ def mock_client_session_class(request): See: https://docs.pytest.org/en/5.4.1/unittest.html#mixing-pytest-fixtures-into-unittest-testcase-subclasses-using-marks """ - httputils.CLIENT_SESSION = request.cls.mock_client_session = mock.AsyncMock() + httputils.CLIENT_SESSION = request.cls.mock_client_session = AsyncMock() httputils.CLIENT_SESSION.get = mocked_session_get try: yield @@ -94,7 +106,7 @@ async def mock_client_session(): instance. """ - httputils.CLIENT_SESSION = mock.AsyncMock() + httputils.CLIENT_SESSION = AsyncMock() httputils.CLIENT_SESSION.get = mocked_session_get try: yield httputils.CLIENT_SESSION