How to use setup_test_tenant method in tempest

Best Python code snippet using tempest_python

test_users.py

Source:test_users.py Github

copy

Full Screen

...26 alt_description = rand_name('desc_')27 @attr(type='smoke')28 def test_create_user(self):29 """Create a user"""30 self.data.setup_test_tenant()31 resp, user = self.client.create_user(self.alt_user, self.alt_password,32 self.data.tenant['id'],33 self.alt_email)34 self.data.users.append(user)35 self.assertEqual('200', resp['status'])36 self.assertEqual(self.alt_user, user['name'])37 @attr(type='negative')38 def test_create_user_by_unauthorized_user(self):39 """Non-admin should not be authorized to create a user"""40 self.data.setup_test_tenant()41 self.assertRaises(exceptions.Unauthorized,42 self.non_admin_client.create_user, self.alt_user,43 self.alt_password, self.data.tenant['id'],44 self.alt_email)45 @attr(type='negative')46 def test_create_user_with_empty_name(self):47 """User with an empty name should not be created"""48 self.data.setup_test_tenant()49 self.assertRaises(exceptions.BadRequest, self.client.create_user, '',50 self.alt_password, self.data.tenant['id'],51 self.alt_email)52 @attr(type='negative')53 @unittest.skip("Until Bug 966251 is fixed")54 def test_create_user_with_name_length_over_64(self):55 """Length of user name filed should be restricted to 64 characters"""56 self.data.setup_test_tenant()57 self.assertRaises(exceptions.BadRequest, self.client.create_user,58 'a' * 65, self.alt_password,59 self.data.tenant['id'], self.alt_email)60 @attr(type='negative')61 def test_create_user_with_duplicate_name(self):62 """Duplicate user should not be created"""63 self.data.setup_test_user()64 self.assertRaises(exceptions.Duplicate, self.client.create_user,65 self.data.test_user, self.data.test_password,66 self.data.tenant['id'], self.data.test_email)67 @attr(type='negative')68 @unittest.skip("Until Bug 999084 is fixed")69 def test_create_user_with_empty_password(self):70 """User with an empty password should not be created"""71 self.data.setup_test_tenant()72 self.assertRaises(exceptions.BadRequest, self.client.create_user,73 self.alt_user, '', self.data.tenant['id'],74 self.alt_email)75 @attr(type='nagative')76 @unittest.skip("Until Bug 999084 is fixed")77 def test_create_user_with_long_password(self):78 """User having password exceeding max length should not be created"""79 self.data.setup_test_tenant()80 self.assertRaises(exceptions.BadRequest, self.client.create_user,81 self.alt_user, 'a' * 65, self.data.tenant['id'],82 self.alt_email)83 @attr(type='negative')84 @unittest.skip("Until Bug 999084 is fixed")85 def test_create_user_with_invalid_email_format(self):86 """Email format should be validated while creating a user"""87 self.data.setup_test_tenant()88 self.assertRaises(exceptions.BadRequest, self.client.create_user,89 self.alt_user, '', self.data.tenant['id'], '12345')90 @attr(type='negative')91 def test_create_user_for_non_existant_tenant(self):92 """Attempt to create a user in a non-existent tenant should fail"""93 self.assertRaises(exceptions.NotFound, self.client.create_user,94 self.alt_user, self.alt_password, '49ffgg99999',95 self.alt_email)96 @attr(type='negative')97 def test_create_user_request_without_a_token(self):98 """Request to create a user without a valid token should fail"""99 self.data.setup_test_tenant()100 # Get the token of the current client101 token = self.client.get_auth()102 # Delete the token from database103 self.client.delete_token(token)104 self.assertRaises(exceptions.Unauthorized, self.client.create_user,105 self.alt_user, self.alt_password,106 self.data.tenant['id'], self.alt_email)107 # Unset the token to allow further tests to generate a new token108 self.client.clear_auth()109 @attr(type='smoke')110 def test_delete_user(self):111 """Delete a user"""112 self.data.setup_test_tenant()113 resp, user = self.client.create_user('user_1234', self.alt_password,114 self.data.tenant['id'],115 self.alt_email)116 resp, body = self.client.delete_user(user['id'])117 self.assertEquals('204', resp['status'])118 @attr(type='negative')119 def test_delete_users_by_unauthorized_user(self):120 """Non admin user should not be authorized to delete a user"""121 self.data.setup_test_user()122 self.assertRaises(exceptions.Unauthorized,123 self.non_admin_client.delete_user,124 self.data.user['id'])125 @attr(type='negative')126 def test_delete_non_existant_user(self):127 """Attempt to delete a non-existent user should fail"""128 self.assertRaises(exceptions.NotFound, self.client.delete_user,129 'junk12345123')130 @attr(type='smoke')131 def test_user_authentication(self):132 """Valid user's token is authenticated"""133 self.data.setup_test_user()134 # Get a token135 self.token_client.auth(self.data.test_user, self.data.test_password,136 self.data.test_tenant)137 # Re-auth138 resp, body = self.token_client.auth(self.data.test_user,139 self.data.test_password,140 self.data.test_tenant)141 self.assertEqual('200', resp['status'])142 @attr(type='negative')143 def test_authentication_for_disabled_user(self):144 """Disabled user's token should not get authenticated"""145 self.data.setup_test_user()146 self.disable_user(self.data.test_user)147 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,148 self.data.test_user,149 self.data.test_password,150 self.data.test_tenant)151 @attr(type='negative')152 @unittest.skip('Until Bug 988920 is fixed')153 def test_authentication_when_tenant_is_disabled(self):154 """User's token for a disabled tenant should not be authenticated"""155 self.data.setup_test_user()156 self.disable_tenant(self.data.test_tenant)157 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,158 self.data.test_user,159 self.data.test_password,160 self.data.test_tenant)161 @attr(type='negative')162 @unittest.skip('Until Bug 988920 is fixed')163 def test_authentication_with_invalid_tenant(self):164 """User's token for an invalid tenant should not be authenticated"""165 self.data.setup_one_user()166 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,167 self.data.test_user,168 self.data.test_password,169 'junktenant1234')170 @attr(type='negative')171 def test_authentication_with_invalid_username(self):172 """Non-existent user's token should not get authenticated"""173 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,174 'junkuser123', self.data.test_password,175 self.data.test_tenant)176 @attr(type='negative')177 def test_authentication_with_invalid_password(self):178 """User's token with invalid password should not be authenticated"""179 self.data.setup_test_user()180 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,181 self.data.test_user, 'junkpass1234',182 self.data.test_tenant)183 @attr(type='positive')184 def test_authentication_request_without_token(self):185 """Request for token authentication with a valid token in header"""186 self.data.setup_test_user()187 self.token_client.auth(self.data.test_user, self.data.test_password,188 self.data.test_tenant)189 # Get the token of the current client190 token = self.client.get_auth()191 # Delete the token from database192 self.client.delete_token(token)193 # Re-auth194 resp, body = self.token_client.auth(self.data.test_user,195 self.data.test_password,196 self.data.test_tenant)197 self.assertEqual('200', resp['status'])198 self.client.clear_auth()199 @attr(type='smoke')200 def test_get_users(self):201 """Get a list of users and find the test user"""202 self.data.setup_test_user()203 resp, users = self.client.get_users()204 self.assertIn(self.data.test_user, [u['name'] for u in users],205 "Could not find %s" % self.data.test_user)206 @attr(type='negative')207 def test_get_users_by_unauthorized_user(self):208 """Non admin user should not be authorized to get user list"""209 self.data.setup_test_user()210 self.assertRaises(exceptions.Unauthorized,211 self.non_admin_client.get_users)212 @attr(type='negative')213 def test_get_users_request_without_token(self):214 """Request to get list of users without a valid token should fail"""215 token = self.client.get_auth()216 self.client.delete_token(token)217 self.assertRaises(exceptions.Unauthorized, self.client.get_users)218 self.client.clear_auth()219 @attr(type='positive')220 def test_list_users_for_tenant(self):221 """Return a list of all users for a tenant"""222 self.data.setup_test_tenant()223 user_ids = list()224 fetched_user_ids = list()225 resp, user1 = self.client.create_user('tenant_user1', 'password1',226 self.data.tenant['id'],227 'user1@123')228 user_ids.append(user1['id'])229 self.data.users.append(user1)230 resp, user2 = self.client.create_user('tenant_user2', 'password2',231 self.data.tenant['id'],232 'user2@123')233 user_ids.append(user2['id'])234 self.data.users.append(user2)235 #List of users for the respective tenant ID236 resp, body = self.client.list_users_for_tenant(self.data.tenant['id'])...

Full Screen

Full Screen

test_projects_rbac.py

Source:test_projects_rbac.py Github

copy

Full Screen

...26 """Create Project Test27 RBAC test for Identity 2.0 create_tenant28 """29 self.rbac_utils.switch_role(self, toggle_rbac_role=True)30 self.setup_test_tenant()31 @rbac_rule_validation.action(service="keystone",32 admin_only=True)33 @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d905')34 def test_update_project(self):35 """Update Project Test36 RBAC test for Identity 2.0 update_tenant37 """38 tenant = self.setup_test_tenant()39 self.rbac_utils.switch_role(self, toggle_rbac_role=True)40 self.tenants_client.update_tenant(tenant['id'],41 description="Changed description")42 @rbac_rule_validation.action(service="keystone",43 admin_only=True)44 @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d906')45 def test_delete_project(self):46 """Delete Project Test47 RBAC test for Identity 2.0 delete_tenant48 """49 tenant = self.setup_test_tenant()50 self.rbac_utils.switch_role(self, toggle_rbac_role=True)51 self.tenants_client.delete_tenant(tenant['id'])52 @rbac_rule_validation.action(service="keystone",53 admin_only=True)54 @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d907')55 def test_get_project(self):56 """Get Project Test57 RBAC test for Identity 2.0 show_tenant58 """59 tenant = self.setup_test_tenant()60 self.rbac_utils.switch_role(self, toggle_rbac_role=True)61 self.tenants_client.show_tenant(tenant['id'])62 @rbac_rule_validation.action(service="keystone",63 admin_only=True)64 @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d909')65 def test_list_project_users(self):66 """Get Users of a Project Test67 RBAC test for Identity 2.0 list_tenant_users68 """69 tenant = self.setup_test_tenant()70 self.rbac_utils.switch_role(self, toggle_rbac_role=True)71 self.tenants_client.list_tenant_users(tenant['id'])72 @rbac_rule_validation.action(service="keystone",73 admin_only=True)74 @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d908')75 def test_list_all_projects(self):76 """List All Projects Test77 RBAC test for Identity 2.0 list_tenants (admin endpoint)78 There are two separate APIs for listing tenants in the Keystone79 v2 API: one for admin and one for non-admin. The ``os_admin`` client80 calls the admin endpoint and the ``os_primary`` client calls the81 non-admin endpoint. To ensure that the admin endpoint only returns82 admin-scoped tenants, raise ``RbacActionFailed`` exception otherwise.83 """...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful