Skip to content

Commit 65f6817

Browse files
author
Andrei Neagu
committed
moved modules
1 parent 5db89cb commit 65f6817

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import re
2+
from collections.abc import Callable
3+
4+
import pytest
5+
from celery import Celery
6+
from models_library.users import UserID
7+
from simcore_service_storage.api._worker_tasks._data_export import data_export
8+
from simcore_service_storage.modules.celery._task import define_task
9+
from simcore_service_storage.modules.celery.client import CeleryTaskQueueClient
10+
from simcore_service_storage.modules.celery.models import (
11+
TaskContext,
12+
TaskState,
13+
)
14+
from tenacity import Retrying, retry_if_exception_type, stop_after_delay, wait_fixed
15+
16+
pytest_simcore_core_services_selection = [
17+
"postgres",
18+
"rabbit",
19+
]
20+
21+
22+
@pytest.fixture
23+
def register_celery_tasks() -> Callable[[Celery], None]:
24+
def _(celery_app: Celery) -> None:
25+
define_task(celery_app, data_export)
26+
27+
return _
28+
29+
30+
@pytest.mark.usefixtures("celery_worker")
31+
async def test_data_export(celery_client: CeleryTaskQueueClient, user_id: UserID):
32+
task_context = TaskContext()
33+
34+
task_uuid = await celery_client.send_task(
35+
data_export.__name__,
36+
task_context=task_context,
37+
user_id=user_id,
38+
paths_to_export=[],
39+
)
40+
41+
for attempt in Retrying(
42+
retry=retry_if_exception_type(AssertionError),
43+
wait=wait_fixed(1),
44+
stop=stop_after_delay(30),
45+
):
46+
with attempt:
47+
status = await celery_client.get_task_status(task_context, task_uuid)
48+
assert status.task_state == TaskState.SUCCESS
49+
50+
assert (
51+
await celery_client.get_task_status(task_context, task_uuid)
52+
).task_state == TaskState.SUCCESS
53+
54+
result = await celery_client.get_task_result(task_context, task_uuid)
55+
assert re.fullmatch(
56+
rf"^exports/{user_id}/[0-9a-fA-F]{{8}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{12}}\.zip$",
57+
result,
58+
)

services/storage/tests/unit/test_api__worker_tasks__paths.py renamed to services/storage/tests/unit/api/_worker_tasks/test__paths.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# pylint:disable=unused-variable
88

99
import random
10-
import re
1110
from pathlib import Path
1211
from typing import Any, TypeAlias
1312

@@ -20,7 +19,6 @@
2019
from models_library.users import UserID
2120
from pydantic import ByteSize, TypeAdapter
2221
from pytest_simcore.helpers.storage_utils import FileIDDict, ProjectWithFilesParams
23-
from simcore_service_storage.api._worker_tasks._data_export import data_export
2422
from simcore_service_storage.api._worker_tasks._paths import compute_path_size
2523
from simcore_service_storage.modules.celery.utils import (
2624
set_celery_worker_client,
@@ -74,6 +72,7 @@ async def _assert_compute_path_size(
7472
@pytest.fixture
7573
def fake_celery_task(celery_app: Celery, initialized_app: FastAPI) -> Task:
7674
celery_task = Task()
75+
celery_task.name = "fake_name"
7776
celery_task.app = celery_app
7877
set_fastapi_app(celery_app, initialized_app)
7978
set_celery_worker_client(celery_app, CeleryWorkerClient(celery_app))
@@ -223,12 +222,3 @@ async def test_path_compute_size_inexistent_path(
223222
path=Path(faker.file_path(absolute=False)),
224223
expected_total_size=0,
225224
)
226-
227-
228-
# TODO: refactor and extract common parts
229-
async def test_data_export(fake_celery_task: Task, user_id: UserID):
230-
data = await data_export(fake_celery_task, user_id=user_id, paths_to_export=[])
231-
assert re.fullmatch(
232-
rf"^exports/{user_id}/[0-9a-fA-F]{{8}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{12}}\.zip$",
233-
data,
234-
)

0 commit comments

Comments
 (0)