2026-09-01 16:10:14 +08:00

50 lines
1.4 KiB
Python

"""API startup and health checks."""
from pathlib import Path
from fastapi.testclient import TestClient
from ekp_api.main import create_app
from ekp_core.config import Settings
def test_health_endpoint_uses_supplied_settings(isolated_settings_environment: None) -> None:
settings = Settings(
app_env="test",
app_name="ekp-test",
)
with TestClient(create_app(settings)) as client:
response = client.get("/healthz")
assert response.status_code == 200
assert response.json() == {
"status": "ok",
"application": "ekp-test",
"environment": "test",
}
def test_openapi_is_versioned(isolated_settings_environment: None) -> None:
settings = Settings(app_env="test")
with TestClient(create_app(settings)) as client:
response = client.get("/api/v1/openapi.json")
assert response.status_code == 200
def test_business_providers_are_lazy_for_health_checks(
tmp_path: Path,
isolated_settings_environment: None,
) -> None:
"""Starting or probing the API must not require Qianfan/Mochow credentials."""
settings = Settings(app_env="test", object_storage_path=tmp_path / "storage")
with TestClient(create_app(settings)) as client:
health_response = client.get("/healthz")
documents_response = client.get("/api/v1/documents")
assert health_response.status_code == 200
assert documents_response.status_code == 503