|
|
@@ -0,0 +1,22 @@
|
|
|
+import pytest
|
|
|
+from fastapi import HTTPException
|
|
|
+
|
|
|
+from app.schemas.pl.plan import PlanContractLink
|
|
|
+from app.services.pl_plan_stop_service import assert_at_most_one_contract
|
|
|
+
|
|
|
+
|
|
|
+def test_assert_at_most_one_contract_allows_zero_or_one():
|
|
|
+ assert assert_at_most_one_contract([], "装货合同") == []
|
|
|
+ one = [PlanContractLink(contractId="c1", contractNo="N1")]
|
|
|
+ assert assert_at_most_one_contract(one, "装货合同") == one
|
|
|
+
|
|
|
+
|
|
|
+def test_assert_at_most_one_contract_rejects_two():
|
|
|
+ links = [
|
|
|
+ PlanContractLink(contractId="c1", contractNo="N1"),
|
|
|
+ PlanContractLink(contractId="c2", contractNo="N2"),
|
|
|
+ ]
|
|
|
+ with pytest.raises(HTTPException) as exc:
|
|
|
+ assert_at_most_one_contract(links, "装货合同")
|
|
|
+ assert exc.value.status_code == 422
|
|
|
+ assert "只能选择 1 份" in str(exc.value.detail)
|