Skip to content

Commit b3196b9

Browse files
committed
Add FastAPI app with Docker, CI/CD, and linter
1 parent e584b5b commit b3196b9

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ mlflow
66
pydantic
77
flake8
88
pytest
9+
httpx

test/test_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import os
22
import sys
33
from unittest.mock import MagicMock, patch
4-
from fastapi.testclient import TestClient
5-
from api.main import app # import AFTER patching
64

75
# Add src to sys.path for imports
86
sys.path.insert(0, os.path.abspath(os.path.join(
97
os.path.dirname(__file__), '..', 'src')))
108

11-
12-
# Mock mlflow.sklearn.load_model before importing your app
9+
# --- Patch before importing app ---
1310
mock_model = MagicMock()
1411
mock_model.predict_proba.return_value = [[0.3, 0.7]]
1512

1613
patcher = patch('mlflow.sklearn.load_model', return_value=mock_model)
1714
patcher.start()
1815

16+
# Now import app
17+
from fastapi.testclient import TestClient
18+
from api.main import app
1919

2020
client = TestClient(app)
2121

22-
22+
# --- Test ---
2323
def test_predict():
2424
sample_data = {
2525
"Recency": 1,
@@ -55,5 +55,5 @@ def test_predict():
5555
assert "risk_probability" in response.json()
5656
assert abs(response.json()["risk_probability"] - 0.7) < 1e-6
5757

58-
58+
# --- Cleanup ---
5959
patcher.stop()

0 commit comments

Comments
 (0)