def test_permission_read(self): """@Test: Create an Permission entity and get it using :meth:`robottelo.orm.EntityReadMixin.read`. @Feature: Test multiple API paths @Assert: The just-read entity is an instance of the correct class and name and resource_type fields are populated """ attrs = entities.Permission().search(per_page=1)[0] read_entity = entities.Permission(id=attrs['id']).read() self.assertIsInstance(read_entity, entities.Permission) self.assertGreater(len(read_entity.name), 0) self.assertGreater(len(read_entity.resource_type), 0)
def give_user_permission(self, perm_name): """Give ``self.user`` the ``perm_name`` permission. This method creates a role and filter to accomplish the above goal. When complete, the relevant relationhips look like this: user → role ← filter → permission :param str perm_name: The name of a permission. For example: 'create_architectures'. :raises: ``AssertionError`` if more than one permission is found when searching for the permission with name ``perm_name``. :raises: ``requests.exceptions.HTTPError`` if an error occurs when updating ``self.user``'s roles. :rtype: None """ role_id = entities.Role().create()['id'] permission_ids = [ permission['id'] for permission in entities.Permission(name=perm_name).search() ] self.assertEqual(len(permission_ids), 1) entities.Filter(permission=permission_ids, role=role_id).create() # NOTE: An extra hash is used due to an API bug. client.put( self.user.path(), {u'user': {u'role_ids': [role_id]}}, auth=get_server_credentials(), verify=False, ).raise_for_status()
def test_directly_delete_filter(self): """@Test: Create a filter and delete it. @Assert: The deleted filter cannot be feched. @Feature: Filter """ filter_ = entities.Filter(id=entities.Filter(permission=[ permission['id'] for permission in entities.Permission( resource_type='ConfigTemplate').search() ], ).create()['id']) filter_.delete() with self.assertRaises(HTTPError): filter_.read_json()
def test_search_by_name(self, permission_name): """@test: Search for a permission by name. @feature: Permissions @assert: Only one permission is returned, and the permission returned is the one searched for. """ if ( permission_name == 'power_compute_resources_vms' and bz_bug_is_open(1198731)): self.skipTest('BZ 1198731 is open.') result = entities.Permission(name=permission_name).search() self.assertEqual(len(result), 1, permission_name) self.assertEqual(permission_name, result[0]['name'])
def test_create_filter_with_perms(self): """@Test: Create a filter and assign it some permissions. @Assert: The created filter has the assigned permissions. @Feature: Filter """ # Create a filter and assign all ConfigTemplate permissions to it. ct_perms = entities.Permission(resource_type='ConfigTemplate').search() filter_id = entities.Filter( permission=[permission['id'] for permission in ct_perms]).create()['id'] # Find all permissions assigned to filter `filter_id`. filter_perms = entities.Filter(id=filter_id).read_json()['permissions'] self.assertListEqual(ct_perms, filter_perms)
def test_search_by_resource_type(self, resource_type): """@test: Search for permissions by resource type. @feature: Permissions @assert: The permissions returned are equal to what is listed for that resource type in :data:`robottelo.common.constants.PERMISSIONS`. """ if resource_type is None: self.skipTest( "Can't search for permissions that have a resource_type of nil" ) perm_group = entities.Permission(resource_type=resource_type).search() self.assertItemsEqual( PERMISSIONS[resource_type], [perm['name'] for perm in perm_group], ) self.assertEqual(len(perm_group), len(PERMISSIONS[resource_type]))
def test_search_permissions(self): """@test: search with no parameters return all permissions @feature: Permission @assert: Search returns a list of all expected permissions """ perms = entities.Permission().search() perm_names = [perm['name'] for perm in perms] perm_resource_types = [perm['resource_type'] for perm in perms] self.assertEqual( frozenset(PERMISSION_RESOURCE_TYPES), frozenset(perm_resource_types), ) self.assertEqual( frozenset(PERMISSION_NAMES), frozenset(perm_names), )
def test_implicitly_delete_filter(self): """@Test: Create a filter and delete the role it points at. @Assert: The filter cannot be fetched. @Feature: Filter """ role = entities.Role(id=entities.Role().create()['id']) ct_perms = entities.Permission(resource_type='ConfigTemplate').search() filter_ = entities.Filter(id=entities.Filter( permission=[permission['id'] for permission in ct_perms], role=role.id, ).create()['id']) # A filter depends on a role. Deleting a role implicitly deletes the # filter pointing at it. role.delete() with self.assertRaises(HTTPError): role.read_json() with self.assertRaises(HTTPError): filter_.read_json()