完成错误测试用例

This commit is contained in:
Your Name
2026-01-31 11:02:59 +08:00
parent 588e3bb478
commit 11cef531bd
15 changed files with 909 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
# 后端 API 测试(TDD
依据《产品文档》与《API 文档》,用 Python + pytest 编写。**先写失败用例(RED),再实现路由(GREEN)。**
后端源码在 `backend/src/` 下,pytest 通过 `pytest.ini``pythonpath = src` 自动加入 `src` 目录,无需手动设置 PYTHONPATH。
## 运行测试
```bash
cd backend
source .venv/bin/activate # 或 pip install -r requirements.txt
pytest tests/ -v
```
## 用例覆盖
| 接口 | 用例 |
|------|------|
| POST /api/auth/login | 成功返回 token/user、错误返回 401、缺 username/password 返回 400 |
| POST /api/projects/list | 无 token 401、有 token 返回 list/total/page/pageSize、无数据时 list 空且 total=0 |
| POST /api/projects/detail | 无 token 401、存在项目返回完整字段、不存在 404 |
| POST /api/projects/create | 无 token 401、非市场部 403、市场部且必填齐全 201、缺合同编号/项目名称 400 |
| POST /api/projects/update | 无 token 401、存在项目 200 保存成功、不存在 404 |
| POST /api/projects/logs | 无 token 401、有 token 返回 list/total/page/pageSize、不存在项目 404 |