@@ -138,6 +138,12 @@ def test_list_configs_when_edit_mode_and_admin_without_allowance(self):
138138
139139 self .assert_list_config_names (self .admin_user , ['a1' , 'c2' ], mode = 'edit' )
140140
141+ def test_list_configs_when_edit_mode_and_admin_not_in_admin_users (self ):
142+ _create_script_config_file ('a1' , admin_users = ['user1' ])
143+ _create_script_config_file ('c2' , admin_users = ['adm_user' ])
144+
145+ self .assert_list_config_names (self .admin_user , ['c2' ], mode = 'edit' )
146+
141147 def test_list_configs_when_edit_mode_and_non_admin (self ):
142148 _create_script_config_file ('a1' , allowed_users = ['user1' ])
143149 _create_script_config_file ('c2' , allowed_users = ['user1' ])
@@ -266,6 +272,14 @@ def test_insert_sorted_values(self):
266272 ('requires_terminal' , False ),
267273 ('parameters' , [{'name' : 'param1' }])]))
268274
275+ def test_create_config_with_admin_users (self ):
276+ config = _prepare_script_config_object ('conf1' ,
277+ description = 'My wonderful test config' ,
278+ admin_users = ['another_user' ])
279+ self .config_service .create_config (self .admin_user , config )
280+
281+ _validate_config (self , 'conf1.json' , config )
282+
269283
270284class ConfigServiceUpdateConfigTest (unittest .TestCase ):
271285
@@ -375,6 +389,32 @@ def test_update_sorted_values(self):
375389 ('parameters' , [{'name' : 'param1' }])])
376390 _validate_config (self , 'confX.json' , body )
377391
392+ def test_update_config_allowed_admin_user (self ):
393+ config = _prepare_script_config_object ('Conf X' ,
394+ description = 'My wonderful test config' ,
395+ admin_users = ['admin_user' ])
396+ self .config_service .update_config (self .admin_user , config , 'confX.json' )
397+
398+ new_config = _prepare_script_config_object ('Conf X' ,
399+ description = 'New desc' )
400+ self .config_service .update_config (self .admin_user , new_config , 'confX.json' )
401+
402+ _validate_config (self , 'confX.json' , new_config )
403+
404+ def test_update_config_different_admin_user (self ):
405+ config = _prepare_script_config_object ('Conf X' ,
406+ description = 'My wonderful test config' ,
407+ admin_users = ['another_user' ])
408+ self .config_service .update_config (self .admin_user , config , 'confX.json' )
409+
410+ new_config = _prepare_script_config_object ('Conf X' ,
411+ description = 'New desc' ,
412+ admin_users = ['admin_user' ])
413+ self .assertRaisesRegex (ConfigNotAllowedException , 'is not allowed to modify' ,
414+ self .config_service .update_config , self .admin_user , new_config , 'confX.json' )
415+
416+ _validate_config (self , 'confX.json' , config )
417+
378418
379419class ConfigServiceLoadConfigForAdminTest (unittest .TestCase ):
380420 def setUp (self ):
@@ -413,6 +453,15 @@ def test_load_config_when_not_exists(self):
413453 config = self .config_service .load_config ('ConfX' , self .admin_user )
414454 self .assertIsNone (config )
415455
456+ def test_load_config_when_script_has_admin_users (self ):
457+ _create_script_config_file ('ConfX' , admin_users = ['admin_user' ])
458+ config = self .config_service .load_config ('ConfX' , self .admin_user )
459+ self .assertEqual (config ['filename' ], 'ConfX.json' )
460+
461+ def test_load_config_when_script_has_different_admin_users (self ):
462+ _create_script_config_file ('ConfX' , admin_users = ['admin_user2' ])
463+ self .assertRaises (ConfigNotAllowedException , self .config_service .load_config , 'ConfX' , self .admin_user )
464+
416465
417466def _create_script_config_file (filename , * , name = None , ** kwargs ):
418467 conf_folder = os .path .join (test_utils .temp_folder , 'runners' )
0 commit comments