|
1 | | -"""Tests for main application""" |
2 | | -from fastapi.testclient import TestClient |
| 1 | +"""Tests for main application and health endpoints.""" |
3 | 2 |
|
4 | | -from app.main import app |
5 | 3 |
|
6 | | -client = TestClient(app) |
7 | | - |
8 | | - |
9 | | -def test_root(): |
10 | | - """Test root endpoint""" |
| 4 | +def test_root(client): |
| 5 | + """Root endpoint returns API info.""" |
11 | 6 | response = client.get("/") |
12 | 7 | assert response.status_code == 200 |
13 | | - assert response.json()["message"] == "Senate API" |
| 8 | + data = response.json() |
| 9 | + assert data["message"] == "Senate API" |
| 10 | + assert "version" in data |
14 | 11 |
|
15 | 12 |
|
16 | | -def test_health_check(): |
17 | | - """Test health check endpoint""" |
| 13 | +def test_health_check(client): |
| 14 | + """Health check returns healthy status.""" |
18 | 15 | response = client.get("/health") |
19 | 16 | assert response.status_code == 200 |
20 | 17 | assert response.json()["status"] == "healthy" |
| 18 | + |
| 19 | + |
| 20 | +def test_cors_headers(client): |
| 21 | + """CORS middleware allows frontend origin.""" |
| 22 | + response = client.options( |
| 23 | + "/", |
| 24 | + headers={ |
| 25 | + "Origin": "http://localhost:3000", |
| 26 | + "Access-Control-Request-Method": "GET", |
| 27 | + }, |
| 28 | + ) |
| 29 | + assert response.headers.get("access-control-allow-origin") == "http://localhost:3000" |
| 30 | + |
| 31 | + |
| 32 | +def test_unknown_route_returns_404(client): |
| 33 | + """Non-existent routes return 404.""" |
| 34 | + response = client.get("/api/nonexistent") |
| 35 | + assert response.status_code == 404 |
0 commit comments