[verified] add SET price snapshot adapter

This commit is contained in:
Kunthawat Greethong committed 2026-08-23 12:38:17 +07:00
1 parent 9301c02306
commit 7f7a6145cd
12 files changed
+705 -9

No files matched your search

+31 -1
View File
@@ -4,6 +4,7 @@ import unittest
from pathlib import Path
from app import create_app
from app.prices import PriceSnapshotStore
from app.vintages import VintageStore
@@ -99,13 +100,42 @@ class ApiTests(unittest.TestCase):
with tempfile.TemporaryDirectory() as temp_dir:
store = VintageStore(Path(temp_dir))
store.persist(b"fixture raw", self.snapshot)
app = create_app({"TESTING": True, "SNAPSHOT": self.snapshot, "VINTAGE_STORE": store})
app = create_app({"TESTING": True, "SNAPSHOT": self.snapshot, "VINTAGE_STORE": store, "PRICE_STORE": PriceSnapshotStore(Path(temp_dir) / "prices")})
response = app.test_client().get("/api/v1/backtest/tourism?min_events=12")
body = response.get_json()
self.assertEqual(response.status_code, 409)
self.assertEqual(body["status"], "blocked")
self.assertEqual(body["reason"], "insufficient_vintages")
self.assertEqual(body["available_events"], 1)
self.assertEqual(body["price_snapshot"]["status"], "missing")
def test_backtest_readiness_blocks_revised_or_missing_prices(self):
class FakeVintageStore:
def list_vintages(self, _as_of=None):
return [{"vintage_id": f"vintage-{index}"} for index in range(12)]
with tempfile.TemporaryDirectory() as temp_dir:
app = create_app(
{
"TESTING": True,
"VINTAGE_STORE": FakeVintageStore(),
"PRICE_STORE": PriceSnapshotStore(Path(temp_dir)),
}
)
response = app.test_client().get("/api/v1/backtest/tourism?min_events=12")
body = response.get_json()
self.assertEqual(response.status_code, 409)
self.assertEqual(body["status"], "blocked")
self.assertEqual(body["reason"], "price_series_not_point_in_time")
def test_prices_health_reports_missing_snapshot(self):
with tempfile.TemporaryDirectory() as temp_dir:
app = create_app({"TESTING": True, "PRICE_STORE": PriceSnapshotStore(Path(temp_dir))})
response = app.test_client().get("/api/v1/prices/health")
body = response.get_json()
self.assertEqual(response.status_code, 200)
self.assertFalse(body["available"])
self.assertEqual(body["status"], "missing")
def test_backtest_readiness_rejects_invalid_min_events(self):
response = self.client.get("/api/v1/backtest/tourism?min_events=bad")