Skip to content

Commit aa1c0bf

Browse files
committed
reuse fixtures
1 parent e680984 commit aa1c0bf

File tree

1 file changed

+22
-61
lines changed

1 file changed

+22
-61
lines changed

services/storage/tests/unit/test_data_export.py

Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# pylint: disable=W0621
22
# pylint: disable=W0613
33
# pylint: disable=R6301
4-
from collections.abc import Awaitable, Callable
54
from dataclasses import dataclass
65
from pathlib import Path
76
from typing import Any, Literal, NamedTuple
@@ -10,7 +9,6 @@
109
import pytest
1110
from celery.exceptions import CeleryError
1211
from faker import Faker
13-
from fastapi import FastAPI
1412
from models_library.api_schemas_long_running_tasks.tasks import TaskResult
1513
from models_library.api_schemas_rpc_async_jobs.async_jobs import (
1614
AsyncJobGet,
@@ -35,15 +33,11 @@
3533
from models_library.users import UserID
3634
from pydantic import ByteSize, TypeAdapter
3735
from pytest_mock import MockerFixture
38-
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
3936
from pytest_simcore.helpers.storage_utils import FileIDDict, ProjectWithFilesParams
40-
from pytest_simcore.helpers.typing_env import EnvVarsDict
4137
from servicelib.rabbitmq import RabbitMQRPCClient
4238
from servicelib.rabbitmq.rpc_interfaces.async_jobs import async_jobs
4339
from servicelib.rabbitmq.rpc_interfaces.storage.data_export import start_data_export
44-
from settings_library.rabbit import RabbitSettings
4540
from simcore_service_storage.api.rpc._data_export import AccessRightError
46-
from simcore_service_storage.core.settings import ApplicationSettings
4741
from simcore_service_storage.modules.celery.client import TaskUUID
4842
from simcore_service_storage.modules.celery.models import TaskState, TaskStatus
4943
from simcore_service_storage.simcore_s3_dsm import SimcoreS3DataManager
@@ -123,38 +117,6 @@ async def mock_celery_client(
123117
return _celery_client
124118

125119

126-
@pytest.fixture
127-
async def app_environment(
128-
app_environment: EnvVarsDict,
129-
rabbit_service: RabbitSettings,
130-
monkeypatch: pytest.MonkeyPatch,
131-
):
132-
new_envs = setenvs_from_dict(
133-
monkeypatch,
134-
{
135-
**app_environment,
136-
"RABBIT_HOST": rabbit_service.RABBIT_HOST,
137-
"RABBIT_PORT": f"{rabbit_service.RABBIT_PORT}",
138-
"RABBIT_USER": rabbit_service.RABBIT_USER,
139-
"RABBIT_SECURE": f"{rabbit_service.RABBIT_SECURE}",
140-
"RABBIT_PASSWORD": rabbit_service.RABBIT_PASSWORD.get_secret_value(),
141-
},
142-
)
143-
144-
settings = ApplicationSettings.create_from_envs()
145-
assert settings.STORAGE_RABBITMQ
146-
147-
return new_envs
148-
149-
150-
@pytest.fixture
151-
async def rpc_client(
152-
initialized_app: FastAPI,
153-
rabbitmq_rpc_client: Callable[[str], Awaitable[RabbitMQRPCClient]],
154-
) -> RabbitMQRPCClient:
155-
return await rabbitmq_rpc_client("client")
156-
157-
158120
class UserWithFile(NamedTuple):
159121
user: UserID
160122
file: Path
@@ -196,7 +158,7 @@ class UserWithFile(NamedTuple):
196158
indirect=True,
197159
)
198160
async def test_start_data_export_success(
199-
rpc_client: RabbitMQRPCClient,
161+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
200162
mock_celery_client: _MockCeleryClient,
201163
with_random_project_with_files: tuple[
202164
dict[str, Any],
@@ -224,7 +186,7 @@ async def test_start_data_export_success(
224186
pytest.fail(f"invalid parameter: {selection_type=}")
225187

226188
result = await start_data_export(
227-
rpc_client,
189+
storage_rabbitmq_rpc_client,
228190
job_id_data=AsyncJobNameData(user_id=user_id, product_name="osparc"),
229191
data_export_start=DataExportTaskStartInput(
230192
location_id=0,
@@ -259,15 +221,14 @@ async def test_start_data_export_success(
259221
indirect=True,
260222
)
261223
async def test_start_data_export_scheduler_error(
262-
rpc_client: RabbitMQRPCClient,
224+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
263225
mock_celery_client: _MockCeleryClient,
264226
with_random_project_with_files: tuple[
265227
dict[str, Any],
266228
dict[NodeID, dict[SimcoreS3FileID, FileIDDict]],
267229
],
268230
user_id: UserID,
269231
):
270-
271232
_, list_of_files = with_random_project_with_files
272233
workspace_files = [
273234
p for p in list(list_of_files.values())[0].keys() if "/workspace/" in p
@@ -277,7 +238,7 @@ async def test_start_data_export_scheduler_error(
277238

278239
with pytest.raises(JobSchedulerError):
279240
_ = await start_data_export(
280-
rpc_client,
241+
storage_rabbitmq_rpc_client,
281242
job_id_data=AsyncJobNameData(user_id=user_id, product_name="osparc"),
282243
data_export_start=DataExportTaskStartInput(
283244
location_id=0,
@@ -294,14 +255,14 @@ async def test_start_data_export_scheduler_error(
294255
indirect=True,
295256
)
296257
async def test_start_data_export_access_error(
297-
rpc_client: RabbitMQRPCClient,
258+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
298259
mock_celery_client: _MockCeleryClient,
299260
user_id: UserID,
300261
faker: Faker,
301262
):
302263
with pytest.raises(AccessRightError):
303264
_ = await async_jobs.submit(
304-
rpc_client,
265+
storage_rabbitmq_rpc_client,
305266
rpc_namespace=STORAGE_RPC_NAMESPACE,
306267
method_name="start_data_export",
307268
job_id_data=AsyncJobNameData(user_id=user_id, product_name="osparc"),
@@ -325,13 +286,13 @@ async def test_start_data_export_access_error(
325286
indirect=True,
326287
)
327288
async def test_abort_data_export_success(
328-
rpc_client: RabbitMQRPCClient,
289+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
329290
mock_celery_client: _MockCeleryClient,
330291
):
331292
assert mock_celery_client.get_task_uuids_object is not None
332293
assert not isinstance(mock_celery_client.get_task_uuids_object, Exception)
333294
await async_jobs.cancel(
334-
rpc_client,
295+
storage_rabbitmq_rpc_client,
335296
rpc_namespace=STORAGE_RPC_NAMESPACE,
336297
job_id_data=AsyncJobNameData(
337298
user_id=_faker.pyint(min_value=1, max_value=100), product_name="osparc"
@@ -355,7 +316,7 @@ async def test_abort_data_export_success(
355316
indirect=["mock_celery_client"],
356317
)
357318
async def test_abort_data_export_error(
358-
rpc_client: RabbitMQRPCClient,
319+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
359320
mock_celery_client: _MockCeleryClient,
360321
expected_exception_type: type[Exception],
361322
):
@@ -365,7 +326,7 @@ async def test_abort_data_export_error(
365326
_job_id = next(iter(job_ids)) if len(job_ids) > 0 else AsyncJobId(_faker.uuid4())
366327
with pytest.raises(expected_exception_type):
367328
await async_jobs.cancel(
368-
rpc_client,
329+
storage_rabbitmq_rpc_client,
369330
rpc_namespace=STORAGE_RPC_NAMESPACE,
370331
job_id_data=AsyncJobNameData(
371332
user_id=_faker.pyint(min_value=1, max_value=100), product_name="osparc"
@@ -389,15 +350,15 @@ async def test_abort_data_export_error(
389350
indirect=True,
390351
)
391352
async def test_get_data_export_status(
392-
rpc_client: RabbitMQRPCClient,
353+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
393354
mock_celery_client: _MockCeleryClient,
394355
):
395356
job_ids = mock_celery_client.get_task_uuids_object
396357
assert job_ids is not None
397358
assert not isinstance(job_ids, Exception)
398359
_job_id = next(iter(job_ids)) if len(job_ids) > 0 else AsyncJobId(_faker.uuid4())
399360
result = await async_jobs.status(
400-
rpc_client,
361+
storage_rabbitmq_rpc_client,
401362
rpc_namespace=STORAGE_RPC_NAMESPACE,
402363
job_id=_job_id,
403364
job_id_data=AsyncJobNameData(
@@ -426,7 +387,7 @@ async def test_get_data_export_status(
426387
indirect=["mock_celery_client"],
427388
)
428389
async def test_get_data_export_status_error(
429-
rpc_client: RabbitMQRPCClient,
390+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
430391
mock_celery_client: _MockCeleryClient,
431392
expected_exception_type: type[Exception],
432393
):
@@ -436,7 +397,7 @@ async def test_get_data_export_status_error(
436397
_job_id = next(iter(job_ids)) if len(job_ids) > 0 else AsyncJobId(_faker.uuid4())
437398
with pytest.raises(expected_exception_type):
438399
_ = await async_jobs.status(
439-
rpc_client,
400+
storage_rabbitmq_rpc_client,
440401
rpc_namespace=STORAGE_RPC_NAMESPACE,
441402
job_id=_job_id,
442403
job_id_data=AsyncJobNameData(
@@ -461,15 +422,15 @@ async def test_get_data_export_status_error(
461422
indirect=True,
462423
)
463424
async def test_get_data_export_result_success(
464-
rpc_client: RabbitMQRPCClient,
425+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
465426
mock_celery_client: _MockCeleryClient,
466427
):
467428
job_ids = mock_celery_client.get_task_uuids_object
468429
assert job_ids is not None
469430
assert not isinstance(job_ids, Exception)
470431
_job_id = next(iter(job_ids)) if len(job_ids) > 0 else AsyncJobId(_faker.uuid4())
471432
result = await async_jobs.result(
472-
rpc_client,
433+
storage_rabbitmq_rpc_client,
473434
rpc_namespace=STORAGE_RPC_NAMESPACE,
474435
job_id=_job_id,
475436
job_id_data=AsyncJobNameData(
@@ -536,7 +497,7 @@ async def test_get_data_export_result_success(
536497
indirect=["mock_celery_client"],
537498
)
538499
async def test_get_data_export_result_error(
539-
rpc_client: RabbitMQRPCClient,
500+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
540501
mock_celery_client: _MockCeleryClient,
541502
expected_exception: type[Exception],
542503
):
@@ -547,7 +508,7 @@ async def test_get_data_export_result_error(
547508

548509
with pytest.raises(expected_exception):
549510
_ = await async_jobs.result(
550-
rpc_client,
511+
storage_rabbitmq_rpc_client,
551512
rpc_namespace=STORAGE_RPC_NAMESPACE,
552513
job_id=_job_id,
553514
job_id_data=AsyncJobNameData(
@@ -564,11 +525,11 @@ async def test_get_data_export_result_error(
564525
indirect=True,
565526
)
566527
async def test_list_jobs_success(
567-
rpc_client: RabbitMQRPCClient,
528+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
568529
mock_celery_client: MockerFixture,
569530
):
570531
result = await async_jobs.list_jobs(
571-
rpc_client,
532+
storage_rabbitmq_rpc_client,
572533
rpc_namespace=STORAGE_RPC_NAMESPACE,
573534
job_id_data=AsyncJobNameData(
574535
user_id=_faker.pyint(min_value=1, max_value=100), product_name="osparc"
@@ -587,12 +548,12 @@ async def test_list_jobs_success(
587548
indirect=True,
588549
)
589550
async def test_list_jobs_error(
590-
rpc_client: RabbitMQRPCClient,
551+
storage_rabbitmq_rpc_client: RabbitMQRPCClient,
591552
mock_celery_client: MockerFixture,
592553
):
593554
with pytest.raises(JobSchedulerError):
594555
_ = await async_jobs.list_jobs(
595-
rpc_client,
556+
storage_rabbitmq_rpc_client,
596557
rpc_namespace=STORAGE_RPC_NAMESPACE,
597558
job_id_data=AsyncJobNameData(
598559
user_id=_faker.pyint(min_value=1, max_value=100), product_name="osparc"

0 commit comments

Comments
 (0)