test_health.py
1 """ 2 Tests for health check endpoints. 3 """ 4 5 import pytest 6 from fastapi.testclient import TestClient 7 8 9 def test_health_check(client: TestClient): 10 """Test basic health check endpoint.""" 11 response = client.get("/v1/health") 12 assert response.status_code == 200 13 data = response.json() 14 assert data["status"] == "healthy" 15 assert data["version"] == "v1" 16 assert "X-Request-ID" in response.headers 17 assert "X-Process-Time" in response.headers 18 19 20 def test_health_check_root(client: TestClient): 21 """Test root health check endpoint (convenience route).""" 22 response = client.get("/health") 23 assert response.status_code == 200 24 data = response.json() 25 assert data["status"] == "healthy" 26 assert data["version"] == "v1" 27 28 29 def test_status_endpoint(client: TestClient): 30 """Test status endpoint.""" 31 response = client.get("/v1/status") 32 assert response.status_code == 200 33 data = response.json() 34 assert "status" in data 35 assert "version" in data 36 assert "environment" in data 37 assert "rpc_connected" in data 38 assert "components" in data 39 40 41 def test_detailed_health_check(client: TestClient): 42 """Test detailed health check endpoint.""" 43 response = client.get("/v1/health/detailed") 44 assert response.status_code == 200 45 data = response.json() 46 assert "status" in data 47 assert "version" in data 48 assert "timestamp" in data 49 assert "components" in data 50 assert "rpc_status" in data 51 assert "sdk_status" in data 52 53 # Check component structure 54 assert "api" in data["components"] 55 assert "rpc" in data["components"] 56 assert "sdk" in data["components"] 57 58 59 def test_metrics_endpoint(client: TestClient): 60 """Test metrics endpoint.""" 61 response = client.get("/v1/metrics") 62 assert response.status_code == 200 63 data = response.json() 64 assert "cache" in data 65 assert "transactions" in data 66 assert "rpc" in data 67 assert "rate_limits" in data 68 69 # Check cache stats structure 70 assert "size" in data["cache"] 71 assert "hits" in data["cache"] 72 assert "misses" in data["cache"] 73 74 # Check rate limits 75 assert "per_minute" in data["rate_limits"] 76 assert "per_hour" in data["rate_limits"] 77 assert "per_day" in data["rate_limits"] 78