Files
crypto_monitor/tests/test_hub_monitor_payload.py
T
dekun 5797d49d8a refactor: 将共用代码迁入 lib/ 模块化目录
统一 strategy、key_monitor、trade、hub 等共用库到 lib/ 子包,并补充 lib-structure 文档,便于四所与中控维护。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-02 16:23:09 +08:00

40 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""hub /api/hub/monitorenrich 局部返回时须保留 keys。"""
from __future__ import annotations
import sys
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from lib.hub.hub_bridge import build_hub_monitor_payload # noqa: E402
class TestHubMonitorPayload(unittest.TestCase):
def test_partial_enrich_keeps_keys(self):
keys = [{"id": 7, "symbol": "BTC/USDT"}]
orders = [{"id": 1}]
trends = [{"id": 9, "symbol": "ETH/USDT"}]
rolls = []
def enrich_only_trends(**_kw):
return {"trends": [{"id": 9, "add_count": 2}]}
out = build_hub_monitor_payload(
keys=keys,
orders=orders,
trends=trends,
rolls=rolls,
enrich=enrich_only_trends,
)
self.assertTrue(out["ok"])
self.assertEqual(out["keys"], keys)
self.assertEqual(out["orders"], orders)
self.assertEqual(out["rolls"], rolls)
self.assertEqual(out["trends"][0]["add_count"], 2)
if __name__ == "__main__":
unittest.main()