feat: add dual-source quote health orchestration

This commit is contained in:
Windows
2026-09-11 19:47:14 +08:00
parent 5c60036dd6
commit 2376585898
4 changed files with 295 additions and 0 deletions
@@ -0,0 +1,25 @@
from datetime import datetime
from decimal import Decimal
from app.service.market_quote_sync_service import MarketQuoteSyncService
def test_snapshot_parses_real_time_quote_fields() -> None:
snapshot = MarketQuoteSyncService._snapshot(7, "eastmoney_exchange", {
"last_price": "1.234", "previous_close": "1.2", "change_pct": "2.83",
"volume": "1000", "turnover_amount": "123456.78",
}, datetime(2026, 9, 10))
assert snapshot is not None
assert snapshot.last_price == Decimal("1.234")
assert snapshot.turnover_amount == Decimal("123456.78")
assert snapshot.source == "eastmoney_exchange"
def test_snapshot_rejects_missing_or_non_positive_price() -> None:
assert MarketQuoteSyncService._snapshot(
7, "eastmoney_exchange", {"last_price": None}, datetime.now()
) is None
assert MarketQuoteSyncService._snapshot(
7, "eastmoney_exchange", {"last_price": "0"}, datetime.now()
) is None