feat(shipping-notice): 新增临时库存管理功能,支持创建会话、获取分析结果及字段映射建议
This commit is contained in:
1 parent
46eb63f5bb
commit
e9bdd81f1a
320 files changed
+28361
-10487
No files matched your search
@@ -19,6 +19,15 @@ from app.services.schedule.job_params import (
|
||||
)
|
||||
|
||||
|
||||
def _enabled_source_code() -> str:
|
||||
"""读取测试数据库的首个启用库存源,避免测试依赖已废弃 YAML 的固定编码。"""
|
||||
from app.services.shipping_notice.inventory_source_repository import list_database_inventory_sources
|
||||
|
||||
sources = list_database_inventory_sources()
|
||||
assert sources, 'expected at least one enabled inventory source'
|
||||
return str(sources[0]['source_code'])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_jwt_headers(app):
|
||||
"""创建 admin 用户并签发 Bearer JWT。"""
|
||||
@@ -80,7 +89,8 @@ def test_platform_task_options_shipping_sources(client, admin_jwt_headers, app):
|
||||
assert options, 'expected at least one enabled inventory source'
|
||||
assert all('label' in item and 'value' in item for item in options)
|
||||
values = {item['value'] for item in options}
|
||||
assert 'DSV360_AWSBI_BYAWSATL01' in values
|
||||
with app.app_context():
|
||||
assert _enabled_source_code() in values
|
||||
|
||||
|
||||
def test_platform_task_options_unknown_source_rejected(client, admin_jwt_headers):
|
||||
@@ -112,10 +122,11 @@ def test_validate_task_params_rejects_unknown_key(app):
|
||||
def test_validate_task_params_rejects_wrong_type(app):
|
||||
"""multi_select 传入非 list 应报类型错误。"""
|
||||
with app.app_context():
|
||||
source_code = _enabled_source_code()
|
||||
with pytest.raises(JobParamsValidationError, match='list of option values'):
|
||||
validate_task_params(
|
||||
'shipping-inventory-rpa',
|
||||
{'source_codes': 'DSV360_AWSBI_BYAWSATL01'},
|
||||
{'source_codes': source_code},
|
||||
check_options=False,
|
||||
)
|
||||
|
||||
@@ -123,6 +134,7 @@ def test_validate_task_params_rejects_wrong_type(app):
|
||||
def test_validate_task_params_checks_option_range(app):
|
||||
"""check_options=True 时,multi_select 值不在选项范围内应报错。"""
|
||||
with app.app_context():
|
||||
source_code = _enabled_source_code()
|
||||
with pytest.raises(JobParamsValidationError, match='not in options'):
|
||||
validate_task_params(
|
||||
'shipping-inventory-rpa',
|
||||
@@ -132,10 +144,10 @@ def test_validate_task_params_checks_option_range(app):
|
||||
# 合法值应通过
|
||||
result = validate_task_params(
|
||||
'shipping-inventory-rpa',
|
||||
{'source_codes': ['DSV360_AWSBI_BYAWSATL01']},
|
||||
{'source_codes': [source_code]},
|
||||
check_options=True,
|
||||
)
|
||||
assert result['source_codes'] == ['DSV360_AWSBI_BYAWSATL01']
|
||||
assert result['source_codes'] == [source_code]
|
||||
|
||||
|
||||
def test_validate_task_params_passes_advanced_through(app):
|
||||
@@ -186,16 +198,18 @@ def owner_id(app):
|
||||
|
||||
def test_post_schedule_persists_valid_job_params(client, admin_jwt_headers, owner_id, app):
|
||||
"""合法 job_params 应持久化并出现在 serialize_task 响应中。"""
|
||||
with app.app_context():
|
||||
source_code = _enabled_source_code()
|
||||
res = _create_platform_schedule(
|
||||
client, admin_jwt_headers, owner_id,
|
||||
job_params={'source_codes': ['DSV360_AWSBI_BYAWSATL01']},
|
||||
job_params={'source_codes': [source_code]},
|
||||
)
|
||||
assert res.status_code == 201
|
||||
body = res.get_json()
|
||||
assert body['job_params'] == {'source_codes': ['DSV360_AWSBI_BYAWSATL01']}
|
||||
assert body['job_params'] == {'source_codes': [source_code]}
|
||||
with app.app_context():
|
||||
task = db.session.get(ScheduleTask, body['id'])
|
||||
assert task.job_params == {'source_codes': ['DSV360_AWSBI_BYAWSATL01']}
|
||||
assert task.job_params == {'source_codes': [source_code]}
|
||||
|
||||
|
||||
def test_post_schedule_without_job_params_applies_schema_defaults(client, admin_jwt_headers, owner_id, app):
|
||||
@@ -254,9 +268,11 @@ def test_post_data_pipeline_rejects_job_params(client, admin_jwt_headers, owner_
|
||||
|
||||
def test_patch_schedule_updates_and_clears_job_params(client, admin_jwt_headers, owner_id, app):
|
||||
"""PATCH 应支持更新;显式 null 对有 schema 的任务重置为默认值。"""
|
||||
with app.app_context():
|
||||
source_code = _enabled_source_code()
|
||||
res = _create_platform_schedule(
|
||||
client, admin_jwt_headers, owner_id,
|
||||
job_params={'source_codes': ['DSV360_AWSBI_BYAWSATL01']},
|
||||
job_params={'source_codes': [source_code]},
|
||||
)
|
||||
task_id = res.get_json()['id']
|
||||
|
||||
@@ -275,9 +291,11 @@ def test_patch_schedule_updates_and_clears_job_params(client, admin_jwt_headers,
|
||||
|
||||
def test_patch_platform_api_path_resets_job_params_to_new_defaults(client, admin_jwt_headers, owner_id, app):
|
||||
"""切换 platform_api_path 且未传 job_params 时,应按新任务 schema 重置,避免旧参数残留。"""
|
||||
with app.app_context():
|
||||
source_code = _enabled_source_code()
|
||||
res = _create_platform_schedule(
|
||||
client, admin_jwt_headers, owner_id,
|
||||
job_params={'source_codes': ['DSV360_AWSBI_BYAWSATL01']},
|
||||
job_params={'source_codes': [source_code]},
|
||||
)
|
||||
task_id = res.get_json()['id']
|
||||
|
||||
@@ -295,9 +313,11 @@ def test_patch_platform_api_path_resets_job_params_to_new_defaults(client, admin
|
||||
|
||||
def test_patch_platform_api_path_to_schemaless_clears_job_params(client, admin_jwt_headers, owner_id, app):
|
||||
"""切换到无 params_schema 的平台任务且未传 job_params 时应清空旧参数。"""
|
||||
with app.app_context():
|
||||
source_code = _enabled_source_code()
|
||||
res = _create_platform_schedule(
|
||||
client, admin_jwt_headers, owner_id,
|
||||
job_params={'source_codes': ['DSV360_AWSBI_BYAWSATL01']},
|
||||
job_params={'source_codes': [source_code]},
|
||||
)
|
||||
task_id = res.get_json()['id']
|
||||
|
||||
@@ -310,11 +330,13 @@ def test_patch_platform_api_path_to_schemaless_clears_job_params(client, admin_j
|
||||
assert body['job_params'] is None
|
||||
|
||||
|
||||
def test_patch_platform_api_path_with_explicit_job_params_keeps_payload(client, admin_jwt_headers, owner_id):
|
||||
def test_patch_platform_api_path_with_explicit_job_params_keeps_payload(client, admin_jwt_headers, owner_id, app):
|
||||
"""切换 platform_api_path 同时显式传 job_params 时,应保留请求体参数(经新 schema 校验)。"""
|
||||
with app.app_context():
|
||||
source_code = _enabled_source_code()
|
||||
res = _create_platform_schedule(
|
||||
client, admin_jwt_headers, owner_id,
|
||||
job_params={'source_codes': ['DSV360_AWSBI_BYAWSATL01']},
|
||||
job_params={'source_codes': [source_code]},
|
||||
)
|
||||
task_id = res.get_json()['id']
|
||||
|
||||
@@ -346,9 +368,10 @@ def test_shipping_rpa_filter_prefers_job_params(app):
|
||||
from app.services.schedule.shipping_inventory_rpa_job import _filter_sources
|
||||
|
||||
with app.app_context():
|
||||
task = ScheduleTask(job_params={'source_codes': ['DSV360_AWSBI_BYAWSATL01']})
|
||||
source_code = _enabled_source_code()
|
||||
task = ScheduleTask(job_params={'source_codes': [source_code]})
|
||||
sources = _filter_sources(task)
|
||||
assert [item.get('source_code') for item in sources] == ['DSV360_AWSBI_BYAWSATL01']
|
||||
assert [item.get('source_code') for item in sources] == [source_code]
|
||||
# job_params 为空(默认值)时不筛选 → 返回全部启用源
|
||||
task_all = ScheduleTask(job_params={'source_codes': []})
|
||||
assert len(_filter_sources(task_all)) >= 1
|
||||
|
||||
Reference in new issue
Block a user