Spaces:
Sleeping
Sleeping
| 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.") | |