feat: 合约撮合 HTTP 接口自动化测试(unittest 数据驱动)
CI / test (push) Canceled after 37s

This commit is contained in:
WbiubiuW
2026-09-22 14:29:21 +08:00
commit a2378c0ae6
30 changed files with 2413 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
"""内存数据库(MockMySQL):模拟 MySQL 的表读写,供用例做落库校验。
只提供用例所需的最小查询能力(insert/select/count),字段命名沿用
snake_case,贴近真实库表列名;缓存侧(MockRedis)则用 camelCase,
模拟真实系统"库与缓存字段命名不一致、断言前需归一化"的常见情况。
"""
class MockMySQL:
def __init__(self):
self._tables = {}
def insert(self, table, row):
"""插入一行(dict)。"""
self._tables.setdefault(table, []).append(dict(row))
def select(self, table, **where):
"""按等值条件查询,返回匹配的行(list[dict]);无条件返回全表。"""
rows = self._tables.get(table, [])
return [row for row in rows if all(row.get(k) == v for k, v in where.items())]
def count(self, table, **where):
"""按条件统计行数。"""
return len(self.select(table, **where))