Skip to content

Commit 42f66c1

Browse files
committed
fix tests
1 parent abfac69 commit 42f66c1

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

services/api-server/src/simcore_service_api_server/api/routes/files.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
)
1616
from models_library.basic_types import SHA256Str
1717
from models_library.projects_nodes_io import NodeID
18-
from pydantic import AnyUrl, PositiveInt, TypeAdapter, ValidationError
18+
from pydantic import PositiveInt, ValidationError
1919
from servicelib.fastapi.requests_decorators import cancel_on_disconnect
2020
from simcore_sdk.node_ports_common.constants import SIMCORE_LOCATION
2121
from simcore_sdk.node_ports_common.file_io_utils import UploadableFileObject
2222
from simcore_sdk.node_ports_common.filemanager import (
2323
UploadedFile,
2424
UploadedFolder,
25-
abort_upload,
2625
)
2726
from simcore_sdk.node_ports_common.filemanager import upload_path as storage_upload_path
2827
from starlette.datastructures import URL
@@ -413,12 +412,7 @@ async def abort_multipart_upload(
413412
file = await _create_domain_file(
414413
webserver_api=webserver_api, file_id=file_id, client_file=client_file
415414
)
416-
abort_link: URL = await storage_client.create_abort_upload_link(
417-
file=file, query={"user_id": str(user_id)}
418-
)
419-
await abort_upload(
420-
abort_upload_link=TypeAdapter(AnyUrl).validate_python(str(abort_link))
421-
)
415+
await storage_client.abort_file_upload(user_id=user_id, file=file)
422416

423417

424418
@router.post(

services/api-server/src/simcore_service_api_server/services_http/storage.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async def get_file_upload_links(
189189

190190
# complete_upload_file
191191
response = await self.client.put(
192-
f"/locations/{self.SIMCORE_S3_ID}/files/{file.storage_file_id}",
192+
f"/locations/{self.SIMCORE_S3_ID}/files/{file.quoted_storage_file_id}:upload",
193193
params=query_params,
194194
)
195195
response.raise_for_status()
@@ -242,6 +242,14 @@ async def complete_file_upload(self, *, user_id: int, file: File) -> ETag:
242242
detail=msg,
243243
)
244244

245+
@_exception_mapper(http_status_map={})
246+
async def abort_file_upload(self, *, user_id: int, file: File) -> None:
247+
response = await self.client.post(
248+
f"/locations/{self.SIMCORE_S3_ID}/files/{file.quoted_storage_file_id}:abort",
249+
params={"user_id": f"{user_id}"},
250+
)
251+
response.raise_for_status()
252+
245253
async def create_complete_upload_link(
246254
self, *, file: File, query: dict[str, str] | None = None
247255
) -> URL:

services/api-server/tests/unit/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def generate_future_link(request: Request, **kwargs):
494494

495495
respx_mock.post(
496496
re.compile(
497-
r"^http://[a-z\-_]*storage:[0-9]+/v0/locations/[0-9]+/files/.+:abort$"
497+
r"^http://[a-z\-_]*storage:[0-9]+/v0/locations/[0-9]+/files/.+:abort(?:\?.*)?$"
498498
),
499499
name="abort_upload_file_v0_locations__location_id__files__file_id__abort_post",
500500
).respond(

services/api-server/tests/unit/test_api_files.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import pytest
1515
import respx
1616
import yarl
17-
from aiohttp import client_exceptions as aiohttp_client_exceptions
18-
from aioresponses import aioresponses as AioResponsesMock
1917
from faker import Faker
2018
from fastapi import status
2119
from fastapi.encoders import jsonable_encoder
@@ -286,15 +284,12 @@ async def test_get_upload_links(
286284
async def test_get_upload_links_timeout(
287285
client: AsyncClient,
288286
auth: httpx.BasicAuth,
289-
aioresponses_mocker: AioResponsesMock,
287+
mocked_storage_rest_api_base: MockRouter,
290288
mocker: MockerFixture,
291289
):
292-
assert aioresponses_mocker # nosec
293-
aioresponses_mocker.put(
290+
mocked_endpoint = mocked_storage_rest_api_base.put(
294291
re.compile(r"^http://[a-z\-_]*storage:[0-9]+/v0/locations/[0-9]+/files.+$"),
295-
repeat=True,
296-
exception=aiohttp_client_exceptions.ServerTimeoutError(),
297-
)
292+
).mock(side_effect=httpx.ReadTimeout("Mocked timeout error"))
298293

299294
msg = {
300295
"filename": DummyFileData.file().filename,
@@ -304,6 +299,7 @@ async def test_get_upload_links_timeout(
304299

305300
response = await client.post(f"{API_VTAG}/files/content", json=msg, auth=auth)
306301

302+
assert mocked_endpoint.called
307303
assert response.status_code == status.HTTP_504_GATEWAY_TIMEOUT
308304

309305

0 commit comments

Comments
 (0)