"""L1 API core: job status polling and source-video streaming.""" import pytest pytestmark = pytest.mark.e2e async def test_status_of_a_queued_job(client, app_state): job_id = "job-status" app_state.app.jobs[job_id] = { "status": "queued", "logs": app_state.app._TimedLog(["Job queued."]), "result": None, "partial": None, } app_state.app._enqueue_job(job_id) resp = await client.get(f"/api/status/{job_id}") assert resp.status_code == 200 body = resp.json() assert body["status"] == "queued" assert body["logs"] == ["Job queued."] assert body["log_times"] is not None and len(body["log_times"]) == 1 assert body["queue"]["position"] == 1 assert body["result"] is None async def test_status_of_a_disk_recovered_job(client, app_state, seeded_job): job_id = seeded_job(job_id="job-status-disk", base="status", clips=1) resp = await client.get(f"/api/status/{job_id}") assert resp.status_code == 200 body = resp.json() assert body["status"] == "completed" assert body["result"]["clips"][0]["video_url"].endswith("/status_clip_1.mp4") # A completed job is not on the queue. assert body["queue"] is None async def test_status_unknown_job_is_404(client): resp = await client.get("/api/status/nobody-home") assert resp.status_code == 404 assert resp.json()["detail"] == "Job not found" async def test_source_url_returns_the_plain_path(client): resp = await client.get("/api/source-url/any-job") assert resp.status_code == 200 assert resp.json() == {"url": "/api/source/any-job"} async def test_source_without_a_file_is_404(client): resp = await client.get("/api/source/nobody-home") assert resp.status_code == 404 assert resp.json()["detail"] == "Source not found" async def test_source_streams_an_upload(client, app_state): job_id = "job-source" payload = b"pretend this is a video" (app_state.up / f"{job_id}_source.mp4").write_bytes(payload) resp = await client.get(f"/api/source/{job_id}") assert resp.status_code == 200 assert resp.content == payload assert resp.headers["content-type"] == "video/mp4"