- 新增后端完整业务支持:数据库模型、API接口、核心服务与RPA对接逻辑 - 新增前端工作台页面、路由适配与多语言国际化 - 新增Dify自定义工具OpenAPI规范、Agent配置脚本与部署文档 - 新增发货Excel模板生成脚本与默认模板 - 修复测试配置文件中的环境变量命名错误 - 更新本地开发环境变量配置
53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _isolate_persisted_settings(monkeypatch, tmp_path):
|
|
"""Prevent tests from inheriting the developer's local ``backend/.env``.
|
|
|
|
``apply_env_settings`` is called eagerly in ``create_app`` and on every
|
|
request via the ``before_request`` hook. If the dev's real ``backend/.env``
|
|
contains ``WECOM_AUTO_CREATE_USER=true`` (or any other WECOM_* override),
|
|
those values would silently overwrite the explicit ``app.config.update(...)``
|
|
calls inside test fixtures. Routing reads to a tmp path makes every test
|
|
start from a clean slate.
|
|
"""
|
|
from app import env_persistence
|
|
|
|
monkeypatch.setattr(env_persistence, 'LEGACY_BACKEND_ENV_PATH', tmp_path / 'isolated.env')
|
|
|
|
|
|
@pytest.fixture
|
|
def app():
|
|
from app import create_app, db
|
|
|
|
app = create_app('testing')
|
|
with app.app_context():
|
|
db.create_all()
|
|
yield app
|
|
db.session.remove()
|
|
db.drop_all()
|
|
|
|
|
|
@pytest.fixture
|
|
def client(app):
|
|
return app.test_client()
|
|
|
|
|
|
@pytest.fixture
|
|
def admin_headers():
|
|
return {
|
|
'X-Username': 'admin',
|
|
'X-Role': 'admin',
|
|
'Content-Type': 'application/json'
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def user_headers():
|
|
return {
|
|
'X-Username': 'user',
|
|
'X-Role': 'user',
|
|
'Content-Type': 'application/json'
|
|
}
|