Spaces:
Running
Running
File size: 1,720 Bytes
d73c099 c125dfd d73c099 c125dfd d73c099 c125dfd d73c099 c125dfd d73c099 c125dfd d73c099 | 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 | import unittest
from unittest.mock import patch
from fastapi.testclient import TestClient
from app import app
from bucklake_ai.errors import InvalidScalerArtifact, ScalerArtifactNotFound
class AppErrorHandlerTests(unittest.TestCase):
def _payload(self):
return {
"symbol": "AAPL",
"published_at": "2026-04-15T12:30:00Z",
"market_bars": {
name: [
{
"open": 100.0 + i,
"close": 101.0 + i,
"high": 102.0 + i,
"low": 99.0 + i,
"volume": 1000.0 + i,
"amount": 0.0,
}
for i in range(30)
]
for name in ("stock", "inx", "dj", "ixic", "ndx")
},
}
def test_scaler_artifact_not_found_returns_503(self):
with patch(
"app.service.predict",
side_effect=ScalerArtifactNotFound("missing scaler"),
):
response = TestClient(app).post("/api/predict/v2", json=self._payload())
self.assertEqual(response.status_code, 503)
self.assertEqual(response.json()["error"], "scaler_artifact_not_found")
def test_invalid_scaler_artifact_returns_503(self):
with patch(
"app.service.predict",
side_effect=InvalidScalerArtifact("bad scaler"),
):
response = TestClient(app).post("/api/predict/v2", json=self._payload())
self.assertEqual(response.status_code, 503)
self.assertEqual(response.json()["error"], "invalid_scaler_artifact")
if __name__ == "__main__":
unittest.main()
|