|
2 | 2 | # pylint: disable=W0613 |
3 | 3 | from collections.abc import Awaitable, Callable |
4 | 4 | from pathlib import Path |
5 | | -from typing import Awaitable, Callable, NamedTuple |
| 5 | +from typing import Any, Awaitable, Callable, Literal, NamedTuple |
6 | 6 |
|
7 | 7 | import pytest |
8 | 8 | from faker import Faker |
|
18 | 18 | from models_library.api_schemas_storage.data_export_async_jobs import ( |
19 | 19 | DataExportTaskStartInput, |
20 | 20 | ) |
21 | | -from models_library.projects import ProjectID |
| 21 | +from models_library.projects_nodes_io import NodeID, SimcoreS3FileID |
22 | 22 | from models_library.users import UserID |
| 23 | +from pydantic import ByteSize, TypeAdapter |
23 | 24 | from pytest_mock import MockerFixture |
24 | 25 | from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict |
| 26 | +from pytest_simcore.helpers.storage_utils import FileIDDict, ProjectWithFilesParams |
25 | 27 | from pytest_simcore.helpers.typing_env import EnvVarsDict |
26 | 28 | from servicelib.rabbitmq import RabbitMQRPCClient |
27 | 29 | from servicelib.rabbitmq.rpc_interfaces.async_jobs import async_jobs |
28 | 30 | from settings_library.rabbit import RabbitSettings |
29 | | -from simcore_postgres_database.models.file_meta_data import file_meta_data |
30 | 31 | from simcore_service_storage.api.rpc._data_export import AccessRightError |
31 | 32 | from simcore_service_storage.core.settings import ApplicationSettings |
32 | | -from simcore_service_storage.models import FileMetaData |
33 | | -from sqlalchemy.ext.asyncio import AsyncEngine |
34 | 33 |
|
35 | 34 | pytest_plugins = [ |
36 | 35 | "pytest_simcore.rabbit_service", |
@@ -86,27 +85,64 @@ class UserWithFile(NamedTuple): |
86 | 85 | file: Path |
87 | 86 |
|
88 | 87 |
|
89 | | -@pytest.fixture |
90 | | -async def user_owner_file( |
91 | | - user_id: UserID, project_id: ProjectID, sqlalchemy_async_engine: AsyncEngine |
92 | | -): |
93 | | - async with sqlalchemy_async_engine.connect() as conn: |
94 | | - file_meta_data.insert() |
95 | | - |
96 | | - |
| 88 | +@pytest.mark.parametrize( |
| 89 | + "project_params,_type", |
| 90 | + [ |
| 91 | + ( |
| 92 | + ProjectWithFilesParams( |
| 93 | + num_nodes=1, |
| 94 | + allowed_file_sizes=(TypeAdapter(ByteSize).validate_python("1b"),), |
| 95 | + workspace_files_count=10, |
| 96 | + ), |
| 97 | + "file", |
| 98 | + ), |
| 99 | + ( |
| 100 | + ProjectWithFilesParams( |
| 101 | + num_nodes=1, |
| 102 | + allowed_file_sizes=(TypeAdapter(ByteSize).validate_python("1b"),), |
| 103 | + workspace_files_count=10, |
| 104 | + ), |
| 105 | + "folder", |
| 106 | + ), |
| 107 | + ], |
| 108 | + ids=str, |
| 109 | +) |
97 | 110 | async def test_start_data_export_success( |
98 | | - rpc_client: RabbitMQRPCClient, output_file: FileMetaData, user_id: UserID |
| 111 | + rpc_client: RabbitMQRPCClient, |
| 112 | + with_random_project_with_files: tuple[ |
| 113 | + dict[str, Any], |
| 114 | + dict[NodeID, dict[SimcoreS3FileID, FileIDDict]], |
| 115 | + ], |
| 116 | + user_id: UserID, |
| 117 | + _type: Literal["file", "folder"], |
99 | 118 | ): |
100 | 119 |
|
| 120 | + project, list_of_files = with_random_project_with_files |
| 121 | + workspace_files = [ |
| 122 | + p for p in list(list_of_files.values())[0].keys() if "/workspace/" in p |
| 123 | + ] |
| 124 | + assert len(workspace_files) > 0 |
| 125 | + if _type == "file": |
| 126 | + file_or_folder_id = workspace_files[0] |
| 127 | + elif _type == "folder": |
| 128 | + parts = Path(workspace_files[0]).parts |
| 129 | + parts = parts[0 : parts.index("workspace") + 1] |
| 130 | + assert len(parts) > 0 |
| 131 | + folder = Path(*parts) |
| 132 | + assert folder.name == "workspace" |
| 133 | + file_or_folder_id = f"{folder}" |
| 134 | + else: |
| 135 | + pytest.fail("invalid parameter: to_check") |
| 136 | + |
101 | 137 | result = await async_jobs.submit_job( |
102 | 138 | rpc_client, |
103 | 139 | rpc_namespace=STORAGE_RPC_NAMESPACE, |
104 | 140 | job_name="start_data_export", |
105 | 141 | data_export_start=DataExportTaskStartInput( |
106 | 142 | user_id=user_id, |
107 | 143 | product_name="osparc", |
108 | | - location_id=output_file.location_id, |
109 | | - file_and_folder_ids=[output_file.file_id], |
| 144 | + location_id=0, |
| 145 | + file_and_folder_ids=[file_or_folder_id], |
110 | 146 | ), |
111 | 147 | ) |
112 | 148 | assert isinstance(result, AsyncJobGet) |
|
0 commit comments