Spaces:
Sleeping
Sleeping
File size: 1,184 Bytes
a3d10df | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | from fastapi.testclient import TestClient
from api import app
import math
client = TestClient(app)
def test_health():
response = client.get("/api/health")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
def test_predict_upcoming():
response = client.get("/api/predict")
assert response.status_code == 200
data = response.json()
assert "predictions" in data
assert "skipped" in data
# We expect 12 valid scheduled matches right now based on the DB state
predictions = data["predictions"]
assert len(predictions) == 12, f"Expected 12 predictions, got {len(predictions)}"
# Check skipped count
assert data["predictions_count"] == 12
assert data["skipped_count"] >= 0
for p in predictions:
# Sum of probabilities should be ~1
total_prob = p["prob_home_win"] + p["prob_draw"] + p["prob_away_win"]
assert math.isclose(total_prob, 1.0, rel_tol=1e-5), f"Match {p['match_id']} prob sum is {total_prob}"
if __name__ == "__main__":
test_health()
test_predict_upcoming()
print("Smoke test passed: API returns 12 valid predictions summing to 1.")
|