File size: 1,369 Bytes
eafdbbf | 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # tests/test_schemas.py
import pytest
from pydantic import ValidationError
from app.api.schemas import PredictionRequest, PredictionResponse
def test_prediction_request_valid():
payload = {
"credit_limit": 50000.0,
"age": 35,
"pay_delay_sep": 0,
"pay_delay_aug": -1,
"bill_amt_sep": 12000.0,
"bill_amt_aug": 11000.0,
"pay_amt_sep": 3000.0,
"pay_amt_aug": 2500.0
}
req = PredictionRequest(**payload)
assert req.credit_limit == 50000.0
assert req.age == 35
def test_prediction_request_missing_field():
payload = {
"credit_limit": 50000.0,
"age": 35
}
with pytest.raises(ValidationError):
PredictionRequest(**payload)
def test_prediction_request_invalid_type():
payload = {
"credit_limit": "not-a-number",
"age": "thirty",
"pay_delay_sep": 0,
"pay_delay_aug": 0,
"bill_amt_sep": 1000.0,
"bill_amt_aug": 1000.0,
"pay_amt_sep": 100.0,
"pay_amt_aug": 100.0
}
with pytest.raises(ValidationError):
PredictionRequest(**payload)
def test_prediction_response_valid():
payload = {
"prediction": 1,
"probability": 0.82
}
resp = PredictionResponse(**payload)
assert resp.prediction in (0, 1)
assert 0.0 <= resp.probability <= 1.0
|