feat(shipping-notice): 添加识别定义和规则集管理功能,支持客户和站点的可配置识别规则
This commit is contained in:
1 parent
88408490d7
commit
34d489a2d1
167 files changed
+10365
-7978
No files matched your search
@@ -14,6 +14,7 @@ from app import db
|
||||
from app.core.errors import ConflictError, ValidationError
|
||||
from app.models import (
|
||||
ShippingInventoryConfigurationTestRun,
|
||||
ShippingInventoryValidationBatch,
|
||||
ShippingInventoryExternalMapping,
|
||||
ShippingExcelTemplate,
|
||||
ShippingExcelTemplate,
|
||||
@@ -45,20 +46,20 @@ def _workbook(path: Path) -> None:
|
||||
workbook.save(path)
|
||||
|
||||
|
||||
def _source() -> dict:
|
||||
def _source(code: str = 'TEST_EXPORT_SOURCE', profile_code: str = 'TEST_EXPORT_LOGIN') -> dict:
|
||||
"""创建一个保持停用的 DBS 库存站点。"""
|
||||
login = shipping_inventory_service.save_profile({
|
||||
'profile_code': 'TEST_EXPORT_LOGIN', 'display_name': 'Test Login', 'connector_type': 'dbs',
|
||||
'profile_code': profile_code, 'display_name': 'Test Login', 'connector_type': 'dbs',
|
||||
'login_url': 'https://example.invalid', 'login_config_json': {'auth_mode': 'password'},
|
||||
'username': 'user', 'password': 'password', 'enabled': True,
|
||||
}, actor_id=None)
|
||||
return shipping_inventory_service.save_source({
|
||||
'source_code': 'TEST_EXPORT_SOURCE', 'display_name': 'Test Export Source', 'connector_type': 'dbs',
|
||||
'source_code': code, 'display_name': 'Test Export Source', 'connector_type': 'dbs',
|
||||
'rpa_profile_id': login['id'], 'parsing_profile_id': None, 'excel_template_id': None,
|
||||
'warehouse_resolution_mode': 'fixed', 'fixed_warehouse_id': 'DUB', 'snapshot_ttl_seconds': 3600,
|
||||
'enabled': False,
|
||||
'report_path_json': {'program_group': 'Bison', 'program_label': 'AWSBI', 'report_group': 'Inventory', 'report_name': 'On Hand'},
|
||||
'query_parameters_json': [], 'match_aliases_json': [],
|
||||
'query_parameters_json': [],
|
||||
}, actor_id=None)
|
||||
|
||||
|
||||
@@ -105,6 +106,23 @@ def _complete_test_run(source: dict, tmp_path: Path) -> dict:
|
||||
})
|
||||
|
||||
|
||||
def _published_template(*, code: str) -> ShippingExcelTemplate:
|
||||
"""创建引用库存料号字段的最小已发布发货模板,满足自动启用门禁。"""
|
||||
template = ShippingExcelTemplate(
|
||||
template_code=code, display_name=code, version=1, status='published',
|
||||
storage_bucket='test', storage_key=f'{code}.xlsx', original_filename=f'{code}.xlsx',
|
||||
file_checksum='0' * 64,
|
||||
definition_json={'filename_pattern': '{business_no}.xlsx', 'mappings': [{
|
||||
'sheet': 'Sheet', 'row_mode': 'line', 'start_row': 2, 'target_column': 1,
|
||||
'source_kind': 'inventory_field', 'source_key': _inventory_field_id('part_number'), 'formatter': 'text',
|
||||
}]},
|
||||
definition_checksum='1' * 64,
|
||||
)
|
||||
db.session.add(template)
|
||||
db.session.flush()
|
||||
return template
|
||||
|
||||
|
||||
def test_configuration_test_callback_isolated_from_production_inventory(app, tmp_path):
|
||||
"""测试文件只能生成测试分析,重复发起复用运行,禁止创建生产库存快照。"""
|
||||
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
|
||||
@@ -127,6 +145,296 @@ def test_configuration_test_callback_isolated_from_production_inventory(app, tmp
|
||||
assert ShippingInventoryConfigurationTestRun.query.count() == 1
|
||||
|
||||
|
||||
def test_empty_configuration_export_is_successful_but_marks_data_validation_pending(app, tmp_path):
|
||||
"""已绑定发布方案的空库存结果是有效连接证据,不能被误写为 RPA 失败。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source()
|
||||
field_id = _published_order_field()
|
||||
analysis_path = tmp_path / 'profile-evidence.xlsx'
|
||||
_workbook(analysis_path)
|
||||
seed_run = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
|
||||
seeded = inventory_configuration_test.report_test_export({
|
||||
'run_no': seed_run['run_no'], 'status': 'success', 'file_path': str(analysis_path),
|
||||
})
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], field_id, code='EMPTY_RESULT_PROFILE')
|
||||
shipping_inventory_service.bind_source_parsing_profile(
|
||||
[source['id']], profile['id'], actor_id=None, reason='空结果前已确认同类报表结构', operation='direct',
|
||||
)
|
||||
|
||||
started = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
|
||||
result = inventory_configuration_test.report_test_export({
|
||||
'run_no': started['run_no'], 'status': 'empty', 'message': 'no inventory rows',
|
||||
})
|
||||
|
||||
# 关键断言:空结果保留数据质量待验证,而不是伪造失败或生成生产快照。
|
||||
assert result['status'] == 'completed_empty'
|
||||
assert result['stage'] == 'empty_data_pending_validation'
|
||||
assert result['result']['data_validation'] == 'pending_first_non_empty_export'
|
||||
assert not ShippingInventoryFile.query.count()
|
||||
current = next(item for item in shipping_inventory_service.list_sources() if item['id'] == source['id'])
|
||||
checks = {item['code']: item for item in current['activation']['checks']}
|
||||
# 关键断言:连接测试已通过;数量与匹配字段仅待首次非空文件验证,不能伪装成失败。
|
||||
assert checks['configuration_test']['status'] == 'empty'
|
||||
assert checks['configuration_test']['blocking'] is False
|
||||
assert checks['parsing_validation']['status'] == 'pending'
|
||||
assert checks['parsing_validation']['blocking'] is False
|
||||
assert checks['warehouse_mapping']['blocking'] is False
|
||||
# 关键断言:无库存不会被行级解析或调拨映射阻断;本例仍缺发货模板,因此尚不可启用。
|
||||
assert current['activation']['missing_requirements'] == ['excel_template']
|
||||
|
||||
|
||||
def test_empty_configuration_export_without_published_profile_is_rejected(app):
|
||||
"""没有受控解析定义时,空结果不能被用作站点可用性的替代证据。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source()
|
||||
started = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
|
||||
result = inventory_configuration_test.report_test_export({
|
||||
'run_no': started['run_no'], 'status': 'empty',
|
||||
})
|
||||
|
||||
# 关键断言:没有已发布方案就无法验证空报表的格式,仍必须阻断。
|
||||
assert result['status'] == 'failed'
|
||||
assert '尚未绑定已发布库存解析方案' in result['error_message']
|
||||
|
||||
|
||||
def test_configuration_test_automatically_verifies_compatible_bound_profile(app, tmp_path):
|
||||
"""当前绑定方案的核心栏位仍在时,历史无关列缺失也必须直接成为验证证据。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source()
|
||||
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
|
||||
seed_file = tmp_path / 'bound-profile-seed.xlsx'; _workbook(seed_file)
|
||||
seeded = inventory_configuration_test.report_test_export({'run_no': seed['run_no'], 'status': 'success', 'file_path': str(seed_file)})
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], _published_order_field(), code='BOUND_PROFILE_VERIFY')
|
||||
shipping_inventory_service.bind_source_parsing_profile([source['id']], profile['id'], actor_id=None, operation='direct')
|
||||
|
||||
verified = _complete_test_run(source, tmp_path)
|
||||
# 关键断言:当前绑定方案无需再出现在候选确认列表,测试直接写入启用所需的确认事实。
|
||||
assert verified['stage'] == 'current_profile_verified'
|
||||
assert verified['result']['current_profile_verified'] is True
|
||||
assert verified['result']['confirmed_profile_id'] == profile['id']
|
||||
|
||||
|
||||
def test_verified_current_profile_automatically_enables_ready_source(app, tmp_path):
|
||||
"""当前解析验证通过且必要条件齐全时,站点无需人工确认即可自动启用。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source()
|
||||
seeded = _complete_test_run(source, tmp_path)
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], _published_order_field(), code='AUTO_ENABLE_PROFILE')
|
||||
template = _published_template(code='AUTO_ENABLE_TEMPLATE')
|
||||
current = next(item for item in shipping_inventory_service.list_sources() if item['id'] == source['id'])
|
||||
shipping_inventory_service.save_source({
|
||||
**current, 'parsing_profile_id': profile['id'], 'excel_template_id': template.id,
|
||||
}, actor_id=None, source_id=source['id'])
|
||||
|
||||
verified = _complete_test_run(source, tmp_path)
|
||||
source_model = db.session.get(ShippingInventorySource, source['id'])
|
||||
# 关键断言:测试证据与完整门禁在同一事务提交,避免页面看到已验证但仍需手动启用。
|
||||
assert verified['stage'] == 'current_profile_verified'
|
||||
assert source_model.enabled is True
|
||||
|
||||
|
||||
def test_verified_current_profile_keeps_source_disabled_without_template(app, tmp_path):
|
||||
"""解析测试通过不绕过发货模板门禁,条件不完整的站点必须保持停用。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source()
|
||||
seeded = _complete_test_run(source, tmp_path)
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], _published_order_field(), code='AUTO_ENABLE_BLOCKED')
|
||||
current = next(item for item in shipping_inventory_service.list_sources() if item['id'] == source['id'])
|
||||
shipping_inventory_service.save_source({
|
||||
**current, 'parsing_profile_id': profile['id'], 'excel_template_id': None,
|
||||
}, actor_id=None, source_id=source['id'])
|
||||
|
||||
_complete_test_run(source, tmp_path)
|
||||
source_model = db.session.get(ShippingInventorySource, source['id'])
|
||||
# 关键断言:自动启用始终复用正式门禁,缺少模板不会被测试成功放行。
|
||||
assert source_model.enabled is False
|
||||
assert shipping_inventory_service.get_source_activation_status(source_model)['missing_requirements'] == ['excel_template']
|
||||
|
||||
|
||||
def test_empty_export_automatically_enables_ready_fixed_source(app, tmp_path):
|
||||
"""固定仓查询成功但无库存时,也能在完整门禁下自动启用站点。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source()
|
||||
seeded = _complete_test_run(source, tmp_path)
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], _published_order_field(), code='AUTO_ENABLE_EMPTY')
|
||||
template = _published_template(code='AUTO_ENABLE_EMPTY_TEMPLATE')
|
||||
current = next(item for item in shipping_inventory_service.list_sources() if item['id'] == source['id'])
|
||||
shipping_inventory_service.save_source({
|
||||
**current, 'parsing_profile_id': profile['id'], 'excel_template_id': template.id,
|
||||
}, actor_id=None, source_id=source['id'])
|
||||
|
||||
started = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
|
||||
completed = inventory_configuration_test.report_test_export({'run_no': started['run_no'], 'status': 'empty'})
|
||||
source_model = db.session.get(ShippingInventorySource, source['id'])
|
||||
# 关键断言:无库存是成功查询事实,完整门禁下不再要求人工启用。
|
||||
assert completed['status'] == 'completed_empty'
|
||||
assert source_model.enabled is True
|
||||
|
||||
|
||||
def test_batch_configuration_test_groups_profiles_and_isolates_site_results(app, tmp_path):
|
||||
"""同连接站点一次投递,混合成功、空库存及失败后仍独立汇总为部分失败。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
) as write_trigger:
|
||||
first = _source('BATCH_SOURCE_A', 'BATCH_LOGIN_A')
|
||||
second = _source('BATCH_SOURCE_B', 'BATCH_LOGIN_B')
|
||||
third = _source('BATCH_SOURCE_C', 'BATCH_LOGIN_C')
|
||||
second_model = db.session.get(ShippingInventorySource, second['id'])
|
||||
second_model.rpa_profile_id = first['rpa_profile_id']
|
||||
second_model.config_version += 1
|
||||
db.session.commit()
|
||||
# 用首站既有测试证据创建发布方案,再作为三站批量验证的受控解析定义。
|
||||
seed = inventory_configuration_test.start_test_export(first['id'], actor_id=None)
|
||||
seed_file = tmp_path / 'batch-seed.xlsx'; _workbook(seed_file)
|
||||
seeded = inventory_configuration_test.report_test_export({'run_no': seed['run_no'], 'status': 'success', 'file_path': str(seed_file)})
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], _published_order_field(), code='BATCH_PROFILE')
|
||||
shipping_inventory_service.bind_source_parsing_profile(
|
||||
[first['id'], second['id'], third['id']], profile['id'], actor_id=None, reason='批量验证测试', operation='bulk',
|
||||
)
|
||||
|
||||
write_trigger.reset_mock()
|
||||
batch = inventory_configuration_test.start_batch_test_export([first['id'], second['id'], third['id']], actor_id=None)
|
||||
# 关键断言:两个相同 Profile 的站点合并为一个 trigger,第三站独立触发。
|
||||
assert write_trigger.call_count == 2
|
||||
assert batch['total_count'] == 3
|
||||
runs = {run['inventory_source_id']: run for run in batch['runs']}
|
||||
result_file = tmp_path / 'batch-success.xlsx'; _workbook(result_file)
|
||||
reported = inventory_configuration_test.report_batch_test_exports({
|
||||
'validation_batch_id': batch['id'], 'results': [
|
||||
{'validation_run_no': runs[first['id']]['run_no'], 'status': 'success', 'file_path': str(result_file)},
|
||||
{'validation_run_no': runs[second['id']]['run_no'], 'status': 'skipped', 'skip_reason': 'no_inventory_data'},
|
||||
{'validation_run_no': runs[third['id']]['run_no'], 'status': 'failed', 'error_message': 'login failed'},
|
||||
],
|
||||
})
|
||||
# 关键断言:失败站点不影响其他站点,批次仅汇总为部分失败。
|
||||
assert reported['status'] == 'partial_failed'
|
||||
assert (reported['success_count'], reported['empty_count'], reported['failed_count']) == (1, 1, 1)
|
||||
assert ShippingInventoryValidationBatch.query.get(batch['id']).status == 'partial_failed'
|
||||
|
||||
|
||||
def test_retry_batch_only_retriggers_failed_sites(app, tmp_path):
|
||||
"""批次重试只新建失败站点运行,成功和空库存结果不会被重复导出。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source('RETRY_SOURCE', 'RETRY_LOGIN')
|
||||
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
|
||||
seed_file = tmp_path / 'retry-seed.xlsx'; _workbook(seed_file)
|
||||
seeded = inventory_configuration_test.report_test_export({'run_no': seed['run_no'], 'status': 'success', 'file_path': str(seed_file)})
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], _published_order_field(), code='RETRY_PROFILE')
|
||||
shipping_inventory_service.bind_source_parsing_profile([source['id']], profile['id'], actor_id=None, reason='重试测试', operation='bulk')
|
||||
batch = inventory_configuration_test.start_batch_test_export([source['id']], actor_id=None)
|
||||
run = batch['runs'][0]
|
||||
inventory_configuration_test.report_batch_test_exports({'validation_batch_id': batch['id'], 'results': [
|
||||
{'validation_run_no': run['run_no'], 'status': 'failed', 'error_message': 'temporary failure'},
|
||||
]})
|
||||
retried = inventory_configuration_test.retry_failed_validation_batch(batch['id'], actor_id=None)
|
||||
assert retried['retry_of_batch_id'] == batch['id']
|
||||
assert retried['total_count'] == 1
|
||||
|
||||
|
||||
def test_batch_callback_marks_changed_source_stale_and_ignores_unknown_run(app, tmp_path):
|
||||
"""配置变更后的旧批次回调必须失效,未知运行号不能污染同批次状态。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source('STALE_BATCH_SOURCE', 'STALE_BATCH_LOGIN')
|
||||
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
|
||||
seed_file = tmp_path / 'stale-batch-seed.xlsx'; _workbook(seed_file)
|
||||
seeded = inventory_configuration_test.report_test_export({'run_no': seed['run_no'], 'status': 'success', 'file_path': str(seed_file)})
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], _published_order_field(), code='STALE_BATCH_PROFILE')
|
||||
shipping_inventory_service.bind_source_parsing_profile([source['id']], profile['id'], actor_id=None, reason='过期回调测试', operation='bulk')
|
||||
batch = inventory_configuration_test.start_batch_test_export([source['id']], actor_id=None)
|
||||
run = batch['runs'][0]
|
||||
source_model = db.session.get(ShippingInventorySource, source['id'])
|
||||
source_model.config_version += 1
|
||||
db.session.commit()
|
||||
result_file = tmp_path / 'stale-batch-result.xlsx'; _workbook(result_file)
|
||||
reported = inventory_configuration_test.report_batch_test_exports({'validation_batch_id': batch['id'], 'results': [
|
||||
{'validation_run_no': 'UNKNOWN-RUN', 'status': 'success', 'file_path': str(result_file)},
|
||||
{'validation_run_no': run['run_no'], 'status': 'success', 'file_path': str(result_file)},
|
||||
]})
|
||||
# 关键断言:旧配置只标记自身 stale,未知运行号不会写入或影响批次统计。
|
||||
assert reported['ignored_count'] == 1
|
||||
assert reported['stale_count'] == 1
|
||||
assert reported['runs'][0]['result']['stale_configuration'] is True
|
||||
|
||||
|
||||
def test_latest_active_batch_restores_only_unfinished_validation(app, tmp_path):
|
||||
"""页面刷新只能恢复仍在执行的批次,已结束批次不会反复占用进度面板。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source('RESTORE_BATCH_SOURCE', 'RESTORE_BATCH_LOGIN')
|
||||
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
|
||||
seed_file = tmp_path / 'restore-batch-seed.xlsx'; _workbook(seed_file)
|
||||
seeded = inventory_configuration_test.report_test_export({'run_no': seed['run_no'], 'status': 'success', 'file_path': str(seed_file)})
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], _published_order_field(), code='RESTORE_BATCH_PROFILE')
|
||||
shipping_inventory_service.bind_source_parsing_profile([source['id']], profile['id'], actor_id=None, operation='bulk')
|
||||
batch = inventory_configuration_test.start_batch_test_export([source['id']], actor_id=None)
|
||||
# 关键断言:刷新期间读取服务端 active batch,会返回待 Worker 处理的真实运行。
|
||||
assert inventory_configuration_test.get_latest_active_validation_batch()['id'] == batch['id']
|
||||
inventory_configuration_test.report_batch_test_exports({'validation_batch_id': batch['id'], 'results': [
|
||||
{'validation_run_no': batch['runs'][0]['run_no'], 'status': 'empty'},
|
||||
]})
|
||||
# 关键断言:结束后不再恢复,避免管理端反复弹出旧批次。
|
||||
assert inventory_configuration_test.get_latest_active_validation_batch() is None
|
||||
|
||||
|
||||
def test_batch_progress_marks_only_claimed_current_run_processing(app, tmp_path):
|
||||
"""Worker 领取回调只更新本批次当前运行,终态运行不得被重新打开。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context(), patch(
|
||||
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
|
||||
):
|
||||
source = _source('PROGRESS_BATCH_SOURCE', 'PROGRESS_BATCH_LOGIN')
|
||||
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
|
||||
seed_file = tmp_path / 'progress-batch-seed.xlsx'; _workbook(seed_file)
|
||||
seeded = inventory_configuration_test.report_test_export({'run_no': seed['run_no'], 'status': 'success', 'file_path': str(seed_file)})
|
||||
profile = _publish_profile_from_analysis(seeded['analysis_id'], _published_order_field(), code='PROGRESS_BATCH_PROFILE')
|
||||
shipping_inventory_service.bind_source_parsing_profile([source['id']], profile['id'], actor_id=None, operation='bulk')
|
||||
batch = inventory_configuration_test.start_batch_test_export([source['id']], actor_id=None)
|
||||
run = batch['runs'][0]
|
||||
|
||||
progressed = inventory_configuration_test.report_batch_test_progress({
|
||||
'validation_batch_id': batch['id'], 'validation_run_no': run['run_no'], 'stage': 'rpa_exporting',
|
||||
})
|
||||
# 关键断言:页面可区分尚未领取与 Worker 已实际执行,批次仍等待最终结果。
|
||||
assert (progressed['status'], progressed['stage']) == ('processing', 'rpa_exporting')
|
||||
assert inventory_configuration_test.get_validation_batch(batch['id'])['status'] == 'running'
|
||||
|
||||
inventory_configuration_test.report_batch_test_exports({'validation_batch_id': batch['id'], 'results': [
|
||||
{'validation_run_no': run['run_no'], 'status': 'empty'},
|
||||
]})
|
||||
unchanged = inventory_configuration_test.report_batch_test_progress({
|
||||
'validation_batch_id': batch['id'], 'validation_run_no': run['run_no'], 'stage': 'rpa_exporting',
|
||||
})
|
||||
# 关键断言:迟到的 progress 不得覆盖已经确认的空库存终态。
|
||||
assert (unchanged['status'], unchanged['stage']) == ('completed_empty', 'empty_data_pending_validation')
|
||||
|
||||
|
||||
def test_latest_configuration_test_recovers_only_current_configuration(app, tmp_path):
|
||||
"""重开配置抽屉只能恢复当前版本测试;站点改动后可发起独立新测试而不复用旧运行。"""
|
||||
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
|
||||
@@ -197,12 +505,9 @@ def test_confirming_test_profile_binds_only_compatible_published_profile(app, tm
|
||||
source_model = db.session.get(ShippingInventorySource, source['id'])
|
||||
assert source_model.parsing_profile_id == profile['id']
|
||||
assert 'configuration_test' not in shipping_inventory_service.get_source_activation_status(source_model)['missing_requirements']
|
||||
assert 'warehouse_mapping' in shipping_inventory_service.get_source_activation_status(source_model)['missing_requirements']
|
||||
# 关键断言:外部仓库映射只在调拨前校验,不应出现在站点启用阻断清单。
|
||||
assert shipping_inventory_service.get_source_activation_status(source_model)['missing_requirements'] == ['excel_template']
|
||||
|
||||
db.session.add(ShippingInventoryExternalMapping(
|
||||
inventory_source_id=source['id'], freight_warehouse_id='DUB', external_system_code='TOPGP',
|
||||
external_warehouse_code='DUB-01', external_warehouse_name='Dublin', enabled=True,
|
||||
))
|
||||
template = ShippingExcelTemplate(
|
||||
template_code='TEST_ACTIVATION', display_name='Activation Template', version=1, status='published',
|
||||
storage_bucket='test', storage_key='activation.xlsx', original_filename='activation.xlsx',
|
||||
|
||||
Reference in new issue
Block a user