diff --git a/api_app/pytest.ini b/api_app/pytest.ini index 9e90ef7cb..a86e89e4b 100644 --- a/api_app/pytest.ini +++ b/api_app/pytest.ini @@ -1,3 +1,5 @@ [pytest] filterwarnings = error +asyncio_mode = strict +asyncio_default_fixture_loop_scope = function diff --git a/api_app/tests_ma/conftest.py b/api_app/tests_ma/conftest.py index 2331ab8b4..06589c324 100644 --- a/api_app/tests_ma/conftest.py +++ b/api_app/tests_ma/conftest.py @@ -1,5 +1,5 @@ import pytest -import pytest_asyncio + from mock import AsyncMock, patch from azure.cosmos.aio import CosmosClient, DatabaseProxy @@ -585,8 +585,8 @@ def simple_pipeline_step() -> PipelineStep: ) -@pytest_asyncio.fixture(autouse=True) -async def no_database(): +@pytest.fixture(autouse=True) +def no_database(): with patch('api.dependencies.database.get_credential_async', return_value=AsyncMock()), \ patch('api.dependencies.database.CosmosClient', return_value=AsyncMock(spec=CosmosClient)) as cosmos_client_mock: cosmos_client_mock.return_value.get_database_client.return_value = AsyncMock(spec=DatabaseProxy) diff --git a/api_app/tests_ma/test_api/conftest.py b/api_app/tests_ma/test_api/conftest.py index 7ad45f341..f1443c208 100644 --- a/api_app/tests_ma/test_api/conftest.py +++ b/api_app/tests_ma/test_api/conftest.py @@ -1,5 +1,7 @@ import pytest import pytest_asyncio + + from mock import patch from fastapi import FastAPI @@ -144,12 +146,12 @@ def inner(): return inner -@pytest_asyncio.fixture(scope='module') +@pytest.fixture(scope='module') def app() -> FastAPI: from main import get_application - the_app = get_application() - return the_app + + return get_application() @pytest_asyncio.fixture @@ -157,3 +159,5 @@ async def client(app: FastAPI) -> AsyncClient: async with AsyncClient(transport=ASGITransport(app=app), base_url="http://testserver", headers={"Content-Type": "application/json"}) as client: yield client + + diff --git a/api_app/tests_ma/test_api/test_routes/test_airlock.py b/api_app/tests_ma/test_api/test_routes/test_airlock.py index 7d8f29576..e0b99bd8b 100644 --- a/api_app/tests_ma/test_api/test_routes/test_airlock.py +++ b/api_app/tests_ma/test_api/test_routes/test_airlock.py @@ -1,6 +1,8 @@ import time import pytest -import pytest_asyncio + +pytestmark = pytest.mark.asyncio + from mock import patch from fastapi import status from azure.core.exceptions import HttpResponseError @@ -129,7 +131,7 @@ def inner(): class TestAirlockRoutesThatRequireOwnerOrResearcherRights(): - @pytest_asyncio.fixture(autouse=True, scope='class') + @pytest.fixture(autouse=True, scope="class") def log_in_with_researcher_user(self, app, researcher_user): app.dependency_overrides[require_workspace_owner_or_researcher] = researcher_user app.dependency_overrides[require_workspace_owner_or_researcher_or_airlock_manager] = researcher_user @@ -141,6 +143,7 @@ def log_in_with_researcher_user(self, app, researcher_user): yield app.dependency_overrides = {} + # [GET] /workspaces/{workspace_id}/requests} @patch("api.routes.airlock.AirlockRequestRepository.get_airlock_requests", return_value=[]) async def test_get_all_airlock_requests_by_workspace_returns_200(self, _, app, client): @@ -305,7 +308,7 @@ async def test_get_airlock_container_link_returned_as_expected(self, get_airlock class TestAirlockRoutesThatRequireAirlockManagerRights(): - @pytest_asyncio.fixture(autouse=True, scope='class') + @pytest.fixture(autouse=True, scope="class") def log_in_with_airlock_manager_user(self, app, airlock_manager_user): app.dependency_overrides[require_airlock_manager] = airlock_manager_user app.dependency_overrides[require_workspace_owner_or_researcher_or_airlock_manager] = airlock_manager_user @@ -316,6 +319,7 @@ def log_in_with_airlock_manager_user(self, app, airlock_manager_user): yield app.dependency_overrides = {} + # [POST] /workspaces/{workspace_id}/requests/{airlock_request_id}/review @patch("services.airlock.AirlockRequestRepository.read_item_by_id", return_value=sample_airlock_request_object(status=AirlockRequestStatus.InReview)) @patch("services.airlock.AirlockRequestRepository.create_airlock_review_item", return_value=sample_airlock_review_object()) @@ -465,7 +469,7 @@ async def test_post_revoke_airlock_request_missing_reason_returns_422(self, _, a class TestAirlockRoutesPermissions(): - @pytest_asyncio.fixture() + @pytest.fixture() def log_in_with_user(self, app): def inner(user): app.dependency_overrides[require_workspace_owner_or_researcher] = user