WIP-CHECKPOINT[auth-refactor]: 固化工程师崩溃前部分成果 + 同树其他未提交WIP(仅源码,不含密钥/二进制)-- 待重激活工程师续作

This commit is contained in:
Simon
2026-07-07 21:52:11 +08:00
parent 242c1967ff
commit fab75760e0
203 changed files with 21504 additions and 3345 deletions
+27
View File
@@ -108,6 +108,19 @@ _starlette_config.Config._read_file = _read_file_utf8
# =============================================================================
# SQLite 内存数据库引擎
# =============================================================================
# 测试环境变量配置
# =============================================================================
# 注意:这些环境变量在模块导入时生效,确保在 app.config 加载前设置
import os as _os
# 预先设置测试所需的环境变量
_os.environ.setdefault("DEV_MODE", "true") # 启用dev模式,跳过企微API调用
_os.environ.setdefault("WECOM_SSO_CALLBACK_BASE", "https://test.example.com")
_os.environ.setdefault("WECOM_CORP_ID", "test_corp_id")
_os.environ.setdefault("WECOM_CORP_SECRET", "test_corp_secret")
_os.environ.setdefault("WECOM_AGENT_ID", "test_agent_id")
# =============================================================================
# 使用 aiosqlite 驱动的 SQLite 内存数据库替代 PostgreSQL
# StaticPool 确保所有连接使用同一个内存数据库实例
@@ -342,6 +355,20 @@ def mock_wecom_instance():
return mock_wecom_module
@pytest.fixture(autouse=True)
def enable_dev_mode(monkeypatch):
"""强制启用 dev_mode,跳过企微 API 调用。
测试环境无法访问企微 API,需要启用 dev_mode 才能正常测试登录等功能。
"""
# 设置环境变量
monkeypatch.setenv("DEV_MODE", "true")
# 同时设置 settings 属性
from app.config import settings
monkeypatch.setattr(settings, "dev_mode", True)
yield
@pytest.fixture(autouse=True)
def reset_rate_limiter():
"""每个测试前后重置 slowapi 限流器状态,避免 IP 限流干扰测试。