test_health_endpoint.py
1 """ 2 Integration tests for the FastAPI health check endpoint. 3 4 These tests use FastAPI's TestClient to test the actual endpoints without 5 running a server. 6 """ 7 8 import pytest 9 10 11 @pytest.mark.integration 12 def test_health_returns_200(): 13 """Test that health endpoint returns 200 OK.""" 14 # Import here to handle potential venv generation failures gracefully 15 try: 16 from fastapi.testclient import TestClient 17 18 from main import app 19 except Exception as e: 20 pytest.skip(f"Failed to import app (venv generation issue?): {e}") 21 22 client = TestClient(app) 23 response = client.get("/") 24 25 assert response.status_code == 200 26 27 28 @pytest.mark.integration 29 def test_health_response_format(): 30 """Test that health endpoint returns correct JSON format.""" 31 try: 32 from fastapi.testclient import TestClient 33 34 from main import app 35 except Exception as e: 36 pytest.skip(f"Failed to import app (venv generation issue?): {e}") 37 38 client = TestClient(app) 39 response = client.get("/") 40 41 assert response.status_code == 200 42 data = response.json() 43 assert "healthy" in data 44 assert isinstance(data["healthy"], bool) 45 assert data["healthy"] is True