6a2e43f829
1、将药物发货新建和编辑从独立页面迁移到抽屉,详情页支持权限控制和停用中心只读状态。 2、补充药物发货状态字段校验,统一 PENDING、IN_TRANSIT、SIGNED、EXCEPTION 状态及演示数据。 3、为物资设备增加详情页和编辑抽屉,复用通用附件上传并按项目权限控制操作入口。 4、将启动会和培训授权编辑迁移到抽屉,详情页按中心过滤培训记录并移除旧独立编辑路由。
82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
import uuid
|
|
from datetime import date
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from app.schemas.drug_shipment import DrugShipmentCreate
|
|
|
|
|
|
def shipment_payload(**overrides):
|
|
payload = {
|
|
"direction": "SEND",
|
|
"center_id": uuid.uuid4(),
|
|
"ship_date": date(2026, 6, 4),
|
|
"receive_date": None,
|
|
"quantity": 1,
|
|
"batch_no": "DP-001",
|
|
"carrier": "顺丰",
|
|
"tracking_no": "SF100003",
|
|
"status": "IN_TRANSIT",
|
|
"remark": None,
|
|
}
|
|
payload.update(overrides)
|
|
return payload
|
|
|
|
|
|
def test_create_allows_pending_shipment_execution_fields_to_be_empty():
|
|
shipment = DrugShipmentCreate.model_validate(
|
|
shipment_payload(
|
|
status="PENDING",
|
|
ship_date=None,
|
|
quantity=None,
|
|
batch_no=None,
|
|
carrier=None,
|
|
tracking_no=None,
|
|
receive_date=None,
|
|
remark=None,
|
|
)
|
|
)
|
|
|
|
assert shipment.ship_date is None
|
|
assert shipment.quantity is None
|
|
assert shipment.batch_no is None
|
|
assert shipment.carrier is None
|
|
assert shipment.tracking_no is None
|
|
|
|
|
|
@pytest.mark.parametrize("field_name", ["ship_date", "quantity", "batch_no", "carrier", "tracking_no"])
|
|
def test_create_requires_shipment_execution_fields_after_pending(field_name):
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
DrugShipmentCreate.model_validate(shipment_payload(status="IN_TRANSIT", **{field_name: None}))
|
|
|
|
assert "发运信息" in str(exc_info.value)
|
|
|
|
|
|
def test_create_allows_pending_receipt_fields_to_be_empty():
|
|
shipment = DrugShipmentCreate.model_validate(shipment_payload())
|
|
|
|
assert shipment.receive_date is None
|
|
assert shipment.remark is None
|
|
|
|
|
|
def test_create_requires_receive_date_when_signed():
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
DrugShipmentCreate.model_validate(shipment_payload(status="SIGNED", receive_date=None))
|
|
|
|
assert "接收日期" in str(exc_info.value)
|
|
|
|
|
|
def test_create_rejects_removed_returned_status():
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
DrugShipmentCreate.model_validate(shipment_payload(status="RETURNED", receive_date=date(2026, 6, 5)))
|
|
|
|
assert "无效状态" in str(exc_info.value)
|
|
|
|
|
|
def test_create_requires_remark_when_exceptional():
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
DrugShipmentCreate.model_validate(shipment_payload(status="EXCEPTION", remark=""))
|
|
|
|
assert "备注" in str(exc_info.value)
|