test_effective_role_user_lookup.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. """按有效角色查用户:空入参行为(不依赖 DB)。"""
  2. from app.services.web_auth_roles import (
  3. list_user_ids_with_any_effective_role_ids,
  4. list_user_ids_with_effective_role_name,
  5. )
  6. class _DummySession:
  7. def query(self, *args, **kwargs): # pragma: no cover
  8. raise AssertionError("空入参不应访问数据库")
  9. def test_list_by_role_name_empty_inputs():
  10. db = _DummySession()
  11. assert list_user_ids_with_effective_role_name(db, tenant_no="", role_name="实验专员") == set()
  12. assert list_user_ids_with_effective_role_name(db, tenant_no="zkxw", role_name="") == set()
  13. assert list_user_ids_with_effective_role_name(
  14. db, tenant_no="zkxw", role_name="实验专员", candidate_user_ids=[]
  15. ) == set()
  16. def test_list_by_role_ids_empty_inputs():
  17. db = _DummySession()
  18. assert list_user_ids_with_any_effective_role_ids(db, tenant_no="zkxw", role_ids=[]) == []
  19. assert list_user_ids_with_any_effective_role_ids(db, tenant_no="", role_ids=["r1"]) == []
  20. assert (
  21. list_user_ids_with_any_effective_role_ids(
  22. db, tenant_no="zkxw", role_ids=["r1"], candidate_user_ids=[]
  23. )
  24. == []
  25. )