Files
ocean/backend/tests/README.md
T
2026-01-31 11:02:59 +08:00

25 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 后端 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 |