Skip to content

Commit a324fb3

Browse files
committed
fix unit tests
1 parent 59a6dbb commit a324fb3

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

services/web/server/tests/unit/with_dbs/01/storage/conftest.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import logging
77
import random
8-
from collections.abc import Callable, Iterator
8+
from collections.abc import Iterator
99
from pathlib import Path
1010
from threading import Thread
11-
from typing import Annotated, Any
11+
from typing import Annotated
1212
from urllib.parse import quote
1313

1414
import pytest
@@ -33,7 +33,6 @@
3333
from models_library.projects_nodes_io import LocationID, StorageFileID
3434
from models_library.users import UserID
3535
from pydantic import AnyUrl, TypeAdapter
36-
from pytest_mock import MockerFixture
3736
from pytest_simcore.helpers.logging_tools import log_context
3837
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
3938
from servicelib.utils import unused_port
@@ -319,21 +318,3 @@ def app_environment(
319318
@pytest.fixture
320319
def location_id(faker: Faker) -> LocationID:
321320
return TypeAdapter(LocationID).validate_python(faker.pyint(min_value=0))
322-
323-
324-
@pytest.fixture
325-
def create_storage_rpc_client_mock(mocker: MockerFixture) -> Callable[[str, Any], None]:
326-
def _(method: str, result_or_exception: Any):
327-
def side_effect(*args, **kwargs):
328-
if isinstance(result_or_exception, Exception):
329-
raise result_or_exception
330-
331-
return result_or_exception
332-
333-
for fct in (
334-
f"simcore_service_webserver.storage._rest.{method}",
335-
f"servicelib.rabbitmq.rpc_interfaces.storage.paths.{method}",
336-
):
337-
mocker.patch(fct, side_effect=side_effect)
338-
339-
return _

services/web/server/tests/unit/with_dbs/01/storage/test_storage.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from models_library.api_schemas_webserver.storage import StorageAsyncJobGet
2323
from models_library.projects_nodes_io import LocationID, StorageFileID
2424
from pydantic import TypeAdapter
25+
from pytest_mock import MockerFixture
2526
from pytest_simcore.helpers.assert_checks import assert_status
2627
from servicelib.aiohttp import status
2728
from servicelib.rabbitmq.rpc_interfaces.async_jobs.async_jobs import (
@@ -89,6 +90,23 @@ async def test_list_storage_paths(
8990
_faker = Faker()
9091

9192

93+
@pytest.fixture
94+
def create_storage_paths_rpc_client_mock(
95+
mocker: MockerFixture,
96+
) -> Callable[[str, Any], None]:
97+
def _(method: str, result_or_exception: Any):
98+
def side_effect(*args, **kwargs):
99+
if isinstance(result_or_exception, Exception):
100+
raise result_or_exception
101+
102+
return result_or_exception
103+
104+
for fct in (f"servicelib.rabbitmq.rpc_interfaces.storage.paths.{method}",):
105+
mocker.patch(fct, side_effect=side_effect)
106+
107+
return _
108+
109+
92110
@pytest.mark.parametrize(
93111
"user_role,expected",
94112
[
@@ -111,10 +129,10 @@ async def test_compute_path_size(
111129
expected: int,
112130
location_id: LocationID,
113131
faker: Faker,
114-
create_storage_rpc_client_mock: Callable[[str, Any], None],
132+
create_storage_paths_rpc_client_mock: Callable[[str, Any], None],
115133
backend_result_or_exception: Any,
116134
):
117-
create_storage_rpc_client_mock(
135+
create_storage_paths_rpc_client_mock(
118136
submit_job.__name__,
119137
backend_result_or_exception,
120138
)

services/web/server/tests/unit/with_dbs/01/storage/test_storage_rpc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
)
3131
from models_library.generics import Envelope
3232
from models_library.progress_bar import ProgressReport
33+
from pytest_mock import MockerFixture
3334
from pytest_simcore.helpers.webserver_login import UserInfoDict
3435
from servicelib.aiohttp import status
3536
from servicelib.rabbitmq.rpc_interfaces.async_jobs.async_jobs import (
@@ -44,6 +45,21 @@
4445
_faker = Faker()
4546

4647

48+
@pytest.fixture
49+
def create_storage_rpc_client_mock(mocker: MockerFixture) -> Callable[[str, Any], None]:
50+
def _(method: str, result_or_exception: Any):
51+
def side_effect(*args, **kwargs):
52+
if isinstance(result_or_exception, Exception):
53+
raise result_or_exception
54+
55+
return result_or_exception
56+
57+
for fct in (f"simcore_service_webserver.storage._rest.{method}",):
58+
mocker.patch(fct, side_effect=side_effect)
59+
60+
return _
61+
62+
4763
@pytest.mark.parametrize("user_role", [UserRole.USER])
4864
@pytest.mark.parametrize(
4965
"backend_result_or_exception",

0 commit comments

Comments
 (0)