Spaces:
Sleeping
Sleeping
File size: 1,203 Bytes
36ee2f7 | 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 38 39 40 41 | from tests.conftest import VALID_PAYLOAD, TEST_API_KEY
# Tester GET /health
def test_health_check(client):
response = client.get("/health")
assert response.status_code == 200
assert response.json()["status"] == "ok"
# Tester POST /predict avec données valides
def test_predict_valid(client):
response = client.post(
"/predict",
json=VALID_PAYLOAD,
headers={"X-API-Key": TEST_API_KEY},
)
assert response.status_code == 200
body = response.json()
assert "label" in body
assert body["label"] in ("Reste", "Quitte")
assert "probabilite" in body
assert 0.0 <= body["probabilite"] <= 1.0
# Tester POST /predict avec données invalides
def test_predict_invalid_data(client):
invalid_payload = {"age": 999, "genre": 99} # hors bornes + champs manquants
response = client.post(
"/predict",
json=invalid_payload,
headers={"X-API-Key": TEST_API_KEY},
)
assert response.status_code == 422 # Pydantic validation error
# Tester POST /predict sans API Key → 401
def test_predict_no_api_key(client):
response = client.post("/predict", json=VALID_PAYLOAD)
assert response.status_code == 401
|