Skip to content

Commit 3fc1440

Browse files
committed
minor
1 parent 91a5cfb commit 3fc1440

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

services/storage/tests/unit/test_handlers_datasets.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
from models_library.projects import ProjectID
1717
from models_library.projects_nodes_io import SimcoreS3FileID
1818
from models_library.users import UserID
19-
from pydantic import ByteSize, TypeAdapter
19+
from pydantic import ByteSize
2020
from pytest_mock import MockerFixture
2121
from pytest_simcore.helpers.fastapi import url_from_operation_id
22+
from pytest_simcore.helpers.httpx_assert_checks import assert_status
2223
from pytest_simcore.helpers.parametrizations import (
2324
byte_size_ids,
2425
parametrized_file_size,
2526
)
2627
from servicelib.aiohttp import status
27-
from yarl import URL
2828

2929
pytest_simcore_core_services_selection = ["postgres"]
3030
pytest_simcore_ops_services_selection = ["adminer"]
@@ -40,15 +40,15 @@ async def test_list_dataset_files_metadata_with_no_files_returns_empty_array(
4040
url = url_from_operation_id(
4141
client,
4242
initialized_app,
43-
"list_datasets_metadata",
43+
"list_dataset_files_metadata",
4444
location_id=location_id,
45-
project_id=project_id,
45+
dataset_id=project_id,
4646
).with_query(user_id=user_id)
4747

4848
response = await client.get(f"{url}")
49-
assert response.status_code == status.HTTP_200_OK
50-
data = response.json()
49+
data, error = assert_status(response, status.HTTP_200_OK, list[FileMetaDataGet])
5150
assert data == []
51+
assert not error
5252

5353

5454
@pytest.mark.parametrize(
@@ -58,6 +58,7 @@ async def test_list_dataset_files_metadata_with_no_files_returns_empty_array(
5858
)
5959
async def test_list_dataset_files_metadata(
6060
upload_file: Callable[[ByteSize, str], Awaitable[tuple[Path, SimcoreS3FileID]]],
61+
initialized_app: FastAPI,
6162
client: AsyncClient,
6263
user_id: UserID,
6364
project_id: ProjectID,
@@ -68,15 +69,20 @@ async def test_list_dataset_files_metadata(
6869
NUM_FILES = 3
6970
for n in range(NUM_FILES):
7071
file, file_id = await upload_file(file_size, faker.file_name())
71-
url = URL(
72-
f"/v0/locations/{location_id}/datasets/{project_id}/metadata"
72+
url = url_from_operation_id(
73+
client,
74+
initialized_app,
75+
"list_dataset_files_metadata",
76+
location_id=location_id,
77+
dataset_id=project_id,
7378
).with_query(user_id=user_id)
7479

7580
response = await client.get(f"{url}")
76-
assert response.status_code == status.HTTP_200_OK
77-
data = response.json()
78-
assert data
79-
list_fmds = TypeAdapter(list[FileMetaDataGet]).validate_python(data)
81+
list_fmds, error = assert_status(
82+
response, status.HTTP_200_OK, list[FileMetaDataGet]
83+
)
84+
assert not error
85+
assert list_fmds
8086
assert len(list_fmds) == (n + 1)
8187
fmd = list_fmds[n]
8288
assert fmd.file_name == file.name
@@ -86,25 +92,33 @@ async def test_list_dataset_files_metadata(
8692

8793

8894
async def test_list_datasets_metadata(
95+
initialized_app: FastAPI,
8996
client: AsyncClient,
9097
user_id: UserID,
9198
location_id: int,
9299
project_id: ProjectID,
93100
):
94-
url = URL(f"/v0/locations/{location_id}/datasets").with_query(user_id=user_id)
101+
url = url_from_operation_id(
102+
client,
103+
initialized_app,
104+
"list_datasets_metadata",
105+
location_id=location_id,
106+
).with_query(user_id=user_id)
95107

96108
response = await client.get(f"{url}")
109+
list_datasets, error = assert_status(
110+
response, status.HTTP_200_OK, list[DatasetMetaDataGet]
111+
)
97112
assert response.status_code == status.HTTP_200_OK
98-
data = response.json()
99-
assert data
100-
list_datasets = TypeAdapter(list[DatasetMetaDataGet]).validate_python(data)
113+
assert list_datasets
101114
assert len(list_datasets) == 1
102115
dataset = list_datasets[0]
103116
assert dataset.dataset_id == project_id
104117

105118

106119
async def test_ensure_expand_dirs_defaults_true(
107120
mocker: MockerFixture,
121+
initialized_app: FastAPI,
108122
client: AsyncClient,
109123
user_id: UserID,
110124
project_id: ProjectID,
@@ -115,9 +129,13 @@ async def test_ensure_expand_dirs_defaults_true(
115129
autospec=True,
116130
)
117131

118-
url = URL(f"/v0/locations/{location_id}/datasets/{project_id}/metadata").with_query(
119-
user_id=user_id
120-
)
132+
url = url_from_operation_id(
133+
client,
134+
initialized_app,
135+
"list_dataset_files_metadata",
136+
location_id=location_id,
137+
dataset_id=project_id,
138+
).with_query(user_id=user_id)
121139

122140
await client.get(f"{url}")
123141

0 commit comments

Comments
 (0)