"""子案跨主案挂载(0018)服务层载荷契约。 仅覆盖不依赖数据库与请求上下文的入参校验分支: _bind_payload 与 _version 均在 get_auth_context/事务之前执行。 """ from __future__ import annotations import pytest from dms.common.errors import InvalidArgumentError from dms.services.sub_plan_binding_service import bind_sub_plans, unbind_sub_plan def test_bind_rejects_missing_main_plan_row_version(): with pytest.raises(InvalidArgumentError) as excinfo: bind_sub_plans(1, {"subPlanIds": ["2"]}) assert excinfo.value.code == "INVALID_ARGUMENT" def test_bind_rejects_extra_fields(): with pytest.raises(InvalidArgumentError): bind_sub_plans( 1, {"subPlanIds": ["2"], "mainPlanRowVersion": 0, "extra": 1}, ) def test_bind_rejects_empty_sub_plan_ids(): with pytest.raises(InvalidArgumentError) as excinfo: bind_sub_plans(1, {"subPlanIds": [], "mainPlanRowVersion": 0}) assert "subPlanIds必须是非空数组" in excinfo.value.message def test_bind_rejects_non_string_sub_plan_id(): with pytest.raises(InvalidArgumentError) as excinfo: bind_sub_plans(1, {"subPlanIds": [2], "mainPlanRowVersion": 0}) assert "subPlanIds[0]" in excinfo.value.message def test_bind_rejects_non_numeric_sub_plan_id(): with pytest.raises(InvalidArgumentError): bind_sub_plans( 1, {"subPlanIds": ["abc"], "mainPlanRowVersion": 0} ) def test_bind_rejects_negative_row_version(): with pytest.raises(InvalidArgumentError) as excinfo: bind_sub_plans(1, {"subPlanIds": ["2"], "mainPlanRowVersion": -1}) assert "mainPlanRowVersion" in excinfo.value.message def test_unbind_rejects_negative_row_version(): with pytest.raises(InvalidArgumentError) as excinfo: unbind_sub_plan(1, 2, -1) assert "mainPlanRowVersion" in excinfo.value.message