refactor(backend): 重构后端

This commit is contained in:
sophie committed 2026-07-01 21:18:35 +08:00
1 parent c8054476c1
commit bba6e6f221
32 files changed
+252 -296

No files matched your search

+23 -1
View File
@@ -1,6 +1,28 @@
import pytest
def parse_api_error(body: dict) -> dict:
"""
从标准 API 错误 envelope 中提取 error 子对象,供测试断言 error.code / details。
"""
assert isinstance(body, dict)
assert body.get('success') is False
error = body.get('error')
assert isinstance(error, dict)
return error
def flatten_api_error(body: dict) -> dict:
"""
将 envelope 错误扁平化为 { error_code, error, ...details },便于 WeCom 等历史测试断言。
"""
error = parse_api_error(body)
flat = dict(error.get('details') or {})
flat['error_code'] = error.get('code')
flat['error'] = error.get('message')
return flat
@pytest.fixture(autouse=True)
def _isolate_persisted_settings(monkeypatch, tmp_path):
"""Prevent tests from inheriting the developer's local ``backend/.env``.
@@ -12,7 +34,7 @@ def _isolate_persisted_settings(monkeypatch, tmp_path):
calls inside test fixtures. Routing reads to a tmp path makes every test
start from a clean slate.
"""
from app import env_persistence
from app.core.config import env_persistence
monkeypatch.setattr(env_persistence, 'LEGACY_BACKEND_ENV_PATH', tmp_path / 'isolated.env')