test_trends_mcp.py 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. from pathlib import Path
  2. from trends_mcp.aliases import normalize_entity
  3. from trends_mcp import ledger
  4. def test_normalize_entity_maps_bitcoin_to_btc():
  5. assert normalize_entity("bitcoin") == "BTC"
  6. def test_store_snapshot_persists_payload(tmp_path, monkeypatch):
  7. monkeypatch.setattr(ledger, "DB_PATH", tmp_path / "trends_history.db")
  8. ledger.store_snapshot(
  9. tool="resolve_entity",
  10. keyword="bitcoin",
  11. normalized_keyword="BTC",
  12. mid="/m/05p0rrx",
  13. canonical_label="Bitcoin",
  14. payload={"keyword": "bitcoin", "canonical_label": "Bitcoin"},
  15. )
  16. rows = ledger.read_recent(10)
  17. assert rows[0]["tool"] == "resolve_entity"
  18. assert rows[0]["payload"]["canonical_label"] == "Bitcoin"
  19. def test_entity_history_matches_keyword(tmp_path, monkeypatch):
  20. monkeypatch.setattr(ledger, "DB_PATH", tmp_path / "trends_history.db")
  21. ledger.store_snapshot(tool="resolve_entity", keyword="bitcoin", normalized_keyword="BTC", mid="/m/05p0rrx", canonical_label="Bitcoin", payload={"keyword": "bitcoin"})
  22. ledger.store_snapshot(tool="get_related_queries", keyword="bitcoin", normalized_keyword="BTC", mid=None, canonical_label=None, payload={"keyword": "bitcoin"})
  23. history = ledger.entity_history("BTC")
  24. assert history["count"] == 2