Docgenie-API / api /tests /functional /test_health_endpoints.py
Ahadhassan-2003
deploy: update HF Space
dc4e6da
"""
Functional tests β€” Health endpoints
======================================
Tests for:
GET / β†’ HealthResponse schema
GET /health β†’ HealthResponse schema
"""
import pytest
import requests
from tests.conftest import BASE_URL, TIMEOUT
class TestRootEndpoint:
"""GET / β€” root health check."""
def test_root_returns_200(self, http, base_url):
r = http.get(f"{base_url}/", timeout=TIMEOUT)
assert r.status_code == 200, f"Expected 200, got {r.status_code}: {r.text}"
def test_root_content_type_is_json(self, http, base_url):
r = http.get(f"{base_url}/", timeout=TIMEOUT)
assert "application/json" in r.headers.get("Content-Type", "")
def test_root_returns_healthy(self, root_response):
data = root_response.json()
assert data.get("status") == "healthy", f"Unexpected status: {data}"
def test_root_response_has_version(self, root_response):
data = root_response.json()
assert "version" in data, "Response missing 'version' field"
assert isinstance(data["version"], str)
assert len(data["version"]) > 0
def test_root_schema_contract(self, root_response):
"""Response must exactly match HealthResponse schema: {status, version}."""
data = root_response.json()
assert set(data.keys()) >= {"status", "version"}, (
f"Missing required fields. Got: {set(data.keys())}"
)
class TestHealthEndpoint:
"""GET /health β€” dedicated health check."""
def test_health_returns_200(self, http, base_url):
r = http.get(f"{base_url}/health", timeout=TIMEOUT)
assert r.status_code == 200, f"Expected 200, got {r.status_code}: {r.text}"
def test_health_content_type_is_json(self, http, base_url):
r = http.get(f"{base_url}/health", timeout=TIMEOUT)
assert "application/json" in r.headers.get("Content-Type", "")
def test_health_returns_healthy_status(self, health_response):
data = health_response.json()
assert data.get("status") == "healthy", f"Unexpected status: {data}"
def test_health_response_has_version(self, health_response):
data = health_response.json()
assert "version" in data
assert isinstance(data["version"], str)
def test_health_schema_contract(self, health_response):
data = health_response.json()
assert "status" in data
assert "version" in data
def test_health_and_root_agree(self, http, base_url):
"""Both endpoints must report the same status and version."""
r_root = http.get(f"{base_url}/", timeout=TIMEOUT).json()
r_health = http.get(f"{base_url}/health", timeout=TIMEOUT).json()
assert r_root["status"] == r_health["status"]
assert r_root["version"] == r_health["version"]