"""库存源仓库事实边界测试。""" from types import SimpleNamespace from app.models import ShippingNoticeLine from app.services.shipping_notice.onhand_source_gate import resolve_inventory_source_warehouse_id def test_fixed_source_warehouse_comes_from_source_configuration_not_order_task() -> None: """固定仓在 OT 不含仓库属性时仍由库存源配置确定。""" task = SimpleNamespace(id=1, source_code='DUBLIN') source = { 'source_code': 'DUBLIN', 'warehouse_resolution_mode': 'fixed', 'fixed_warehouse_id': ' DUB ', } assert resolve_inventory_source_warehouse_id(task, source=source) == 'DUB' def test_dynamic_source_has_no_warehouse_before_verified_inventory_link() -> None: """动态仓不得从 OT 推测,须等待库存文件或 Link 的已验证事实。""" task = SimpleNamespace(id=1, source_code='DYNAMIC') source = { 'source_code': 'DYNAMIC', 'warehouse_resolution_mode': 'inventory_match', 'fixed_warehouse_id': None, } assert resolve_inventory_source_warehouse_id(task, source=source) is None def test_shipping_notice_line_owns_confirmed_inventory_facts() -> None: """正式通知仓库、来源和文件必须是行级字段,而非通知单头或 OT 字段。""" columns = ShippingNoticeLine.__table__.c assert {'inventory_source_code', 'inventory_file_id', 'inventory_warehouse_id'} <= set(columns.keys()) def test_match_completed_requires_all_frozen_order_lines(monkeypatch) -> None: """单个 Match 成功不能让尚有未匹配 Snapshot 项次的订单通过满足性 Gate。""" from app.services.shipping_notice import fulfillment_workflow as workflow matched = SimpleNamespace(snapshot_line_id=101, match_result='matched', shortage_qty='0') class Query: def filter_by(self, **_kwargs): return self def all(self): return [matched] class MatchModel: query = Query() snapshot = SimpleNamespace(lines=[SimpleNamespace(id=101), SimpleNamespace(id=102)]) monkeypatch.setattr('app.models.ShippingNoticeLineOnhandMatch', MatchModel) monkeypatch.setattr(workflow.db.session, 'get', lambda _model, _identifier: snapshot) monkeypatch.setattr(workflow, '_released_snapshot_line_ids_for_task', lambda _task: set()) assert workflow.match_completed(SimpleNamespace(id=1, order_snapshot_id=10)) is False