-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_api.py
More file actions
36 lines (28 loc) · 952 Bytes
/
Copy pathtest_api.py
File metadata and controls
36 lines (28 loc) · 952 Bytes
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
import pytest
from fastapi.testclient import TestClient
from src.api import app
from src.predict import load_model
client = TestClient(app)
def test_health():
r = client.get("/health")
assert r.status_code == 200 and r.json() == {"status": "ok"}
def test_predict_endpoint():
try:
load_model()
except FileNotFoundError:
pytest.skip("Model not trained")
r = client.post(
"/predict",
json={
"applicant_income": 5400, "coapplicant_income": 1200,
"loan_amount": 128000, "loan_term_months": 360,
"credit_history": 1, "dependents": 0,
"employment_status": "salaried", "property_area": "urban",
},
)
assert r.status_code == 200
body = r.json()
assert body["decision"] in {"Approved", "Rejected"}
def test_predict_validation_error():
r = client.post("/predict", json={"applicant_income": -5})
assert r.status_code == 422