mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 04:46:26 +00:00
本次提交进行了大规模的系统重构: 1. 拆分租户相关模块到platform平台层,重构租户表名与关联关系 2. 迁移日志、工单、插件等模块到对应层级,统一代码结构 3. 重构批量操作接口路径,从/available/setting改为/status/batch 4. 新增批量删除基础模型,统一处理批量操作逻辑 5. 优化导入导出接口,修正路由方法与描述信息 6. 修复循环引用问题,重构依赖注入与类型导入 7. 更新初始化脚本与路由注册,新增平台管理路由 8. 重构岗位模型,新增岗位编码字段与校验 9. 完善部门删除逻辑,新增子部门删除限制 10. 更新初始化数据与配置文件,适配新架构
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""
|
|
后端接口测试入口。
|
|
|
|
注意:测试函数使用同步 `def`,由 TestClient 驱动;勿对用例本身使用 `async def`。
|
|
执行示例: `pytest tests/test_main.py` 或 `pytest tests/`
|
|
"""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
def test_check_readiness(test_client: TestClient) -> None:
|
|
"""
|
|
校验 ``/common/health/ready/``:数据库与 Redis(若启用)均可达时返回 200。
|
|
"""
|
|
response = test_client.get("/common/health/ready/")
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
assert body["success"] is True
|
|
assert body["data"] is not None
|
|
# 检查实际返回的结构
|
|
assert "dependencies" in body["data"]
|
|
assert body["data"]["dependencies"].get("database") is not None
|
|
|
|
|
|
def test_check_health(test_client: TestClient) -> None:
|
|
"""
|
|
校验 `/common/health/` 返回统一成功响应结构。
|
|
|
|
参数:
|
|
- test_client (TestClient): pytest 注入的客户端。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
response = test_client.get("/common/health/")
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
assert body["success"] is True
|
|
assert body["code"] == 0
|
|
assert body["msg"] == "系统健康"
|
|
# 检查实际返回的 data 结构
|
|
assert body["data"] is not None
|
|
assert body["data"].get("status") == "healthy"
|
|
assert body["status_code"] == 200
|
|
|
|
|
|
# 运行所有测试
|
|
if __name__ == "__main__":
|
|
pytest.main(["-v", "tests/test_main.py"])
|