test: 添加测试框架和全面的单元测试

- 添加 pytest 配置和测试依赖到 requirements.txt
- 创建测试包结构和 fixtures (conftest.py)
- 添加数据库模块的 CRUD 操作测试 (test_database.py)
- 添加 Provider 插件系统测试 (test_providers.py)
- 添加调度器模块测试 (test_scheduler.py)
- 添加 API 路由测试 (test_api.py)
- 添加回归测试覆盖边界条件和错误处理 (test_regressions.py)
- 添加健康检查端点用于容器监控
- 修复调度器中的日历计算逻辑和任务执行参数处理
- 更新数据库函数以返回操作结果状态
This commit is contained in:
congsh
2026-03-31 22:36:18 +08:00
parent 61ce809634
commit 37d282c0a2
17 changed files with 1769 additions and 50 deletions

View File

@@ -306,6 +306,13 @@ async def update_quota_rule(rule_id: str, **fields) -> bool:
return True
async def delete_quota_rule(rule_id: str) -> bool:
db = await get_db()
cur = await db.execute("DELETE FROM quota_rules WHERE id=?", (rule_id,))
await db.commit()
return cur.rowcount > 0
async def increment_quota_used(plan_id: str, token_count: int = 0):
"""请求完成后增加该 Plan 所有 Rule 的 quota_used"""
db = await get_db()
@@ -441,6 +448,18 @@ async def update_task(task_id: str, **fields) -> bool:
return True
async def get_task(task_id: str) -> dict | None:
db = await get_db()
cur = await db.execute("SELECT * FROM tasks WHERE id=?", (task_id,))
row = await cur.fetchone()
if not row:
return None
t = row_to_dict(row)
t["request_payload"] = _parse_json(t["request_payload"], {})
t["response_payload"] = _parse_json(t.get("response_payload"))
return t
# ── 种子数据导入 ──────────────────────────────────────
async def seed_from_config():