File size: 1,028 Bytes
1e5b98a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# tests/test_api.py
from fastapi.testclient import TestClient

from api.main import app

client = TestClient(app)


def test_health():
    resp = client.get("/health")
    assert resp.status_code == 200
    assert resp.json()["status"] == "ok"


def test_predict_ok():
    payload = {
        "age": 35,
        "gender": "M",
        "marital_status": "single",
        "dependents": 1,
        "monthly_income": 3500.0,
        "employment_type": "permanent",
        "employment_months": 48,
        "requested_amount": 25000.0,
        "loan_term_months": 36,
        "interest_rate": 18.0,
        "installment": 950.0,
        "debt_to_income": 0.45,
        "num_open_loans": 2,
        "num_credit_cards": 2,
        "has_mortgage": 0,
        "channel": "web",
        "region": "capital",
    }
    resp = client.post("/predict/", json=payload)
    assert resp.status_code == 200
    body = resp.json()
    assert "default_probability" in body
    assert "default_class" in body