Skip to content

Commit

Permalink
cleanup fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Mar 14, 2023
1 parent 7419ff4 commit e7c3668
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import AsyncGenerator, AsyncIterator, Callable

import pytest
import redis.asyncio as aioredis
from aiohttp import ClientResponse, ClientSession, web
from aiohttp.test_utils import TestClient, TestServer
from faker import Faker
Expand All @@ -26,6 +27,7 @@
from pytest_simcore.helpers.utils_envs import setenvs_from_dict
from pytest_simcore.helpers.utils_login import UserInfoDict, UserRole
from pytest_simcore.helpers.utils_projects import NewProject, delete_all_projects
from pytest_simcore.helpers.utils_webserver_unit_with_db import MockedStorageSubsystem
from servicelib.aiohttp.long_running_tasks.client import LRTask
from servicelib.aiohttp.long_running_tasks.server import TaskProgress
from servicelib.aiohttp.rest_responses import unwrap_envelope
Expand Down Expand Up @@ -178,9 +180,13 @@ def mocks_on_projects_api(mocker: MockerFixture) -> None:


@pytest.fixture
async def storage_subsystem_mock(storage_subsystem_mock, mocker: MockerFixture):
async def storage_subsystem_mock_override(
storage_subsystem_mock: MockedStorageSubsystem, mocker: MockerFixture
) -> None:
"""
Mocks functions that require storage client
NOTE: overrides conftest.storage_subsystem_mock
"""
# Overrides + extends fixture in services/web/server/tests/unit/with_dbs/conftest.py
# SEE https://docs.pytest.org/en/stable/fixture.html#override-a-fixture-on-a-folder-conftest-level
Expand Down Expand Up @@ -293,11 +299,12 @@ async def test_access_to_forbidden_study(
async def test_access_study_anonymously(
client: TestClient,
published_project: ProjectDict,
storage_subsystem_mock,
storage_subsystem_mock_override: None,
catalog_subsystem_mock: Callable[[list[ProjectDict]], None],
director_v2_service_mock,
mocks_on_projects_api,
redis_locks_client, # needed to cleanup the locks between parametrizations
director_v2_service_mock: AioResponsesMock,
mocks_on_projects_api: None,
# needed to cleanup the locks between parametrizations
redis_locks_client: AsyncIterator[aioredis.Redis],
):
catalog_subsystem_mock([published_project])

Expand Down Expand Up @@ -340,12 +347,13 @@ async def test_access_study_by_logged_user(
client: TestClient,
logged_user: UserInfoDict,
published_project: ProjectDict,
storage_subsystem_mock,
storage_subsystem_mock_override: None,
catalog_subsystem_mock: Callable[[list[ProjectDict]], None],
director_v2_service_mock: AioResponsesMock,
mocks_on_projects_api,
mocks_on_projects_api: None,
auto_delete_projects: None,
redis_locks_client, # needed to cleanup the locks between parametrizations
# needed to cleanup the locks between parametrizations
redis_locks_client: AsyncIterator[aioredis.Redis],
):
catalog_subsystem_mock([published_project])
assert _is_user_authenticated(client.session), "Is already logged-in"
Expand All @@ -369,11 +377,12 @@ async def test_access_study_by_logged_user(
async def test_access_cookie_of_expired_user(
client: TestClient,
published_project: ProjectDict,
storage_subsystem_mock,
storage_subsystem_mock_override: None,
catalog_subsystem_mock: Callable[[list[ProjectDict]], None],
director_v2_service_mock: AioResponsesMock,
mocks_on_projects_api,
redis_locks_client, # needed to cleanup the locks between parametrizations
mocks_on_projects_api: None,
# needed to cleanup the locks between parametrizations
redis_locks_client: AsyncIterator[aioredis.Redis],
):
catalog_subsystem_mock([published_project])
# emulates issue #1570
Expand Down Expand Up @@ -436,11 +445,12 @@ async def test_guest_user_is_not_garbage_collected(
web_server: TestServer,
aiohttp_client: Callable,
published_project: ProjectDict,
storage_subsystem_mock,
storage_subsystem_mock_override: None,
catalog_subsystem_mock: Callable[[list[ProjectDict]], None],
director_v2_service_mock: AioResponsesMock,
mocks_on_projects_api,
redis_locks_client, # needed to cleanup the locks between parametrizations
mocks_on_projects_api: None,
# needed to cleanup the locks between parametrizations
redis_locks_client: AsyncIterator[aioredis.Redis],
):
catalog_subsystem_mock([published_project])
## NOTE: use pytest -s --log-cli-level=DEBUG to see GC logs
Expand Down
2 changes: 1 addition & 1 deletion services/web/server/tests/unit/with_dbs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def add_index_route(app: web.Application) -> None:


@pytest.fixture
async def storage_subsystem_mock(mocker) -> MockedStorageSubsystem:
async def storage_subsystem_mock(mocker: MonkeyPatch) -> MockedStorageSubsystem:
"""
Patches client calls to storage service
Expand Down

0 comments on commit e7c3668

Please sign in to comment.