"""L1 API core: the per-job "download all clips" ZIP bundle.""" import io import json import zipfile import pytest pytestmark = pytest.mark.e2e async def test_download_all_returns_a_zip_of_every_clip(client, app_state, seeded_job): job_id = seeded_job(job_id="job-zip", base="bundle", clips=2) resp = await client.get(f"/api/jobs/{job_id}/download-all") assert resp.status_code == 200 assert resp.headers["content-type"] == "application/zip" with zipfile.ZipFile(io.BytesIO(resp.content)) as zf: names = sorted(zf.namelist()) assert names == [ "clip_01_bundle_clip_1.mp4", "clip_02_bundle_clip_2.mp4", ] for name in names: assert zf.read(name) async def test_download_all_without_metadata_is_404(client): resp = await client.get("/api/jobs/nobody-home/download-all") assert resp.status_code == 404 assert resp.json()["detail"] == "Job not found" async def test_download_all_without_clip_files_is_404(client, app_state): job_id = "job-empty" job_dir = app_state.out / job_id job_dir.mkdir() # Metadata promises a clip; the file itself was never rendered. (job_dir / "empty_metadata.json").write_text(json.dumps({ "shorts": [{"start": 0.0, "end": 5.0, "video_title_for_youtube_short": "x"}], })) resp = await client.get(f"/api/jobs/{job_id}/download-all") assert resp.status_code == 404 assert resp.json()["detail"] == "No clip files found for this job"