Files
syops/backend/tests/conftest.py
T
hugo 4cd987eef6 feat(queue): 添加旧知识库任务入队兼容入口
- 增加 enqueue_kb_job 和 enqueue_clean_job 函数以支持旧 KB 清洗任务入队
- 在 enqueue 函数中处理 KB_CLEAN 和 KB_DIFY_SYNC 类型的任务
- 引入 ValidationError 以处理 job_id 缺失的情况

feat(shipping_notice): 更新库存 RPA 工作流逻辑
- 修改 ensure_inventory_via_rpa 函数以支持手动重试逻辑
- 优化库存导出触发和状态更新的消息提示

fix(i18n): 更新任务未找到的提示信息
- 修改中文和英文提示,明确用户操作要求

feat(shipping_notice): 增强任务解析逻辑
- 添加缺失 Reservation ID 的检查,阻止任务进入确认阶段
- 更新 get_task_status 函数以处理多票会话的任务解析
2026-06-30 21:00:25 +08:00

83 lines
2.6 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(autouse=True)
def _shipping_notice_stable_auto_config(app, request):
"""发货通知单测默认关闭 auto 链,避免 dev .env 开启 AUTO_PROGRESS 导致用例漂移。"""
tmp_path = request.getfixturevalue("tmp_path")
app.config["FREIGHT_UPLOAD_QUEUE_DIR"] = str(tmp_path / "shipping_notice" / "freight_rpa" / "upload_queue")
app.config["FREIGHT_RPA_UPLOAD_TRIGGER_DIR"] = str(
tmp_path / "shipping_notice" / "freight_rpa" / "upload_triggers"
)
if request.node.get_closest_marker("auto_rpa"):
app.config["SHIPPING_NOTICE_AUTO_RPA_INVENTORY_ENABLED"] = True
app.config["SHIPPING_NOTICE_AUTO_PROGRESS_ENABLED"] = True
app.config["SHIPPING_NOTICE_BATCH_ORCHESTRATOR_ENABLED"] = False
return
app.config["SHIPPING_NOTICE_AUTO_RPA_INVENTORY_ENABLED"] = False
app.config["SHIPPING_NOTICE_AUTO_PROGRESS_ENABLED"] = False
app.config["SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED"] = True
app.config["SHIPPING_NOTICE_BATCH_ORCHESTRATOR_ENABLED"] = False
def pytest_configure(config):
config.addinivalue_line(
"markers",
"auto_rpa: 发货通知测试启用 auto_progress + RPA 自动链",
)
config.addinivalue_line(
"markers",
"rpa_e2e: 真实货代 RPA 浏览器导出测试,默认跳过,需 FREIGHT_RPA_E2E=true",
)
@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'
}