Skip to content

Commit bf5686c

Browse files
committed
start adding tests
1 parent 38aecfd commit bf5686c

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

services/storage/src/simcore_service_storage/api/_worker_tasks/tasks.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
from ...models import FileMetaData
1414
from ._files import complete_upload_file
1515
from ._paths import compute_path_size, delete_paths
16-
from ._simcore_s3 import deep_copy_files_from_project, export_data
16+
from ._simcore_s3 import (
17+
deep_copy_files_from_project,
18+
export_data,
19+
export_data_as_download_link,
20+
)
1721

1822
_logger = logging.getLogger(__name__)
1923

@@ -24,6 +28,9 @@ def setup_worker_tasks(app: Celery) -> None:
2428

2529
with log_context(_logger, logging.INFO, msg="worker task registration"):
2630
register_task(app, export_data, dont_autoretry_for=(AccessRightError,))
31+
register_task(
32+
app, export_data_as_download_link, dont_autoretry_for=(AccessRightError,)
33+
)
2734
register_task(app, compute_path_size)
2835
register_task(app, complete_upload_file)
2936
register_task(app, delete_paths)

services/storage/src/simcore_service_storage/api/rpc/_simcore_s3.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Literal
2+
13
from models_library.api_schemas_rpc_async_jobs.async_jobs import (
24
AsyncJobFilter,
35
AsyncJobGet,
@@ -8,7 +10,11 @@
810
from servicelib.celery.task_manager import TaskManager
911
from servicelib.rabbitmq import RPCRouter
1012

11-
from .._worker_tasks._simcore_s3 import deep_copy_files_from_project, export_data
13+
from .._worker_tasks._simcore_s3 import (
14+
deep_copy_files_from_project,
15+
export_data,
16+
export_data_as_download_link,
17+
)
1218

1319
router = RPCRouter()
1420

@@ -38,8 +44,14 @@ async def start_export_data(
3844
task_manager: TaskManager,
3945
job_filter: AsyncJobFilter,
4046
paths_to_export: list[PathToExport],
47+
export_as: Literal["path", "download_link"] = "path",
4148
) -> AsyncJobGet:
42-
task_name = export_data.__name__
49+
if export_as == "path":
50+
task_name = export_data.__name__
51+
elif export_as == "download_link":
52+
task_name = export_data_as_download_link.__name__
53+
else:
54+
raise ValueError(f"Invalid export_as value: {export_as}")
4355
task_filter = TaskFilter.model_validate(job_filter.model_dump())
4456
task_uuid = await task_manager.submit_task(
4557
task_metadata=TaskMetadata(

services/storage/tests/unit/test_rpc_handlers_simcore_s3.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from collections.abc import Awaitable, Callable
1414
from copy import deepcopy
1515
from pathlib import Path
16-
from typing import Any
16+
from typing import Any, Literal
1717
from unittest.mock import Mock
1818

1919
import httpx
@@ -514,6 +514,7 @@ async def _request_start_export_data(
514514
user_id: UserID,
515515
product_name: ProductName,
516516
paths_to_export: list[PathToExport],
517+
export_as: Literal["path", "download_link"],
517518
*,
518519
client_timeout: datetime.timedelta = datetime.timedelta(seconds=60),
519520
) -> dict[str, Any]:
@@ -526,6 +527,7 @@ async def _request_start_export_data(
526527
user_id=user_id,
527528
product_name=product_name,
528529
paths_to_export=paths_to_export,
530+
export_as=export_as,
529531
)
530532

531533
async for async_job_result in wait_and_get_result(
@@ -572,6 +574,10 @@ def task_progress_spy(mocker: MockerFixture) -> Mock:
572574
],
573575
ids=str,
574576
)
577+
@pytest.mark.parametrize(
578+
"export_as",
579+
["path", "download_link"],
580+
)
575581
async def test_start_export_data(
576582
initialized_app: FastAPI,
577583
short_dsm_cleaner_interval: int,
@@ -589,6 +595,7 @@ async def test_start_export_data(
589595
],
590596
project_params: ProjectWithFilesParams,
591597
task_progress_spy: Mock,
598+
export_as: Literal["path", "download_link"],
592599
):
593600
_, src_projects_list = await random_project_with_files(project_params)
594601

@@ -606,6 +613,7 @@ async def test_start_export_data(
606613
user_id,
607614
product_name,
608615
paths_to_export=list(nodes_in_project_to_export),
616+
export_as=export_as,
609617
)
610618

611619
assert re.fullmatch(
@@ -618,6 +626,10 @@ async def test_start_export_data(
618626
assert progress_updates[-1] == 1
619627

620628

629+
@pytest.mark.parametrize(
630+
"export_as",
631+
["path", "download_link"],
632+
)
621633
async def test_start_export_data_access_error(
622634
initialized_app: FastAPI,
623635
short_dsm_cleaner_interval: int,
@@ -626,6 +638,7 @@ async def test_start_export_data_access_error(
626638
user_id: UserID,
627639
product_name: ProductName,
628640
faker: Faker,
641+
export_as: Literal["path", "download_link"],
629642
):
630643
path_to_export = TypeAdapter(PathToExport).validate_python(
631644
f"{faker.uuid4()}/{faker.uuid4()}/{faker.file_name()}"
@@ -637,6 +650,7 @@ async def test_start_export_data_access_error(
637650
product_name,
638651
paths_to_export=[path_to_export],
639652
client_timeout=datetime.timedelta(seconds=60),
653+
export_as=export_as,
640654
)
641655

642656
assert isinstance(exc.value, JobError)

0 commit comments

Comments
 (0)