feat(v2): expose execution control and event APIs

This commit is contained in:
2026-07-27 21:54:05 +02:00
parent 057895f138
commit 474efa526f
3 changed files with 162 additions and 4 deletions
+32 -2
View File
@@ -6,12 +6,15 @@ import httpx
import pytest
from backup_tool.api.app import create_app
from backup_tool.config import Settings
from backup_tool.db.models import Execution
PASSWORD = "correct-horse-battery-staple"
async def login(client: httpx.AsyncClient) -> dict[str, str]:
response = await client.post("/api/v2/setup", json={"username": "admin", "password": PASSWORD})
response = await client.post(
"/api/v2/setup", json={"username": "admin", "password": PASSWORD}
)
assert response.status_code == 201
return {"X-CSRF-Token": client.cookies["backup_tool_csrf"]}
@@ -46,7 +49,9 @@ async def test_local_source_probe_archive_and_repository_targeted_job(
async with app.state.engine.begin() as connection:
await connection.run_sync(Base.metadata.create_all)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(transport=transport, base_url="https://test") as client:
async with httpx.AsyncClient(
transport=transport, base_url="https://test"
) as client:
headers = await login(client)
repository = await client.post(
"/api/v2/repositories",
@@ -94,6 +99,31 @@ async def test_local_source_probe_archive_and_repository_targeted_job(
)
assert duplicate.status_code == 409
assert duplicate.json()["code"] == "execution_active"
polled = await client.get(f"/api/v2/executions/{execution.json()['id']}", headers=headers)
assert polled.status_code == 200
assert polled.json()["state"] == "queued"
cancellation = await client.post(
f"/api/v2/executions/{execution.json()['id']}/cancel", headers=headers
)
assert cancellation.status_code == 202
assert cancellation.json()["state"] == "cancelling"
async with app.state.sessions() as db:
stored = await db.get(Execution, execution.json()["id"])
assert stored is not None
stored.state = "failed"
stored.reason_code = "timeout"
await db.commit()
retried = await client.post(
f"/api/v2/executions/{execution.json()['id']}/retry", headers=headers
)
assert retried.status_code == 202
assert retried.json()["id"] == execution.json()["id"]
assert retried.json()["attempt"] == 2
stream = await client.get(
f"/api/v2/executions/{execution.json()['id']}/events", headers=headers
)
assert stream.status_code == 200
assert "event: execution" in stream.text
archived = await client.delete(f"/api/v2/sources/{source_id}", headers=headers)
assert archived.status_code == 204
assert (