File size: 928 Bytes
9e03a51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from pathlib import Path

from fastapi.testclient import TestClient

from src.api import create_app
from src.modeling import train_model
from tests.test_pipeline import sample_training_frame


def test_predict_endpoint_returns_price(tmp_path: Path) -> None:
    artifact_path = tmp_path / "house_price_model.joblib"
    train_model(sample_training_frame(), artifact_path=artifact_path)
    client = TestClient(create_app(model_path=artifact_path))

    response = client.post(
        "/predict",
        json={
            "OverallQual": 7,
            "GrLivArea": 1850,
            "GarageCars": 2,
            "TotalBsmtSF": 1050,
            "FullBath": 2,
            "YearBuilt": 1995,
            "Neighborhood": "Somerst",
            "HouseStyle": "2Story",
        },
    )

    assert response.status_code == 200
    body = response.json()
    assert body["predicted_price"] > 0
    assert body["currency"] == "USD"