Skip to content

Commit 9ae8d2d

Browse files
committed
refactor
1 parent e0e5bbb commit 9ae8d2d

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

services/storage/tests/unit/test__legacy_storage_sdk_compatibility.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
"""
1313

1414
import logging
15+
from collections.abc import AsyncIterator
1516
from pathlib import Path
1617
from threading import Thread
17-
from typing import AsyncIterator
1818

1919
import aiohttp
2020
import httpx
2121
import pytest
2222
import uvicorn
2323
from faker import Faker
24-
from models_library.projects_nodes_io import LocationID, SimcoreS3FileID
24+
from models_library.projects_nodes_io import SimcoreS3FileID
2525
from models_library.users import UserID
2626
from pytest_simcore.helpers.logging_tools import log_context
2727
from servicelib.utils import unused_port
@@ -112,21 +112,22 @@ def file_id(simcore_file_id: SimcoreS3FileID) -> str:
112112

113113

114114
@pytest.fixture
115-
def location_id() -> LocationID:
116-
return SimcoreS3DataManager.get_location_id()
117-
118-
119-
@pytest.fixture
120-
def location_name() -> str:
115+
def simcore_location_name() -> str:
121116
return SimcoreS3DataManager.get_location_name()
122117

123118

119+
@pytest.mark.parametrize(
120+
"location_id",
121+
[SimcoreS3DataManager.get_location_id()],
122+
ids=[SimcoreS3DataManager.get_location_name()],
123+
indirect=True,
124+
)
124125
async def test_storage_client_used_in_simcore_sdk_0_3_2(
125126
real_storage_server: URL,
126127
str_user_id: str,
127128
file_id: str,
128129
location_id: int,
129-
location_name: str,
130+
simcore_location_name: str,
130131
tmp_path: Path,
131132
faker: Faker,
132133
):
@@ -211,7 +212,7 @@ async def test_storage_client_used_in_simcore_sdk_0_3_2(
211212
resp_model = await api.get_storage_locations(user_id=str_user_id)
212213
print(f"{resp_model=}")
213214
for location in resp_model.data:
214-
assert location["name"] == location_name
215+
assert location["name"] == simcore_location_name
215216
assert location["id"] == location_id
216217

217218
# _get_download_link

services/storage/tests/unit/test_handlers_datasets.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
parametrized_file_size,
2929
)
3030
from servicelib.aiohttp import status
31+
from simcore_service_storage.simcore_s3_dsm import SimcoreS3DataManager
3132

3233
pytest_simcore_core_services_selection = ["postgres"]
3334
pytest_simcore_ops_services_selection = ["adminer"]
@@ -54,6 +55,12 @@ async def test_list_dataset_files_metadata_with_no_files_returns_empty_array(
5455
assert not error
5556

5657

58+
@pytest.mark.parametrize(
59+
"location_id",
60+
[SimcoreS3DataManager.get_location_id()],
61+
ids=[SimcoreS3DataManager.get_location_name()],
62+
indirect=True,
63+
)
5764
@pytest.mark.parametrize(
5865
"file_size",
5966
[parametrized_file_size("100Mib")],
@@ -94,6 +101,12 @@ async def test_list_dataset_files_metadata(
94101
assert fmd.file_size == file.stat().st_size
95102

96103

104+
@pytest.mark.parametrize(
105+
"location_id",
106+
[SimcoreS3DataManager.get_location_id()],
107+
ids=[SimcoreS3DataManager.get_location_name()],
108+
indirect=True,
109+
)
97110
async def test_list_datasets_metadata(
98111
initialized_app: FastAPI,
99112
client: AsyncClient,
@@ -119,6 +132,12 @@ async def test_list_datasets_metadata(
119132
assert dataset.dataset_id == project_id
120133

121134

135+
@pytest.mark.parametrize(
136+
"location_id",
137+
[SimcoreS3DataManager.get_location_id()],
138+
ids=[SimcoreS3DataManager.get_location_name()],
139+
indirect=True,
140+
)
122141
async def test_ensure_expand_dirs_defaults_true(
123142
mocker: MockerFixture,
124143
initialized_app: FastAPI,

services/storage/tests/unit/test_handlers_files.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from simcore_service_storage.modules.long_running_tasks import (
5959
get_completed_upload_tasks,
6060
)
61+
from simcore_service_storage.simcore_s3_dsm import SimcoreS3DataManager
6162
from sqlalchemy.ext.asyncio import AsyncEngine
6263
from tenacity.asyncio import AsyncRetrying
6364
from tenacity.retry import retry_if_exception_type
@@ -87,9 +88,9 @@ async def assert_multipart_uploads_in_progress(
8788
expected_upload_ids: list[str] | None,
8889
):
8990
"""if None is passed, then it checks that no uploads are in progress"""
90-
list_uploads: list[
91-
tuple[UploadID, S3ObjectKey]
92-
] = await storage_s3_client.list_ongoing_multipart_uploads(bucket=storage_s3_bucket)
91+
list_uploads: list[tuple[UploadID, S3ObjectKey]] = (
92+
await storage_s3_client.list_ongoing_multipart_uploads(bucket=storage_s3_bucket)
93+
)
9394
if expected_upload_ids is None:
9495
assert (
9596
not list_uploads
@@ -586,6 +587,12 @@ async def test_upload_real_file(
586587
await upload_file(file_size, complex_file_name)
587588

588589

590+
@pytest.mark.parametrize(
591+
"location_id",
592+
[SimcoreS3DataManager.get_location_id()],
593+
ids=[SimcoreS3DataManager.get_location_name()],
594+
indirect=True,
595+
)
589596
@pytest.mark.parametrize(
590597
"file_size",
591598
[
@@ -830,6 +837,12 @@ async def test_upload_real_file_with_s3_client(
830837
assert s3_metadata.e_tag == completion_etag
831838

832839

840+
@pytest.mark.parametrize(
841+
"location_id",
842+
[SimcoreS3DataManager.get_location_id()],
843+
ids=[SimcoreS3DataManager.get_location_name()],
844+
indirect=True,
845+
)
833846
@pytest.mark.parametrize(
834847
"file_size",
835848
[
@@ -930,7 +943,7 @@ async def _assert_file_downloaded(
930943
async def test_download_file_no_file_was_uploaded(
931944
initialized_app: FastAPI,
932945
client: httpx.AsyncClient,
933-
location_id: int,
946+
location_id: LocationID,
934947
project_id: ProjectID,
935948
node_id: NodeID,
936949
user_id: UserID,
@@ -966,7 +979,7 @@ async def test_download_file_1_to_1_with_file_meta_data(
966979
client: httpx.AsyncClient,
967980
file_size: ByteSize,
968981
upload_file: Callable[[ByteSize, str], Awaitable[tuple[Path, SimcoreS3FileID]]],
969-
location_id: int,
982+
location_id: LocationID,
970983
user_id: UserID,
971984
storage_s3_client: SimcoreS3API,
972985
storage_s3_bucket: S3BucketName,
@@ -1005,7 +1018,7 @@ async def test_download_file_from_inside_a_directory(
10051018
initialized_app: FastAPI,
10061019
client: httpx.AsyncClient,
10071020
file_size: ByteSize,
1008-
location_id: int,
1021+
location_id: LocationID,
10091022
user_id: UserID,
10101023
project_id: ProjectID,
10111024
node_id: NodeID,
@@ -1066,7 +1079,7 @@ async def test_download_file_from_inside_a_directory(
10661079
async def test_download_file_the_file_is_missing_from_the_directory(
10671080
initialized_app: FastAPI,
10681081
client: httpx.AsyncClient,
1069-
location_id: int,
1082+
location_id: LocationID,
10701083
user_id: UserID,
10711084
project_id: ProjectID,
10721085
node_id: NodeID,
@@ -1099,7 +1112,7 @@ async def test_download_file_the_file_is_missing_from_the_directory(
10991112
async def test_download_file_access_rights(
11001113
initialized_app: FastAPI,
11011114
client: httpx.AsyncClient,
1102-
location_id: int,
1115+
location_id: LocationID,
11031116
user_id: UserID,
11041117
storage_s3_client: SimcoreS3API,
11051118
storage_s3_bucket: S3BucketName,
@@ -1144,7 +1157,7 @@ async def test_delete_file(
11441157
client: httpx.AsyncClient,
11451158
file_size: ByteSize,
11461159
upload_file: Callable[[ByteSize, str], Awaitable[tuple[Path, SimcoreS3FileID]]],
1147-
location_id: int,
1160+
location_id: LocationID,
11481161
user_id: UserID,
11491162
faker: Faker,
11501163
):
@@ -1321,7 +1334,7 @@ async def test_ensure_expand_dirs_defaults_true(
13211334
mocker: MockerFixture,
13221335
client: httpx.AsyncClient,
13231336
user_id: UserID,
1324-
location_id: int,
1337+
location_id: LocationID,
13251338
):
13261339
mocked_object = mocker.patch(
13271340
"simcore_service_storage.simcore_s3_dsm.SimcoreS3DataManager.list_files",

0 commit comments

Comments
 (0)