clipwright/tests/e2e/api/test_health_config.py
pedro-bento 97f813553d 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 22:12:21 +01:00

65 lines
2.3 KiB
Python

"""L1 API core: liveness/readiness probes and the dashboard bootstrap config.
Drives the real app through ``httpx.ASGITransport`` (no lifespan), so the
``_stopping`` flag is flipped by hand the same way SIGTERM does at runtime.
"""
import pytest
pytestmark = pytest.mark.e2e
async def test_health_is_ok(client):
resp = await client.get("/health")
assert resp.status_code == 200
assert resp.json() == {"status": "ok"}
async def test_health_ready_when_running(client, app_state):
app_state.app._stopping = False
resp = await client.get("/health/ready")
assert resp.status_code == 200
assert resp.json() == {"status": "ready"}
async def test_health_ready_is_503_while_stopping(client, app_state, monkeypatch):
monkeypatch.setattr(app_state.app, "_stopping", True)
resp = await client.get("/health/ready")
assert resp.status_code == 503
assert resp.json() == {"status": "stopping"}
async def test_config_youtube_enabled(client, app_state, monkeypatch):
monkeypatch.setattr(app_state.app, "DISABLE_YOUTUBE_URL", False)
monkeypatch.delenv("LLM_BASE_URL", raising=False)
monkeypatch.delenv("LLM_PROVIDER", raising=False)
resp = await client.get("/api/config")
assert resp.status_code == 200
body = resp.json()
assert body["youtubeUrlEnabled"] is True
assert body["billingEnabled"] is False
assert body["jobRetentionSeconds"] == app_state.app.JOB_RETENTION_SECONDS
# No OpenAI-compatible server configured -> the dashboard is told nothing.
assert body["localLlm"] is None
async def test_config_youtube_disabled(client, app_state, monkeypatch):
monkeypatch.setattr(app_state.app, "DISABLE_YOUTUBE_URL", True)
resp = await client.get("/api/config")
assert resp.status_code == 200
assert resp.json()["youtubeUrlEnabled"] is False
async def test_config_describes_local_llm(client, app_state, monkeypatch):
monkeypatch.setenv("LLM_PROVIDER", "openai")
monkeypatch.setenv("LLM_BASE_URL", "http://127.0.0.1:11434")
monkeypatch.delenv("LLM_MODEL", raising=False)
resp = await client.get("/api/config")
assert resp.status_code == 200
assert resp.json()["localLlm"] == {
"provider": "openai",
"model": "llama3.1:8b",
"baseUrl": "http://127.0.0.1:11434",
}