Skip to content

Commit c8c46ee

Browse files
committed
fix tests
1 parent 30ca456 commit c8c46ee

File tree

5 files changed

+32
-101
lines changed

5 files changed

+32
-101
lines changed

api/specs/web-server/_long_running_tasks.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
# pylint: disable=too-many-arguments
55

66

7-
from typing import Annotated
7+
from typing import Annotated, Any
88

99
from fastapi import APIRouter, Depends, status
1010
from models_library.generics import Envelope
11+
from models_library.rest_error import EnvelopedError
1112
from servicelib.aiohttp.long_running_tasks._routes import _PathParam
1213
from servicelib.long_running_tasks._models import TaskGet, TaskStatus
1314
from simcore_service_webserver._meta import API_VTAG
15+
from simcore_service_webserver.tasks._exception_handlers import (
16+
_TO_HTTP_ERROR_MAP as data_export_http_error_map,
17+
)
1418

1519
router = APIRouter(
1620
prefix=f"/{API_VTAG}",
@@ -19,37 +23,46 @@
1923
],
2024
)
2125

26+
_data_export_responses: dict[int | str, dict[str, Any]] = {
27+
i.status_code: {"model": EnvelopedError}
28+
for i in data_export_http_error_map.values()
29+
}
30+
2231

2332
@router.get(
2433
"/tasks",
2534
response_model=Envelope[list[TaskGet]],
35+
name="get_async_jobs",
36+
responses=_data_export_responses,
2637
)
27-
def list_tasks():
28-
...
38+
def list_tasks(): ...
2939

3040

3141
@router.get(
3242
"/tasks/{task_id}",
3343
response_model=Envelope[TaskStatus],
44+
name="get_async_job_status",
45+
responses=_data_export_responses,
3446
)
3547
def get_task_status(
3648
_path_params: Annotated[_PathParam, Depends()],
37-
):
38-
...
49+
): ...
3950

4051

4152
@router.delete(
4253
"/tasks/{task_id}",
54+
name="abort_async_job",
55+
responses=_data_export_responses,
4356
status_code=status.HTTP_204_NO_CONTENT,
4457
)
4558
def cancel_and_delete_task(
4659
_path_params: Annotated[_PathParam, Depends()],
47-
):
48-
...
60+
): ...
4961

5062

5163
@router.get("/tasks/{task_id}/result")
5264
def get_task_result(
5365
_path_params: Annotated[_PathParam, Depends()],
54-
):
55-
...
66+
name="get_async_job_result",
67+
responses=_data_export_responses,
68+
): ...

api/specs/web-server/_storage.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
from fastapi import APIRouter, Depends, Query, status
1010
from models_library.api_schemas_long_running_tasks.tasks import (
1111
TaskGet,
12-
TaskResult,
13-
TaskStatus,
1412
)
15-
from models_library.api_schemas_rpc_async_jobs.async_jobs import AsyncJobId
1613
from models_library.api_schemas_storage.storage_schemas import (
1714
FileLocation,
1815
FileMetaDataGet,
@@ -226,43 +223,3 @@ async def is_completed_upload_file(
226223
)
227224
async def export_data(data_export: DataExportPost, location_id: LocationID):
228225
"""Trigger data export. Returns async job id for getting status and results"""
229-
230-
231-
@router.get(
232-
"/storage/async-jobs/{job_id}/status",
233-
response_model=Envelope[TaskStatus],
234-
name="get_async_job_status",
235-
responses=_data_export_responses,
236-
)
237-
async def get_async_job_status(job_id: AsyncJobId):
238-
"""Get async job status"""
239-
240-
241-
@router.post(
242-
"/storage/async-jobs/{job_id}:abort",
243-
name="abort_async_job",
244-
responses=_data_export_responses,
245-
status_code=status.HTTP_204_NO_CONTENT,
246-
)
247-
async def abort_async_job(job_id: AsyncJobId):
248-
"""aborts execution of an async job"""
249-
250-
251-
@router.get(
252-
"/storage/async-jobs/{job_id}/result",
253-
response_model=Envelope[TaskResult],
254-
name="get_async_job_result",
255-
responses=_data_export_responses,
256-
)
257-
async def get_async_job_result(job_id: AsyncJobId):
258-
"""Get the result of the async job"""
259-
260-
261-
@router.get(
262-
"/storage/async-jobs",
263-
response_model=Envelope[list[TaskResult]],
264-
name="get_async_jobs",
265-
responses=_data_export_responses,
266-
)
267-
async def get_async_jobs():
268-
"""Returns the user's async jobs"""

api/specs/web-server/_tasks.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

services/web/server/src/simcore_service_webserver/tasks/_rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ async def get_async_job_status(request: web.Request) -> web.Response:
139139
)
140140

141141

142-
@routes.post(
143-
_task_prefix + "/{task_id}:abort",
142+
@routes.delete(
143+
_task_prefix + "/{task_id}",
144144
name="abort_async_job",
145145
)
146146
@login_required

services/web/server/tests/unit/with_dbs/01/storage/test_storage_rpc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,19 @@ async def test_abort_async_jobs(
182182
user_role: UserRole,
183183
logged_user: UserInfoDict,
184184
client: TestClient,
185-
create_storage_rpc_client_mock: Callable[[str, Any], None],
185+
create_storage_rpc_client_mock: Callable[[str, str, Any], None],
186186
faker: Faker,
187187
backend_result_or_exception: Any,
188188
expected_status: int,
189189
):
190190
_job_id = AsyncJobId(faker.uuid4())
191-
create_storage_rpc_client_mock(abort.__name__, backend_result_or_exception)
191+
create_storage_rpc_client_mock(
192+
"simcore_service_webserver.tasks._rest",
193+
abort.__name__,
194+
backend_result_or_exception,
195+
)
192196

193-
response = await client.post(f"/{API_VERSION}/storage/async-jobs/{_job_id}:abort")
197+
response = await client.delete(f"/{API_VERSION}/tasks/{_job_id}")
194198
assert response.status == expected_status
195199

196200

@@ -284,7 +288,7 @@ async def test_get_user_async_jobs(
284288
TaskStatus,
285289
),
286290
(
287-
"POST",
291+
"DELETE",
288292
"abort_href",
289293
abort.__name__,
290294
AsyncJobAbort(result=True, job_id=AsyncJobId(_faker.uuid4())),

0 commit comments

Comments
 (0)