重构: 迁移后端代码到 app 目录,前端移动到 WebUI,添加完整测试套件
主要变更: - 后端代码从根目录迁移到 app/ 目录 - 前端代码从 frontend/ 重命名为 WebUI/ - 更新所有导入路径以适配新结构 - 提取公共 API 响应函数到 app/api/common.py - 精简验证器服务代码 - 更新启动脚本和文档 测试: - 新增完整测试套件 (tests/) - 单元测试: 模型、仓库层 - 集成测试: 覆盖所有 22+ API 端点 - E2E 测试: 4个完整工作流场景 - 添加 pytest 配置和测试运行脚本
This commit is contained in:
41
app/api/common.py
Normal file
41
app/api/common.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""API 通用工具函数"""
|
||||
from typing import Any, Optional
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
|
||||
def success_response(message: str, data: Any = None) -> dict:
|
||||
"""成功响应"""
|
||||
return {"code": 200, "message": message, "data": data}
|
||||
|
||||
|
||||
def error_response(message: str, code: int = 500) -> JSONResponse:
|
||||
"""错误响应"""
|
||||
return JSONResponse(
|
||||
status_code=code,
|
||||
content={"code": code, "message": message, "data": None},
|
||||
)
|
||||
|
||||
|
||||
def format_proxy(proxy) -> dict:
|
||||
"""格式化代理对象"""
|
||||
return {
|
||||
"ip": proxy.ip,
|
||||
"port": proxy.port,
|
||||
"protocol": proxy.protocol,
|
||||
"score": proxy.score,
|
||||
"last_check": proxy.last_check.isoformat() if proxy.last_check else None,
|
||||
}
|
||||
|
||||
|
||||
def format_plugin(plugin) -> dict:
|
||||
"""格式化插件对象"""
|
||||
return {
|
||||
"id": plugin.id,
|
||||
"name": plugin.display_name,
|
||||
"display_name": plugin.display_name,
|
||||
"description": plugin.description,
|
||||
"enabled": plugin.enabled,
|
||||
"last_run": plugin.last_run.isoformat() if plugin.last_run else None,
|
||||
"success_count": plugin.success_count,
|
||||
"failure_count": plugin.failure_count,
|
||||
}
|
||||
Reference in New Issue
Block a user