Best Python code snippet using tempest_python
test_roles.py
Source:test_roles.py
...31 user = self.get_user_by_name(self.data.test_user)32 tenant = self.get_tenant_by_name(self.data.test_tenant)33 role = self.get_role_by_name(self.data.test_role)34 return (user, tenant, role)35 def assert_role_in_role_list(self, role, roles):36 found = False37 for user_role in roles:38 if user_role['id'] == role['id']:39 found = True40 self.assertTrue(found, "assigned role was not in list")41 @attr(type='gate')42 def test_list_roles(self):43 # Return a list of all roles44 resp, body = self.client.list_roles()45 found = [role for role in body if role in self.data.roles]46 self.assertTrue(any(found))47 self.assertEqual(len(found), len(self.data.roles))48 @attr(type='gate')49 def test_role_create_delete(self):50 # Role should be created, verified, and deleted51 role_name = data_utils.rand_name(name='role-test-')52 resp, body = self.client.create_role(role_name)53 self.assertIn('status', resp)54 self.assertTrue(resp['status'].startswith('2'))55 self.assertEqual(role_name, body['name'])56 resp, body = self.client.list_roles()57 found = [role for role in body if role['name'] == role_name]58 self.assertTrue(any(found))59 resp, body = self.client.delete_role(found[0]['id'])60 self.assertIn('status', resp)61 self.assertTrue(resp['status'].startswith('2'))62 resp, body = self.client.list_roles()63 found = [role for role in body if role['name'] == role_name]64 self.assertFalse(any(found))65 @attr(type='gate')66 def test_assign_user_role(self):67 # Assign a role to a user on a tenant68 (user, tenant, role) = self._get_role_params()69 self.client.assign_user_role(tenant['id'], user['id'], role['id'])70 resp, roles = self.client.list_user_roles(tenant['id'], user['id'])71 self.assert_role_in_role_list(role, roles)72 @attr(type='gate')73 def test_remove_user_role(self):74 # Remove a role assigned to a user on a tenant75 (user, tenant, role) = self._get_role_params()76 resp, user_role = self.client.assign_user_role(tenant['id'],77 user['id'], role['id'])78 resp, body = self.client.remove_user_role(tenant['id'], user['id'],79 user_role['id'])80 self.assertEqual(resp['status'], '204')81 @attr(type='gate')82 def test_list_user_roles(self):83 # List roles assigned to a user on tenant84 (user, tenant, role) = self._get_role_params()85 self.client.assign_user_role(tenant['id'], user['id'], role['id'])86 resp, roles = self.client.list_user_roles(tenant['id'], user['id'])87 self.assert_role_in_role_list(role, roles)88class RolesTestXML(RolesTestJSON):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!