Files
syops/backend/tests/test_shipping_notice_ui_state.py
T

78 lines
2.5 KiB
Python

"""
tests/test_shipping_notice_ui_state.py
用途:校验发货通知 UI State 摘要字段与 entry_surface 映射。
依赖:pytest、ShippingTask、ui_state、state_machine constants。
逻辑:build_task_ui_state.summary 含 STP 可解释字段;复核 vs 待上传入口面正确。
"""
from app.models import ShippingTask
from app.services.shipping_notice.constants import (
CP_EXPORT_READY,
CP_PARSE_REVIEW,
PH_LOW_CONF,
RS_PARSE_REVIEW,
)
from app.services.shipping_notice.ui_state import build_task_ui_state
_REQUIRED_SUMMARY_KEYS = {
"title",
"message",
"issues",
"stage",
"checkpoint_kind",
"current_todo",
"pause_reason",
"next_auto_step",
"event_at",
"entry_surface",
"allowed_actions",
}
def test_build_task_ui_state_summary_has_required_keys(app) -> None:
"""summary 必须包含 STP 可解释字段全集。"""
with app.app_context():
task = ShippingTask(
task_no="SN-UI-SUMMARY",
process_status="pending_review",
review_status=RS_PARSE_REVIEW,
pending_human_reason=PH_LOW_CONF,
source_type="manual",
)
state = build_task_ui_state(task)
assert set(_REQUIRED_SUMMARY_KEYS).issubset(state["summary"].keys())
assert state["checkpoint"] == CP_PARSE_REVIEW
assert state["checkpoint_kind"] == "must_human"
def test_entry_surface_parse_review_is_review_workbench(app) -> None:
"""解析复核应进入人工复核工作台。"""
with app.app_context():
task = ShippingTask(
task_no="SN-UI-REVIEW",
process_status="pending_review",
review_status=RS_PARSE_REVIEW,
pending_human_reason=PH_LOW_CONF,
source_type="manual",
)
state = build_task_ui_state(task)
assert state["summary"]["entry_surface"] == "review_workbench"
def test_entry_surface_export_ready_is_task_workbench(app) -> None:
"""Excel 待人工上传应进入任务处理工作台。"""
with app.app_context():
task = ShippingTask(
task_no="SN-UI-EXPORT",
process_status="matched",
source_type="manual",
export_file_path="/tmp/shipping-export.xlsx",
export_file_name="shipping-export.xlsx",
)
state = build_task_ui_state(task)
assert state["checkpoint"] == CP_EXPORT_READY
assert state["checkpoint_kind"] == "wait_manual_upload"
assert state["summary"]["entry_surface"] == "task_workbench"