"""角色列表 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