feat: annuleren taak toegevoegd

This commit is contained in:
kodi
2026-03-15 13:06:48 +01:00
parent 7d910479f9
commit a52493459a
32 changed files with 835 additions and 61 deletions
@@ -40,6 +40,14 @@ class TasksApiGoldenTest(unittest.TestCase):
return asyncio.run(_run())
def _post(self, url: str, payload: dict | None = None) -> httpx.Response:
async def _run() -> httpx.Response:
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:
return await client.post(url, json=payload)
return asyncio.run(_run())
def _insert_task(
self,
*,
@@ -265,6 +273,78 @@ class TasksApiGoldenTest(unittest.TestCase):
self.assertEqual(body["total_items"], 1)
self.assertEqual(body["current_item"], "storage1/trash.txt")
def test_cancel_running_delete_task_returns_cancelling(self) -> None:
self._insert_task(
task_id="task-delete",
operation="delete",
status="running",
source="storage1/trash.txt",
destination="",
created_at="2026-03-10T10:00:00Z",
started_at="2026-03-10T10:00:01Z",
done_items=0,
total_items=1,
current_item="storage1/trash.txt",
)
response = self._post("/api/tasks/task-delete/cancel")
self.assertEqual(response.status_code, 200)
body = response.json()
self.assertEqual(body["operation"], "delete")
self.assertEqual(body["status"], "cancelling")
self.assertEqual(body["current_item"], "storage1/trash.txt")
def test_cancel_completed_task_rejected(self) -> None:
self._insert_task(
task_id="task-copy",
operation="copy",
status="completed",
source="storage1/a.txt",
destination="storage2/a.txt",
created_at="2026-03-10T10:00:00Z",
finished_at="2026-03-10T10:00:04Z",
)
response = self._post("/api/tasks/task-copy/cancel")
self.assertEqual(response.status_code, 409)
self.assertEqual(
response.json(),
{
"error": {
"code": "task_not_cancellable",
"message": "Task cannot be cancelled",
"details": {"task_id": "task-copy", "status": "completed"},
}
},
)
def test_cancel_download_task_rejected(self) -> None:
self._insert_task(
task_id="task-download",
operation="download",
status="preparing",
source="single_directory_zip",
destination="docs.zip",
created_at="2026-03-10T10:00:00Z",
started_at="2026-03-10T10:00:01Z",
)
response = self._post("/api/tasks/task-download/cancel")
self.assertEqual(response.status_code, 409)
self.assertEqual(
response.json(),
{
"error": {
"code": "task_not_cancellable",
"message": "Task cannot be cancelled",
"details": {"task_id": "task-download", "status": "preparing"},
}
},
)
def test_get_task_detail_ready_archive_download(self) -> None:
self._insert_task(
task_id="task-download-ready",