1414from ai .backend .common .plugin .hook import HookPluginContext
1515from ai .backend .common .types import ResourceSlot
1616from ai .backend .manager .actions .validators import ActionValidators
17+ from ai .backend .manager .actions .validators .rbac import RBACValidators
1718from ai .backend .manager .api .rest .middleware import auth as _auth_api
1819from ai .backend .manager .api .rest .resource .handler import ResourceHandler
1920from ai .backend .manager .api .rest .resource .registry import register_resource_routes
5152PresetFactory = Callable [..., Coroutine [Any , Any , PresetFixtureData ]]
5253
5354
55+ def _create_mock_validators () -> ActionValidators :
56+ """Create a properly structured mock ActionValidators with rbac attribute."""
57+ mock_rbac = MagicMock (spec = RBACValidators )
58+ mock_rbac .scope = MagicMock ()
59+ mock_rbac .single_entity = MagicMock ()
60+ mock_validators = MagicMock (spec = ActionValidators )
61+ mock_validators .rbac = mock_rbac
62+ return mock_validators
63+
64+
5465@pytest .fixture ()
5566def container_registry_processors (
5667 database_engine : ExtendedAsyncSAEngine ,
5768) -> ContainerRegistryProcessors :
5869 repo = ContainerRegistryRepository (database_engine )
5970 service = ContainerRegistryService (database_engine , repo )
6071 return ContainerRegistryProcessors (
61- service = service , action_monitors = [], validators = MagicMock ( spec = ActionValidators )
72+ service = service , action_monitors = [], validators = _create_mock_validators ( )
6273 )
6374
6475
@@ -71,7 +82,7 @@ def resource_preset_processors(
7182 repo = ResourcePresetRepository (database_engine , valkey_clients .stat , config_provider )
7283 service = ResourcePresetService (repo )
7384 return ResourcePresetProcessors (
74- service = service , action_monitors = [], validators = MagicMock ( spec = ActionValidators )
85+ service = service , action_monitors = [], validators = _create_mock_validators ( )
7586 )
7687
7788
@@ -103,7 +114,7 @@ def agent_processors(
103114 agent_cache = AsyncMock (),
104115 )
105116 return AgentProcessors (
106- service = service , action_monitors = [], validators = MagicMock ( spec = ActionValidators )
117+ service = service , action_monitors = [], validators = _create_mock_validators ( )
107118 )
108119
109120
@@ -120,7 +131,7 @@ def group_processors(
120131 group_repos = GroupRepositories (repository = group_repo )
121132 service = GroupService (storage_manager , config_provider , valkey_clients .stat , group_repos )
122133 return GroupProcessors (
123- group_service = service , action_monitors = [], validators = MagicMock ( spec = ActionValidators )
134+ group_service = service , action_monitors = [], validators = _create_mock_validators ( )
124135 )
125136
126137
@@ -133,7 +144,7 @@ def user_processors(
133144 user_repo = UserRepository (database_engine )
134145 service = UserService (storage_manager , valkey_clients .stat , AsyncMock (), user_repo )
135146 return UserProcessors (
136- user_service = service , action_monitors = [], validators = MagicMock ( spec = ActionValidators )
147+ user_service = service , action_monitors = [], validators = _create_mock_validators ( )
137148 )
138149
139150
0 commit comments