Files
syops/backend/tests/test_shipping_xfa_ocr_automark.py
hugo 1b6483a4ea feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程
清理废弃的shipping xfa ocr automark相关代码和job配置
新增收料报表管理的前端页面、路由和侧边栏入口
新增后端收料报表配置接口、数据库模型和RPA脚本
优化发货通知流程的重试策略,将shipping相关job默认不自动重试
移除废弃的库存源确认相关逻辑,更新流程门禁规则
重构订单模板的值适配器模块,新增坐标OCR值适配器
清理前端shipping菜单和action的废弃选项
更新相关文档和测试用例,调整.gitignore忽略规则
2026-08-20 20:23:10 +08:00

85 lines
2.9 KiB
Python

"""
tests/test_shipping_xfa_ocr_automark.py
用途:验收 XFA 最终 datasets 映射的契约,以及遗留 synthetic 视觉确认的降级。
依赖:XFA Profile 契约、旧 preview 清理服务、pytest。
逻辑:自动标记已完全复用统一 PDF/OCR Job,本文件不再维护 XFA 专用自动标注路径。
"""
from __future__ import annotations
import pytest
from app.services.shipping_notice.document_layout.xfa_contract import OrderXfaDatasetProfile
pytestmark = pytest.mark.pure_unit
def _source_contract() -> dict:
"""最小 XFA source_contract。"""
return {
'template_packet_checksum': 'sha256:' + ('a' * 64),
'dataset_structure_fingerprint': 'sha256:' + ('b' * 64),
'dataset_root_path': '/data',
'authoritative_line_collection_path': '/data/ITEMS/DATA',
'mirror_collection_paths': [],
}
def _definition_with_binding(*, visual_status: str = 'suggested', region_kind: str = 'field') -> dict:
"""构造含统一 binding 的草稿 definition。"""
checksum = 'sha256:' + ('c' * 64)
visual = {
'page_no': 1,
'normalized_bbox': {'x0': 0.1, 'y0': 0.4, 'x1': 0.4, 'y1': 0.5},
'source': 'suggested',
'status': visual_status,
'confidence': 0.95,
'region_kind': region_kind,
}
if visual_status == 'confirmed':
visual.update({
'preview_render_checksum': checksum,
'render_mode': 'xfa_dataset_preview',
'confirmed_on': 'xfa_dataset_preview',
'renderer_version': 'hxops.xfa_static_preview.v1',
})
return {
'template_mode': 'xfa_dataset',
'source_contract': _source_contract(),
'header_mappings': [],
'line_mapping': {'row_path': '/data/ITEMS/DATA', 'fields': []},
'bindings': [{
'binding_id': 'bind-po-001',
'field_id': 'f-h-po',
'field_code': 'customer_po_no',
'scope': 'header',
'value_binding': {
'type': 'xfa_dataset',
'path_id': 'path-po',
'data_path': '/data/HEADER/EBELN',
},
'visual_binding': visual,
}],
'xfa_preview': {
'status': 'ready',
'preview_render_checksum': checksum,
'render_mode': 'xfa_dataset_preview',
'renderer_version': 'hxops.xfa_static_preview.v1',
'page_count': 1,
'unresolved_ocr_mismatch_count': 0,
},
}
def test_xfa_profile_rejects_coordinate_value_binding():
"""关键断言:XFA 正式值只能来自 datasets,坐标/OCR 只能作为视觉证据。"""
definition = _definition_with_binding()
definition['bindings'][0]['value_binding'] = {
'type': 'pdf_coordinate',
'region_id': 'visual-only-box',
}
with pytest.raises(ValueError, match='xfa_dataset'):
OrderXfaDatasetProfile.model_validate(definition)