|
14 | 14 |
|
15 | 15 | import httpx |
16 | 16 | import pytest |
17 | | -import sqlalchemy as sa |
18 | | -from aws_library.s3 import SimcoreS3API |
19 | 17 | from faker import Faker |
20 | 18 | from fastapi import FastAPI |
21 | 19 | from models_library.api_schemas_storage.storage_schemas import ( |
|
43 | 41 | from servicelib.aiohttp import status |
44 | 42 | from servicelib.fastapi.long_running_tasks.client import long_running_task_request |
45 | 43 | from settings_library.s3 import S3Settings |
46 | | -from simcore_postgres_database.storage_models import file_meta_data |
47 | 44 | from simcore_service_storage.models import SearchFilesQueryParams |
48 | 45 | from simcore_service_storage.simcore_s3_dsm import SimcoreS3DataManager |
49 | 46 | from sqlalchemy.ext.asyncio import AsyncEngine |
@@ -123,125 +120,6 @@ async def _request_copy_folders( |
123 | 120 | pytest.fail(reason="Copy folders failed!") |
124 | 121 |
|
125 | 122 |
|
126 | | -async def test_copy_folders_from_empty_project( |
127 | | - initialized_app: FastAPI, |
128 | | - client: httpx.AsyncClient, |
129 | | - user_id: UserID, |
130 | | - create_project: Callable[[], Awaitable[dict[str, Any]]], |
131 | | - sqlalchemy_async_engine: AsyncEngine, |
132 | | - storage_s3_client: SimcoreS3API, |
133 | | -): |
134 | | - # we will copy from src to dst |
135 | | - src_project = await create_project() |
136 | | - dst_project = await create_project() |
137 | | - |
138 | | - data = await _request_copy_folders( |
139 | | - initialized_app, |
140 | | - client, |
141 | | - user_id, |
142 | | - src_project, |
143 | | - dst_project, |
144 | | - nodes_map={}, |
145 | | - ) |
146 | | - assert data == jsonable_encoder(dst_project) |
147 | | - # check there is nothing in the dst project |
148 | | - async with sqlalchemy_async_engine.connect() as conn: |
149 | | - num_entries = await conn.scalar( |
150 | | - sa.select(sa.func.count()) |
151 | | - .select_from(file_meta_data) |
152 | | - .where(file_meta_data.c.project_id == dst_project["uuid"]) |
153 | | - ) |
154 | | - assert num_entries == 0 |
155 | | - |
156 | | - |
157 | | -@pytest.fixture |
158 | | -def short_dsm_cleaner_interval(monkeypatch: pytest.MonkeyPatch) -> int: |
159 | | - monkeypatch.setenv("STORAGE_CLEANER_INTERVAL_S", "1") |
160 | | - return 1 |
161 | | - |
162 | | - |
163 | | -@pytest.mark.parametrize( |
164 | | - "location_id", |
165 | | - [SimcoreS3DataManager.get_location_id()], |
166 | | - ids=[SimcoreS3DataManager.get_location_name()], |
167 | | - indirect=True, |
168 | | -) |
169 | | -@pytest.mark.parametrize( |
170 | | - "project_params", |
171 | | - [ |
172 | | - ProjectWithFilesParams( |
173 | | - num_nodes=1, |
174 | | - allowed_file_sizes=(TypeAdapter(ByteSize).validate_python("210Mib"),), |
175 | | - allowed_file_checksums=( |
176 | | - TypeAdapter(SHA256Str).validate_python( |
177 | | - "0b3216d95ec5a36c120ba16c88911dcf5ff655925d0fbdbc74cf95baf86de6fc" |
178 | | - ), |
179 | | - ), |
180 | | - workspace_files_count=0, |
181 | | - ), |
182 | | - ], |
183 | | - ids=str, |
184 | | -) |
185 | | -async def test_copy_folders_from_valid_project_with_one_large_file( |
186 | | - initialized_app: FastAPI, |
187 | | - short_dsm_cleaner_interval: int, |
188 | | - client: httpx.AsyncClient, |
189 | | - user_id: UserID, |
190 | | - create_project: Callable[[], Awaitable[dict[str, Any]]], |
191 | | - sqlalchemy_async_engine: AsyncEngine, |
192 | | - random_project_with_files: Callable[ |
193 | | - [ProjectWithFilesParams], |
194 | | - Awaitable[ |
195 | | - tuple[dict[str, Any], dict[NodeID, dict[SimcoreS3FileID, FileIDDict]]] |
196 | | - ], |
197 | | - ], |
198 | | - project_params: ProjectWithFilesParams, |
199 | | -): |
200 | | - # 1. create a src project with 1 large file |
201 | | - src_project, src_projects_list = await random_project_with_files(project_params) |
202 | | - # 2. create a dst project without files |
203 | | - dst_project, nodes_map = clone_project_data(src_project) |
204 | | - dst_project = await create_project(**dst_project) |
205 | | - # copy the project files |
206 | | - data = await _request_copy_folders( |
207 | | - initialized_app, |
208 | | - client, |
209 | | - user_id, |
210 | | - src_project, |
211 | | - dst_project, |
212 | | - nodes_map={NodeID(i): NodeID(j) for i, j in nodes_map.items()}, |
213 | | - ) |
214 | | - assert data == jsonable_encoder( |
215 | | - await get_updated_project(sqlalchemy_async_engine, dst_project["uuid"]) |
216 | | - ) |
217 | | - # check that file meta data was effectively copied |
218 | | - for src_node_id in src_projects_list: |
219 | | - dst_node_id = nodes_map.get( |
220 | | - TypeAdapter(NodeIDStr).validate_python(f"{src_node_id}") |
221 | | - ) |
222 | | - assert dst_node_id |
223 | | - for src_file_id, src_file in src_projects_list[src_node_id].items(): |
224 | | - path: Any = src_file["path"] |
225 | | - assert isinstance(path, Path) |
226 | | - checksum: Any = src_file["sha256_checksum"] |
227 | | - assert isinstance(checksum, str) |
228 | | - await assert_file_meta_data_in_db( |
229 | | - sqlalchemy_async_engine, |
230 | | - file_id=TypeAdapter(SimcoreS3FileID).validate_python( |
231 | | - f"{src_file_id}".replace( |
232 | | - f"{src_project['uuid']}", dst_project["uuid"] |
233 | | - ).replace(f"{src_node_id}", f"{dst_node_id}") |
234 | | - ), |
235 | | - expected_entry_exists=True, |
236 | | - expected_file_size=path.stat().st_size, |
237 | | - expected_upload_id=None, |
238 | | - expected_upload_expiration_date=None, |
239 | | - expected_sha256_checksum=TypeAdapter(SHA256Str).validate_python( |
240 | | - checksum |
241 | | - ), |
242 | | - ) |
243 | | - |
244 | | - |
245 | 123 | @pytest.mark.parametrize( |
246 | 124 | "location_id", |
247 | 125 | [SimcoreS3DataManager.get_location_id()], |
|
0 commit comments