def test_populate_resource_columns(self): """Test function that fills in extra columns""" singleton_output = copy(example_role_data) Role.populate_resource_columns(singleton_output) self.assertIn('resource_name', singleton_output) # Case for non-singleton roles normal_output = copy(example_role_data) normal_output['summary_fields'] = { "resource_name": "Default", "resource_type": "organization", "resource_type_display_name": "Organization"} Role.populate_resource_columns(normal_output) self.assertIn('resource_name', normal_output)
def test_populate_resource_columns(self): """Test function that fills in extra columns""" singleton_output = copy(example_role_data) Role.populate_resource_columns(singleton_output) self.assertIn('resource_name', singleton_output) # Case for non-singleton roles normal_output = copy(example_role_data) normal_output['summary_fields'] = { "resource_name": "Default", "resource_type": "organization", "resource_type_display_name": "Organization" } Role.populate_resource_columns(normal_output) self.assertIn('resource_name', normal_output)
def test_obj_res_missing_errors(self): """Testing obj_res method, ability to produce errors here.""" with self.assertRaises(exc.UsageError): obj, obj_type, res, res_type = Role.obj_res({ "inventory": None, "credential": None })
def test_data_endpoint_inventory_admin(self): """Translation of input args to lookup args, space in type""" kwargs = {'user': 2, 'type': 'Inventory Admin', 'inventory': 5} data, endpoint = Role.data_endpoint(kwargs, ignore=['res']) self.assertIn('members__in', data) self.assertEqual(endpoint, '/roles/') self.assertIn('role_field', data) self.assertEqual(data['role_field'], 'inventory_admin_role')
def test_obj_res_too_many_errors(self): """Testing obj_res method, ability to duplicate errors.""" with self.assertRaises(exc.UsageError): obj, obj_type, res, res_type = Role.obj_res({ "inventory": 1, "target_team": 2, "user": 3, "team": 5 })
def test_obj_res_team(self): """Test that the input format can be correctly translated into the object & resource data structure for granting the resource role to the object. Do this for teams getting read permission on inventory here.""" obj, obj_type, res, res_type = Role.obj_res( {"team": 3, "inventory": 5, "type": "read", "not_a_res": None, "credential": None, "project": None}) self.assertEqual(obj, 3) self.assertEqual(obj_type, 'team') self.assertEqual(res, 5) self.assertEqual(res_type, 'inventory')
def test_obj_res_team(self): """Test that the input format can be correctly translated into the object & resource data structure for granting the resource role to the object. Do this for teams getting read permission on inventory here.""" obj, obj_type, res, res_type = Role.obj_res({ "team": 3, "inventory": 5, "type": "read", "not_a_res": None, "credential": None, "project": None }) self.assertEqual(obj, 3) self.assertEqual(obj_type, 'team') self.assertEqual(res, 5) self.assertEqual(res_type, 'inventory')
def test_data_endpoint_inventory_ignore(self): """Translation of input args to lookup args, ignoring inventory""" kwargs = {'user': 2, 'type': 'admin', 'inventory': 5} data, endpoint = Role.data_endpoint(kwargs, ignore=['res']) self.assertIn('members__in', data) self.assertEqual(endpoint, '/roles/')
def test_data_endpoint_team_no_res(self): """Translation of input args to lookup args, using team""" kwargs = {'team': 2} data, endpoint = Role.data_endpoint(kwargs, ignore=[]) self.assertEqual(endpoint, 'teams/2/roles/') self.assertNotIn('object_id', data)
def test_obj_res_too_many_errors(self): """Testing obj_res method, ability to duplicate errors.""" with self.assertRaises(exc.UsageError): obj, obj_type, res, res_type = Role.obj_res( {"inventory": 1, "target_team": 2, "user": 3, "team": 5})
def test_obj_res_missing_errors(self): """Testing obj_res method, ability to produce errors here.""" with self.assertRaises(exc.UsageError): obj, obj_type, res, res_type = Role.obj_res( {"inventory": None, "credential": None})
def test_plurals(self): """English words changed from singular to plural""" self.assertEqual(Role.pluralize("inventory"), "inventories") self.assertEqual(Role.pluralize("job_template"), "job_templates")