feat(in-transit-transfer): 实现在途仓自动调拨Agent一期完整功能
包含后端服务层、任务处理器与消费Worker、前端聊天组件、数据库模型与迁移脚本、测试用例,同时新增外部系统连接器框架基础能力并更新相关文档。
This commit is contained in:
1 parent
f3050164d0
commit
6b53b563e7
177 files changed
+17260
-36
No files matched your search
@@ -0,0 +1,69 @@
|
||||
"""通用文件解析规则 purpose 字段测试(L0 纯单元 + DB 列校验)。
|
||||
|
||||
用途:验证 inventory_parsing_profile._validate_definition(purpose=...) 分支——
|
||||
movement 端点用定死领域字段(doc_no/material_code/quantity/movement_date 必填、
|
||||
不查库存字段目录、无 match_keys);inventory 维持既有 match_keys 校验。
|
||||
并用 app fixture 校验模型 purpose 列默认 'inventory'。
|
||||
依赖:inventory_parsing_profile._validate_definition(纯)、app(SQLite)。
|
||||
逻辑:_required_movement_field_ids 纯函数校验;模型列默认值经 app fixture 校验。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.shipping_notice.inventory_parsing_profile import _validate_definition
|
||||
|
||||
pytestmark = pytest.mark.pure_unit
|
||||
|
||||
|
||||
def _movement_definition() -> dict:
|
||||
return {
|
||||
'sheet_name': 'Movement',
|
||||
'header_row_index': 1,
|
||||
'field_mapping': {
|
||||
'doc_no': '单据编号',
|
||||
'line_no': '项次',
|
||||
'in_out_flag': '进出库别',
|
||||
'material_code': '料号',
|
||||
'material_name': '品名',
|
||||
'warehouse_code': '仓库',
|
||||
'storage_code': '储位',
|
||||
'lot_no': '批号',
|
||||
'quantity': '数量',
|
||||
'movement_date': '异动日期',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_movement_definition_validates_fixed_fields():
|
||||
"""movement 定义完整 → 通过校验,field_mapping 端点保留,match_keys 空。"""
|
||||
definition = _validate_definition(_movement_definition(), purpose='movement')
|
||||
assert definition['field_mapping']['doc_no'] == '单据编号'
|
||||
assert definition['field_mapping']['quantity'] == '数量'
|
||||
assert definition['match_keys'] == []
|
||||
|
||||
|
||||
def test_movement_definition_missing_fixed_field_rejected():
|
||||
"""movement 缺 movement_date → 阻断。"""
|
||||
raw = dict(_movement_definition())
|
||||
raw['field_mapping'] = {k: v for k, v in raw['field_mapping'].items() if k != 'movement_date'}
|
||||
with pytest.raises(ValidationError):
|
||||
_validate_definition(raw, purpose='movement')
|
||||
|
||||
|
||||
def test_movement_definition_rejects_unknown_field():
|
||||
"""movement 引用非定死领域字段 → 阻断。"""
|
||||
raw = dict(_movement_definition())
|
||||
raw['field_mapping'] = {**raw['field_mapping'], 'free_text': '随意列'}
|
||||
with pytest.raises(ValidationError):
|
||||
_validate_definition(raw, purpose='movement')
|
||||
|
||||
|
||||
def test_model_purpose_column_defaults_to_inventory(app):
|
||||
"""模型 purpose 列默认 'inventory'(既有行不回填)。"""
|
||||
from app.models import ShippingInventoryParsingProfile
|
||||
|
||||
existing = ShippingInventoryParsingProfile.query.filter_by(profile_code='TEST_RUNTIME').first()
|
||||
assert existing is not None and existing.purpose == 'inventory'
|
||||
Reference in new issue
Block a user