Files
zkxw/backend/tests/test_role_list_bound_names.py
T
zlwuandCursor de22678c87 feat: ship OA drafts/badges, role dual-track, and test-env deploy tooling.
Add approval instance drafts with menu badges, dual-track user/role read model and role bound names, form-designer outline docs, and bare-metal test deploy scripts. Ignore local test-server credential file.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 13:58:47 +08:00

36 lines
1.3 KiB
Python

"""角色列表 boundUserNames / boundPostNames enrichment。"""
import inspect
from app.crud import role as role_crud
class _DummySession:
def query(self, *args, **kwargs): # pragma: no cover
raise AssertionError("空入参不应访问数据库")
def test_bound_user_names_by_role_ids_empty():
db = _DummySession()
assert role_crud._bound_user_names_by_role_ids(db, [], "zkxw") == {}
assert role_crud._bound_user_names_by_role_ids(db, ["r1"], "") == {}
def test_bound_post_names_by_role_ids_empty():
db = _DummySession()
assert role_crud._bound_post_names_by_role_ids(db, [], "zkxw") == {}
assert role_crud._bound_post_names_by_role_ids(db, ["r1"], "") == {}
def test_user_display_name_prefers_nick():
assert role_crud._user_display_name("张三", "zhangsan") == "张三"
assert role_crud._user_display_name("", "zhangsan") == "zhangsan"
assert role_crud._user_display_name(" ", "u1") == "u1"
assert role_crud._user_display_name(None, None) == ""
def test_list_roles_enriches_bound_names():
source = inspect.getsource(role_crud.list_roles)
assert "_bound_user_names_by_role_ids" in source
assert "_bound_post_names_by_role_ids" in source
assert "boundUserNames" in inspect.getsource(role_crud._row_to_dict) or "bound_user_names" in source