clipwright/tests/e2e/api/test_download_all.py
pedro-bento 026f3ff271
Some checks failed
CI / unit (pull_request) Failing after 24s
CI / backend-e2e (pull_request) Successful in 1m18s
CI / dashboard-e2e (pull_request) Successful in 1m44s
test: add full E2E coverage (API, pipeline, browser)
Three-level end-to-end suite, all deterministic (no retries, no sleeps, no
unmocked network):

- tests/e2e/api (209 tests): every route in clipwright/api/app.py +
  free_tools — health/config, uploads, process submit matrix + worker/webhook/
  auto-retry/resume, status/source/download-all, edit/effects, transcript/EDL/
  rerender, scenes/reframe, subtitle, hook, Postiz, thumbnails, free tools,
  and the security/path guards.
- tests/e2e/pipeline (136 tests): every stage with real ffmpeg and stubbed
  Gemini/yt-dlp/ASR/ML — download, transcribe, scene detect, selection,
  layout, reframe/render, subtitles, hooks, watermark, thumbnails, plus the
  real CLI full pipeline via stub_env.
- dashboard/e2e (19 Playwright specs): route-interception state machine
  covering every dashboard flow; one real-backend spec left test.fixme.
- Foundation: tests/e2e/conftest.py (state isolation, no-network guard, ffmpeg
  media factory, disk-seeded jobs), FakePopen worker harness, child-process
  stub_env, architecture-consistent fixtures.
- CI: unit + backend-e2e + dashboard-e2e jobs in the python+node container;
  ffmpeg + Playwright installed in-job; no setup-node/cache (act runner).

Verified: unit 790 passed; API E2E 209 passed; pipeline E2E 136 passed;
Playwright 19 passed / 1 skipped.
2026-10-04 21:58:28 +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"