"""阶段八:库存、Excel 与人工上传的底层入口门禁。""" from __future__ import annotations import pytest from app.core.errors import ValidationError from app.models import ShippingNotice from app.services.shipping_notice.export import generate_shipment_excel from app.services.shipping_notice.upload_attempt_service import record_manual_upload def test_export_rejects_voided_task_before_reading_template(app): """关键断言:被替代/作废任务即使持有旧字段也不能从底层导出。""" with app.app_context(): task = ShippingNotice(task_no='SN-ENTRY-VOID', source_type='test', lifecycle_status='voided') from app import db db.session.add(task); db.session.commit() with pytest.raises(ValueError, match='作废'): generate_shipment_excel(task) def test_manual_upload_requires_uploadable_artifact(app): """关键断言:人工上传入口必须先存在可上传的导出 Artifact,不能仅凭客户端声明完成上传。""" with app.app_context(): task = ShippingNotice(task_no='SN-ENTRY-UPLOAD', source_type='test') from app import db db.session.add(task); db.session.commit() with pytest.raises(ValidationError) as error: record_manual_upload(task, artifact_id=None, operator_id=1) assert error.value.code == 'SHIPPING.UPLOAD_ARTIFACT_REQUIRED'