chore: P1 工程化工具链

- pyproject.toml:pytest/black/isort/mypy 统一配置
- requirements-dev.txt:测试与代码规范开发依赖
- .flake8 / .editorconfig:PEP8 与编辑器统一
- .pre-commit-config.yaml:提交前钩子
- Makefile:常用命令集
- .env.example:环境变量模板(76 键)
- tests/:pytest 骨架 + R 响应格式冒烟测试

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
DjangoAdmin Dev
2026-08-07 12:14:51 +08:00
co-authored by Claude
parent 15f2a5e097
commit 8691412ec6
12 changed files with 448 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
"""单元测试包。"""
+1
View File
@@ -0,0 +1 @@
"""core 层单元测试。"""
+53
View File
@@ -0,0 +1,53 @@
"""
R 统一响应格式单元测试
验证 `R.ok()` / `R.failed()` 返回的 JSON 响应结构符合前后端约定:
{code, data, msg, ok}(code=0 成功,非 0 失败)。
"""
from utils import R
class TestOk:
"""成功响应"""
def test_ok_default_format(self):
resp = R.ok()
body = resp.get_json()
assert body["code"] == 0
assert body["ok"] is True
assert body["data"] is None
assert body["msg"]
def test_ok_with_data(self):
resp = R.ok(data={"id": 1, "name": "张三"})
body = resp.get_json()
assert body["code"] == 0
assert body["data"] == {"id": 1, "name": "张三"}
def test_ok_with_kwargs(self):
resp = R.ok(data=[], total=100)
body = resp.get_json()
assert body["total"] == 100
class TestFailed:
"""失败响应"""
def test_failed_default_format(self):
resp = R.failed()
body = resp.get_json()
assert body["code"] != 0
assert body["ok"] is False
assert body["data"] is None
def test_failed_custom_code(self):
resp = R.failed(msg="未授权访问", code=401)
body = resp.get_json()
assert body["code"] == 401
assert body["msg"] == "未授权访问"