Files
syops/backend/tests/test_shipping_task_supersession.py
T
hugo 5ef8329bd8 refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段
统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成
设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程
删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本
替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段
更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
2026-08-15 10:19:10 +08:00

46 lines
2.3 KiB
Python

"""阶段七:重发版本替代与上传后撤销门禁。"""
from __future__ import annotations
import pytest
from app import db
from app.core.errors import ConflictError
from app.models import ShippingFreightCancellation, ShippingNotice, User
from app.services.shipping_notice.freight_cancellation_service import complete_freight_cancellation
from app.services.shipping_notice.task_supersession_service import assert_task_not_supersession_blocked, establish_task_supersession
def _tasks(*, uploaded: bool) -> tuple[ShippingNotice, ShippingNotice, User]:
user = User(username=f'supersession-{uploaded}', email=f'supersession-{uploaded}@example.test', password_hash='x')
old = ShippingNotice(task_no=f'SN-SUP-OLD-{uploaded}', user_id=None, upload_status='uploaded' if uploaded else None, freight_ref_no='F-1' if uploaded else None)
db.session.add_all([user, old]); db.session.flush()
old.user_id = user.id
new = ShippingNotice(task_no=f'SN-SUP-NEW-{uploaded}', user_id=user.id, supersedes_task_id=old.id)
db.session.add(new); db.session.commit()
return old, new, user
def test_unuploaded_resend_voids_old_task_and_keeps_new_active(app):
"""关键断言:未上传重发立即使旧版失效,库存入口不能继续消费旧版本。"""
with app.app_context():
old, new, user = _tasks(uploaded=False)
establish_task_supersession(old_task=old, new_task=new, actor_id=user.id, reason='customer resend')
assert old.lifecycle_status == 'voided'
assert new.lifecycle_status == 'active'
def test_uploaded_resend_requires_cancellation_receipt_before_new_can_continue(app):
"""关键断言:已上传旧版必须先有撤销回执,后继版才恢复活动状态。"""
with app.app_context():
old, new, user = _tasks(uploaded=True)
establish_task_supersession(old_task=old, new_task=new, actor_id=user.id, reason='customer resend')
row = ShippingFreightCancellation.query.one()
assert new.lifecycle_status == 'blocked'
with pytest.raises(ConflictError):
assert_task_not_supersession_blocked(new)
complete_freight_cancellation(cancellation_id=row.id, actor_id=user.id, freight_receipt_no='CANCEL-1', receipt_asset_id=1)
assert row.status == 'cancelled'
assert old.lifecycle_status == 'voided'
assert new.lifecycle_status == 'active'