from app.services.pl_personnel_user_bind import assert_sys_user_bind_available class FakeRow: def __init__(self, id, sys_user_id, del_flag=0): self.id = id self.sys_user_id = sys_user_id self.del_flag = del_flag def test_bind_ok_when_empty(): assert_sys_user_bind_available( existing=[], personnel_id="p1", sys_user_id="u1" ) def test_bind_rejects_other_personnel(): try: assert_sys_user_bind_available( existing=[FakeRow("p2", "u1")], personnel_id="p1", sys_user_id="u1", ) assert False, "expected ValueError" except ValueError as e: assert "已关联" in str(e) def test_bind_allows_self(): assert_sys_user_bind_available( existing=[FakeRow("p1", "u1")], personnel_id="p1", sys_user_id="u1", )