feat(shipping-notice): 完成货代发货通知全门禁恢复MVP收口
完成全门禁恢复MVP版本交付:调整自动上传与重试配置,重构正式执行链路;修复多处代码bug,新增测试与审计工具;更新全流程文档与契约规范。
This commit is contained in:
1 parent
8e0bbf7a81
commit
c94d173f92
181 files changed
+12947
-1724
No files matched your search
@@ -1,12 +1,32 @@
|
||||
from dotenv import dotenv_values
|
||||
|
||||
from app import db, env_persistence
|
||||
from app.models import AppSetting
|
||||
from app import db
|
||||
from app.core.auth.jwt import issue_local_access_token
|
||||
from app.core.config import env_persistence
|
||||
from app.models import AppSetting, User
|
||||
|
||||
|
||||
def _admin_auth_headers(app) -> dict[str, str]:
|
||||
"""使用当前 JWT 鉴权合同构造企微管理端请求身份。"""
|
||||
with app.app_context():
|
||||
admin = db.session.query(User).filter_by(username='wecom-settings-admin').first()
|
||||
if admin is None:
|
||||
admin = User(
|
||||
username='wecom-settings-admin',
|
||||
email='wecom-settings-admin@example.com',
|
||||
role='admin',
|
||||
status='active',
|
||||
)
|
||||
admin.set_password('test-password')
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
token = issue_local_access_token(admin)
|
||||
return {'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'}
|
||||
|
||||
|
||||
def test_wecom_system_settings_persist_to_env_and_reload(client, app, admin_headers, monkeypatch, tmp_path):
|
||||
env_file = tmp_path / '.env'
|
||||
monkeypatch.setattr(env_persistence, 'BACKEND_ENV_PATH', env_file)
|
||||
monkeypatch.setattr(env_persistence, 'ROOT_ENV_LOCAL_PATH', env_file)
|
||||
|
||||
payload = {
|
||||
'enabled': True,
|
||||
@@ -27,7 +47,7 @@ def test_wecom_system_settings_persist_to_env_and_reload(client, app, admin_head
|
||||
'public_base_url': 'https://example.com',
|
||||
}
|
||||
|
||||
res = client.put('/api/admin/wecom/system-settings', json=payload, headers=admin_headers)
|
||||
res = client.put('/api/admin/wecom/system-settings', json=payload, headers=_admin_auth_headers(app))
|
||||
assert res.status_code == 200
|
||||
|
||||
saved = dotenv_values(env_file)
|
||||
@@ -49,7 +69,7 @@ def test_wecom_system_settings_persist_to_env_and_reload(client, app, admin_head
|
||||
app.config['WECOM_MATCH_OPERATOR'] = 'AND'
|
||||
app.config['WECOM_PUBLIC_BASE_URL'] = ''
|
||||
|
||||
res = client.get('/api/admin/wecom/system-settings', headers=admin_headers)
|
||||
res = client.get('/api/admin/wecom/system-settings', headers=_admin_auth_headers(app))
|
||||
assert res.status_code == 200
|
||||
data = res.get_json()
|
||||
assert data['enabled'] is True
|
||||
@@ -60,7 +80,7 @@ def test_wecom_system_settings_persist_to_env_and_reload(client, app, admin_head
|
||||
|
||||
def test_wecom_notify_settings_persist_to_env_and_reload(client, app, admin_headers, monkeypatch, tmp_path):
|
||||
env_file = tmp_path / '.env'
|
||||
monkeypatch.setattr(env_persistence, 'BACKEND_ENV_PATH', env_file)
|
||||
monkeypatch.setattr(env_persistence, 'ROOT_ENV_LOCAL_PATH', env_file)
|
||||
|
||||
payload = {
|
||||
'enabled': False,
|
||||
@@ -68,7 +88,7 @@ def test_wecom_notify_settings_persist_to_env_and_reload(client, app, admin_head
|
||||
'events': ['task_completed', 'permission_batch_updated'],
|
||||
}
|
||||
|
||||
res = client.put('/api/admin/wecom/notify-settings', json=payload, headers=admin_headers)
|
||||
res = client.put('/api/admin/wecom/notify-settings', json=payload, headers=_admin_auth_headers(app))
|
||||
assert res.status_code == 200
|
||||
|
||||
saved = dotenv_values(env_file)
|
||||
@@ -87,7 +107,7 @@ def test_wecom_notify_settings_persist_to_env_and_reload(client, app, admin_head
|
||||
app.config['WECOM_NOTIFY_BASE_URL'] = ''
|
||||
app.config['WECOM_NOTIFY_EVENTS'] = ''
|
||||
|
||||
res = client.get('/api/admin/wecom/notify-settings', headers=admin_headers)
|
||||
res = client.get('/api/admin/wecom/notify-settings', headers=_admin_auth_headers(app))
|
||||
assert res.status_code == 200
|
||||
data = res.get_json()
|
||||
assert data['enabled'] is False
|
||||
@@ -99,12 +119,12 @@ def test_wecom_system_settings_survive_when_env_file_is_wiped(client, app, admin
|
||||
"""Simulate a container rebuild that wipes backend/.env. The DB row must
|
||||
still drive the runtime configuration."""
|
||||
env_file = tmp_path / '.env'
|
||||
monkeypatch.setattr(env_persistence, 'BACKEND_ENV_PATH', env_file)
|
||||
monkeypatch.setattr(env_persistence, 'ROOT_ENV_LOCAL_PATH', env_file)
|
||||
|
||||
res = client.put(
|
||||
'/api/admin/wecom/system-settings',
|
||||
json={'corp_id': 'ww-from-db-only', 'enabled': True},
|
||||
headers=admin_headers,
|
||||
headers=_admin_auth_headers(app),
|
||||
)
|
||||
assert res.status_code == 200
|
||||
|
||||
@@ -118,7 +138,7 @@ def test_wecom_system_settings_survive_when_env_file_is_wiped(client, app, admin
|
||||
app.config['WECOM_CORP_ID'] = ''
|
||||
app.config['WECOM_ENABLED'] = False
|
||||
|
||||
res = client.get('/api/admin/wecom/system-settings', headers=admin_headers)
|
||||
res = client.get('/api/admin/wecom/system-settings', headers=_admin_auth_headers(app))
|
||||
assert res.status_code == 200
|
||||
data = res.get_json()
|
||||
assert data['corp_id'] == 'ww-from-db-only'
|
||||
|
||||
Reference in new issue
Block a user