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"