clipwright/tests/e2e/api/test_download_all.py
pedro-bento 0040aa49da
All checks were successful
CI / dashboard-e2e (push) Successful in 1m44s
CI / unit (push) Successful in 29s
CI / backend-e2e (push) Successful in 1m17s
test/e2e-coverage (#5)
Reviewed-on: #5
Co-authored-by: pedro-bento <mail@pbento.pt>
Co-committed-by: pedro-bento <mail@pbento.pt>
2026-10-04 22:28:46 +01:00

46 lines
1.5 KiB
Python

"""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"