test_sub_plan_binding_service.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """子案跨主案挂载(0018)服务层载荷契约。
  2. 仅覆盖不依赖数据库与请求上下文的入参校验分支:
  3. _bind_payload 与 _version 均在 get_auth_context/事务之前执行。
  4. """
  5. from __future__ import annotations
  6. import pytest
  7. from dms.common.errors import InvalidArgumentError
  8. from dms.services.sub_plan_binding_service import bind_sub_plans, unbind_sub_plan
  9. def test_bind_rejects_missing_main_plan_row_version():
  10. with pytest.raises(InvalidArgumentError) as excinfo:
  11. bind_sub_plans(1, {"subPlanIds": ["2"]})
  12. assert excinfo.value.code == "INVALID_ARGUMENT"
  13. def test_bind_rejects_extra_fields():
  14. with pytest.raises(InvalidArgumentError):
  15. bind_sub_plans(
  16. 1,
  17. {"subPlanIds": ["2"], "mainPlanRowVersion": 0, "extra": 1},
  18. )
  19. def test_bind_rejects_empty_sub_plan_ids():
  20. with pytest.raises(InvalidArgumentError) as excinfo:
  21. bind_sub_plans(1, {"subPlanIds": [], "mainPlanRowVersion": 0})
  22. assert "subPlanIds必须是非空数组" in excinfo.value.message
  23. def test_bind_rejects_non_string_sub_plan_id():
  24. with pytest.raises(InvalidArgumentError) as excinfo:
  25. bind_sub_plans(1, {"subPlanIds": [2], "mainPlanRowVersion": 0})
  26. assert "subPlanIds[0]" in excinfo.value.message
  27. def test_bind_rejects_non_numeric_sub_plan_id():
  28. with pytest.raises(InvalidArgumentError):
  29. bind_sub_plans(
  30. 1, {"subPlanIds": ["abc"], "mainPlanRowVersion": 0}
  31. )
  32. def test_bind_rejects_negative_row_version():
  33. with pytest.raises(InvalidArgumentError) as excinfo:
  34. bind_sub_plans(1, {"subPlanIds": ["2"], "mainPlanRowVersion": -1})
  35. assert "mainPlanRowVersion" in excinfo.value.message
  36. def test_unbind_rejects_negative_row_version():
  37. with pytest.raises(InvalidArgumentError) as excinfo:
  38. unbind_sub_plan(1, 2, -1)
  39. assert "mainPlanRowVersion" in excinfo.value.message