"""HTTP surface of the service.""" from __future__ import annotations import pytest from fastapi.testclient import TestClient from app.main import app @pytest.fixture def client(): with TestClient(app) as test_client: yield test_client def test_health_is_available(client) -> None: response = client.get("/health") assert response.status_code == 200 body = response.json() assert body["status"] in ("ok", "degraded") assert "engines" in body def test_version_reports_the_application(client) -> None: response = client.get("/version") assert response.status_code == 200 assert response.json()["language"] == "python" def test_openapi_is_generated(client) -> None: response = client.get("/openapi.json") assert response.status_code == 200 paths = response.json()["paths"] assert "/convert" in paths assert "/jobs" in paths assert "/jobs/{job_id}/result" in paths def test_source_requires_exactly_one_input(client) -> None: response = client.post( "/convert", json={"source": {"url": "https://example.com/a.html", "html": ""}}, ) assert response.status_code == 422 def test_empty_source_is_rejected(client) -> None: response = client.post("/convert", json={"source": {}}) assert response.status_code == 422 def test_private_address_is_refused(client) -> None: response = client.post("/convert", json={"source": {"url": "http://127.0.0.1:8000/a.html"}}) assert response.status_code == 400 assert response.json()["error_code"] == "blocked_target" def test_unknown_job_returns_404(client) -> None: response = client.get("/jobs/00000000-0000-0000-0000-000000000000") assert response.status_code == 404 assert response.json()["error_code"] == "job_not_found"