test_storage.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from datetime import datetime, timezone
  2. from pathlib import Path
  3. from argus_mcp.models import MarketQuote, RegimeSnapshot
  4. from argus_mcp.storage import SnapshotStore
  5. def test_storage_roundtrip(tmp_path: Path):
  6. store = SnapshotStore(tmp_path / "argus.sqlite3")
  7. snapshot = RegimeSnapshot(
  8. snapshot_id="abc123",
  9. generated_at=datetime.now(timezone.utc),
  10. regime="risk_on",
  11. confidence=0.7,
  12. summary="Test",
  13. signals=[MarketQuote(symbol="QQQ", source="test", change_pct=1.0)],
  14. )
  15. store.save(snapshot)
  16. latest = store.latest()
  17. assert latest is not None
  18. assert latest.snapshot_id == "abc123"
  19. assert store.count() == 1
  20. def test_quote_cache_roundtrip(tmp_path: Path):
  21. store = SnapshotStore(tmp_path / "argus.sqlite3")
  22. quote = MarketQuote(symbol="QQQ", source="finnhub", last=500.0, change_pct=1.2)
  23. store.save_quote(quote, fetched_at=datetime.now(timezone.utc))
  24. cached = store.latest_quote("QQQ", "finnhub")
  25. assert cached is not None
  26. cached_quote, fetched_at = cached
  27. assert cached_quote.symbol == "QQQ"
  28. assert cached_quote.source == "finnhub"
  29. assert fetched_at.tzinfo is not None