docs+tests: P8 测试与文档(CHANGELOG/CONTRIBUTING + 补充单测)

- CHANGELOG.md / CONTRIBUTING.md
- 新增 exceptions / case_converter 单元测试
- pytest 12 → 22 passed;全项目 flake8 0

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
DjangoAdmin Dev
2026-08-07 19:53:01 +08:00
co-authored by Claude
parent 8937799973
commit d45b61d808
5 changed files with 173 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
"""
业务异常单元测试
=============================================================
验证 BizError 及子类的 msg/code 约定:
业务层 raise BizError → 全局异常处理器转 R.failed。
"""
from src.core.exceptions import BizError, NotFoundError, PermissionDeniedError
class TestBizError:
def test_default_values(self):
"""默认 msg='操作失败',code=1"""
e = BizError()
assert e.msg == "操作失败"
assert e.code == 1
def test_custom_msg_and_code(self):
e = BizError("自定义错误", code=403)
assert e.msg == "自定义错误"
assert e.code == 403
def test_is_exception(self):
assert issubclass(BizError, Exception)
class TestSubclasses:
def test_not_found(self):
e = NotFoundError()
assert e.msg == "资源不存在"
assert e.code == 1
def test_permission_denied(self):
e = PermissionDeniedError()
assert e.msg == "权限不足"
assert e.code == 403