generated from kgod/ai-review-template
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
"""Production docs gate: /docs, /redoc, /openapi.json 404 unless RESUME_AGENT_API_DOCS opts in."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.asgi import application
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _docs_flag_cleared(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.delenv("RESUME_AGENT_API_DOCS", raising=False)
|
|
|
|
|
|
def test_api_docs_are_not_served_by_default() -> None:
|
|
client = TestClient(application)
|
|
assert client.get("/docs").status_code == 404
|
|
assert client.get("/redoc").status_code == 404
|
|
assert client.get("/openapi.json").status_code == 404
|
|
|
|
|
|
def test_app_routes_still_work_through_the_gate() -> None:
|
|
client = TestClient(application)
|
|
assert client.get("/health").status_code == 200
|
|
|
|
|
|
def test_api_docs_can_be_enabled_explicitly(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("RESUME_AGENT_API_DOCS", "1")
|
|
client = TestClient(application)
|
|
assert client.get("/openapi.json").status_code == 200
|