clipwright/tests/e2e/api/test_health_config.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

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