Files
syops/backend/tests/test_inventory_empty_snapshot.py
T

33 lines
1.5 KiB
Python

"""
tests/test_inventory_empty_snapshot.py
用途:验证 RPA 零库存结果仅形成审计快照,绝不作为可匹配库存复用。
依赖:inventory_snapshot_store、ShippingInventoryFile、Flask 测试应用。
逻辑:二期空结果由 Worker/回调写入 empty 快照;查询 ready 快照的运行链路必须忽略它。
"""
from app.services.shipping_notice.inventory_snapshot_store import (
create_empty_rpa_inventory_snapshot,
find_latest_ready_snapshot,
)
def test_empty_rpa_snapshot_is_auditable_but_never_available_for_matching(app):
"""空快照应保留导出事实和幂等身份,但 ready 查询必须返回空。"""
with app.app_context():
source = {'source_code': 'EMPTY_DUB', 'warehouse_id': 'DUB', 'connector_type': 'dbs'}
first = create_empty_rpa_inventory_snapshot(
source=source, rpa_run_no='EMPTY-RUN-1', schedule_run_id=None,
trigger_type='scheduled', message='no inventory data',
)
repeated = create_empty_rpa_inventory_snapshot(
source=source, rpa_run_no='EMPTY-RUN-1', schedule_run_id=None,
trigger_type='scheduled', message='no inventory data',
)
# 关键断言:重放同一空结果不重复写审计;空快照不能污染匹配可用库存池。
assert repeated.id == first.id
assert first.snapshot_status == 'empty'
assert first.line_count == 0
assert find_latest_ready_snapshot('EMPTY_DUB', 'DUB') is None