How to use create_user_ec2_credential method in tempest

Best Python code snippet using tempest_python

test_ec2_credential.py

Source:test_ec2_credential.py Github

copy

Full Screen

...151 user_id=user_id, access=resp['access'])152 def test_identity_ec2_get_credential(self):153 # user can get their own credential154 user_id = self.persona.credentials.user_id155 cred = self.admin_credentials_client.create_user_ec2_credential(156 user_id=user_id,157 **self.ec2_credential(project_id=self.test_project_1)158 )['credential']159 self.addCleanup(160 self.admin_credentials_client.delete_user_ec2_credential,161 user_id=user_id, access=cred['access'])162 self.do_request('show_user_ec2_credential',163 user_id=user_id, access=cred['access'])164 # user can get credential for other user165 cred = self.admin_credentials_client.create_user_ec2_credential(166 user_id=self.test_user_2,167 **self.ec2_credential(project_id=self.test_project_2)168 )['credential']169 self.addCleanup(170 self.admin_credentials_client.delete_user_ec2_credential,171 user_id=self.test_user_2, access=cred['access'])172 self.do_request('show_user_ec2_credential',173 user_id=self.test_user_2, access=cred['access'])174 # non-existent credential is Not Found175 self.do_request(176 'show_user_ec2_credential',177 expected_status=exceptions.NotFound,178 user_id=self.test_user_2,179 access=data_utils.rand_uuid_hex())180 def test_identity_ec2_list_credentials(self):181 # user can list their own credentials182 user_id = self.persona.credentials.user_id183 cred = self.admin_credentials_client.create_user_ec2_credential(184 user_id=user_id,185 **self.ec2_credential(project_id=self.test_project_1)186 )['credential']187 self.addCleanup(188 self.admin_credentials_client.delete_user_ec2_credential,189 user_id=user_id, access=cred['access'])190 resp = self.do_request('list_user_ec2_credentials',191 user_id=user_id)['credentials']192 self.assertIn(cred['access'], [c['access'] for c in resp])193 # user can list credentials for other user194 cred = self.admin_credentials_client.create_user_ec2_credential(195 user_id=self.test_user_2,196 **self.ec2_credential(project_id=self.test_project_2)197 )['credential']198 self.addCleanup(199 self.admin_credentials_client.delete_user_ec2_credential,200 user_id=self.test_user_2, access=cred['access'])201 resp = self.do_request('list_user_ec2_credentials',202 user_id=self.test_user_2)['credentials']203 self.assertIn(cred['access'], [c['access'] for c in resp])204 def test_identity_ec2_delete_credential(self):205 # user can delete their own credential206 user_id = self.persona.credentials.user_id207 cred = self.admin_credentials_client.create_user_ec2_credential(208 user_id=user_id,209 **self.ec2_credential(project_id=self.test_project_1)210 )['credential']211 self.do_request(212 'delete_user_ec2_credential',213 expected_status=204,214 user_id=user_id, access=cred['access'])215 # user can delete another user's credential216 cred = self.admin_credentials_client.create_user_ec2_credential(217 user_id=self.test_user_2,218 **self.ec2_credential(project_id=self.test_project_2)219 )['credential']220 self.do_request(221 'delete_user_ec2_credential',222 expected_status=204,223 user_id=self.test_user_2, access=cred['access'])224 # non-existent credential is Not Found225 self.do_request(226 'delete_user_ec2_credential',227 expected_status=exceptions.NotFound,228 user_id=self.test_user_2,229 access=data_utils.rand_uuid_hex())230class SystemMemberTests(SystemAdminTests):231 credentials = ['system_member', 'system_admin']232 def test_identity_ec2_create_credential(self):233 # user can create their own credential234 user_id = self.persona.credentials.user_id235 resp = self.do_request(236 'create_user_ec2_credential',237 expected_status=201,238 user_id=user_id,239 **self.ec2_credential(project_id=self.test_project_1)240 )['credential']241 self.addCleanup(self.client.delete_user_ec2_credential,242 user_id=user_id, access=resp['access'])243 # user cannot create credential for other user244 self.do_request(245 'create_user_ec2_credential',246 expected_status=exceptions.Forbidden,247 user_id=self.test_user_2,248 **self.ec2_credential(project_id=self.test_project_2))249 def test_identity_ec2_delete_credential(self):250 # user can delete their own credential251 user_id = self.persona.credentials.user_id252 cred = self.admin_credentials_client.create_user_ec2_credential(253 user_id=user_id,254 **self.ec2_credential(project_id=self.test_project_1)255 )['credential']256 self.do_request(257 'delete_user_ec2_credential',258 expected_status=204,259 user_id=user_id, access=cred['access'])260 # user cannot delete another user's credential261 cred = self.admin_credentials_client.create_user_ec2_credential(262 user_id=self.test_user_2,263 **self.ec2_credential(project_id=self.test_project_2)264 )['credential']265 self.addCleanup(266 self.admin_credentials_client.delete_user_ec2_credential,267 user_id=self.test_user_2, access=cred['access'])268 self.do_request(269 'delete_user_ec2_credential',270 expected_status=exceptions.Forbidden,271 user_id=self.test_user_2, access=cred['access'])272 # non-existent credential is Not Found273 self.do_request(274 'delete_user_ec2_credential',275 expected_status=exceptions.NotFound,276 user_id=self.test_user_2,277 access=data_utils.rand_uuid_hex())278class SystemReaderTests(SystemMemberTests):279 credentials = ['system_reader', 'system_admin']280class DomainAdminTests(IdentityV3RbacEc2CredentialTest, base.BaseIdentityTest):281 credentials = ['domain_admin', 'system_admin']282 def test_identity_ec2_create_credential(self):283 # user cannot create their own credential284 user_id = self.persona.credentials.user_id285 self.do_request(286 'create_user_ec2_credential',287 expected_status=exceptions.Forbidden,288 user_id=user_id,289 **self.ec2_credential(project_id=self.test_project_1))290 # user cannot create credential for user in own domain291 self.do_request(292 'create_user_ec2_credential',293 expected_status=exceptions.Forbidden,294 user_id=self.test_user_1,295 **self.ec2_credential(project_id=self.test_project_1))296 # user cannot create credential for other user297 self.do_request(298 'create_user_ec2_credential',299 expected_status=exceptions.Forbidden,300 user_id=self.test_user_2,301 **self.ec2_credential(project_id=self.test_project_2))302 def test_identity_ec2_get_credential(self):303 # user cannot get their own credential304 user_id = self.persona.credentials.user_id305 cred = self.admin_credentials_client.create_user_ec2_credential(306 user_id=user_id,307 **self.ec2_credential(project_id=self.test_project_1)308 )['credential']309 self.addCleanup(310 self.admin_credentials_client.delete_user_ec2_credential,311 user_id=user_id, access=cred['access'])312 self.do_request('show_user_ec2_credential',313 expected_status=exceptions.Forbidden,314 user_id=user_id, access=cred['access'])315 # user cannot get credential for user in own domain316 cred = self.admin_credentials_client.create_user_ec2_credential(317 user_id=self.test_user_1,318 **self.ec2_credential(project_id=self.test_project_1)319 )['credential']320 self.addCleanup(321 self.admin_credentials_client.delete_user_ec2_credential,322 user_id=self.test_user_1, access=cred['access'])323 self.do_request('show_user_ec2_credential',324 expected_status=exceptions.Forbidden,325 user_id=self.test_user_2, access=cred['access'])326 # user cannot get credential for other user327 cred = self.admin_credentials_client.create_user_ec2_credential(328 user_id=self.test_user_2,329 **self.ec2_credential(project_id=self.test_project_2)330 )['credential']331 self.addCleanup(332 self.admin_credentials_client.delete_user_ec2_credential,333 user_id=self.test_user_2, access=cred['access'])334 self.do_request('show_user_ec2_credential',335 expected_status=exceptions.Forbidden,336 user_id=self.test_user_2, access=cred['access'])337 # non-existent credential is Not Found338 self.do_request(339 'show_user_ec2_credential',340 expected_status=exceptions.NotFound,341 user_id=self.test_user_2,342 access=data_utils.rand_uuid_hex())343 def test_identity_ec2_list_credentials(self):344 # user cannot list their own credentials345 user_id = self.persona.credentials.user_id346 cred = self.admin_credentials_client.create_user_ec2_credential(347 user_id=user_id,348 **self.ec2_credential(project_id=self.test_project_1)349 )['credential']350 self.addCleanup(351 self.admin_credentials_client.delete_user_ec2_credential,352 user_id=user_id, access=cred['access'])353 self.do_request('list_user_ec2_credentials',354 expected_status=exceptions.Forbidden,355 user_id=user_id)356 # user cannot list credentials for user in own domain357 cred = self.admin_credentials_client.create_user_ec2_credential(358 user_id=self.test_user_1,359 **self.ec2_credential(project_id=self.test_project_1)360 )['credential']361 self.addCleanup(362 self.admin_credentials_client.delete_user_ec2_credential,363 user_id=self.test_user_1, access=cred['access'])364 self.do_request('list_user_ec2_credentials',365 expected_status=exceptions.Forbidden,366 user_id=self.test_user_1)367 # user cannot list credentials for other user368 cred = self.admin_credentials_client.create_user_ec2_credential(369 user_id=self.test_user_2,370 **self.ec2_credential(project_id=self.test_project_2)371 )['credential']372 self.addCleanup(373 self.admin_credentials_client.delete_user_ec2_credential,374 user_id=self.test_user_2, access=cred['access'])375 self.do_request('list_user_ec2_credentials',376 expected_status=exceptions.Forbidden,377 user_id=self.test_user_2)378 def test_identity_ec2_delete_credential(self):379 # user cannot delete their own credential380 user_id = self.persona.credentials.user_id381 cred = self.admin_credentials_client.create_user_ec2_credential(382 user_id=user_id,383 **self.ec2_credential(project_id=self.test_project_1)384 )['credential']385 self.addCleanup(386 self.admin_credentials_client.delete_user_ec2_credential,387 user_id=user_id, access=cred['access'])388 self.do_request(389 'delete_user_ec2_credential',390 expected_status=exceptions.Forbidden,391 user_id=user_id, access=cred['access'])392 # user cannot delete credential for user in own domain393 cred = self.admin_credentials_client.create_user_ec2_credential(394 user_id=self.test_user_1,395 **self.ec2_credential(project_id=self.test_project_1)396 )['credential']397 self.addCleanup(398 self.admin_credentials_client.delete_user_ec2_credential,399 user_id=self.test_user_1, access=cred['access'])400 self.do_request(401 'delete_user_ec2_credential',402 expected_status=exceptions.Forbidden,403 user_id=self.test_user_1, access=cred['access'])404 # user cannot delete another user's credential405 cred = self.admin_credentials_client.create_user_ec2_credential(406 user_id=self.test_user_2,407 **self.ec2_credential(project_id=self.test_project_2)408 )['credential']409 self.addCleanup(410 self.admin_credentials_client.delete_user_ec2_credential,411 user_id=self.test_user_2, access=cred['access'])412 self.do_request(413 'delete_user_ec2_credential',414 expected_status=exceptions.Forbidden,415 user_id=self.test_user_2, access=cred['access'])416 # non-existent credential is Not Found417 self.do_request(418 'delete_user_ec2_credential',419 expected_status=exceptions.NotFound,420 user_id=self.test_user_2,421 access=data_utils.rand_uuid_hex())422class DomainMemberTests(DomainAdminTests):423 credentials = ['domain_member', 'system_admin']424class DomainReaderTests(DomainAdminTests):425 credentials = ['domain_reader', 'system_admin']426class ProjectAdminTests(SystemReaderTests):427 credentials = ['project_admin', 'system_admin']428 def test_identity_ec2_get_credential(self):429 # user can get their own credential430 user_id = self.persona.credentials.user_id431 cred = self.admin_credentials_client.create_user_ec2_credential(432 user_id=user_id,433 **self.ec2_credential(project_id=self.test_project_1)434 )['credential']435 self.addCleanup(436 self.admin_credentials_client.delete_user_ec2_credential,437 user_id=user_id, access=cred['access'])438 self.do_request('show_user_ec2_credential',439 user_id=user_id, access=cred['access'])440 # user cannot get credential for other user441 cred = self.admin_credentials_client.create_user_ec2_credential(442 user_id=self.test_user_2,443 **self.ec2_credential(project_id=self.test_project_2)444 )['credential']445 self.addCleanup(446 self.admin_credentials_client.delete_user_ec2_credential,447 user_id=self.test_user_2, access=cred['access'])448 self.do_request('show_user_ec2_credential',449 expected_status=exceptions.Forbidden,450 user_id=self.test_user_2, access=cred['access'])451 # non-existent credential is Not Found452 self.do_request(453 'show_user_ec2_credential',454 expected_status=exceptions.NotFound,455 user_id=self.test_user_2,456 access=data_utils.rand_uuid_hex())457 def test_identity_ec2_list_credentials(self):458 # user can list their own credentials459 user_id = self.persona.credentials.user_id460 cred = self.admin_credentials_client.create_user_ec2_credential(461 user_id=user_id,462 **self.ec2_credential(project_id=self.test_project_1)463 )['credential']464 self.addCleanup(465 self.admin_credentials_client.delete_user_ec2_credential,466 user_id=user_id, access=cred['access'])467 resp = self.do_request('list_user_ec2_credentials',468 user_id=user_id)['credentials']469 self.assertIn(cred['access'], [c['access'] for c in resp])470 # user cannot list credentials for other user471 cred = self.admin_credentials_client.create_user_ec2_credential(472 user_id=self.test_user_2,473 **self.ec2_credential(project_id=self.test_project_2)474 )['credential']475 self.addCleanup(476 self.admin_credentials_client.delete_user_ec2_credential,477 user_id=self.test_user_2, access=cred['access'])478 self.do_request('list_user_ec2_credentials',479 expected_status=exceptions.Forbidden,480 user_id=self.test_user_2)481class ProjectMemberTests(ProjectAdminTests):482 credentials = ['project_member', 'system_admin']483class ProjectReaderTests(ProjectAdminTests):...

Full Screen

Full Screen

test_ec2_credentials.py

Source:test_ec2_credentials.py Github

copy

Full Screen

...29 cls.creds = cls.os_primary.credentials30 @decorators.idempotent_id('b580fab9-7ae9-46e8-8138-417260cb6f9f')31 def test_create_ec2_credential(self):32 """Create user ec2 credential."""33 resp = self.non_admin_users_client.create_user_ec2_credential(34 self.creds.user_id,35 tenant_id=self.creds.tenant_id)["credential"]36 access = resp['access']37 self.addCleanup(38 self.non_admin_users_client.delete_user_ec2_credential,39 self.creds.user_id, access)40 self.assertNotEmpty(resp['access'])41 self.assertNotEmpty(resp['secret'])42 self.assertEqual(self.creds.user_id, resp['user_id'])43 self.assertEqual(self.creds.tenant_id, resp['tenant_id'])44 @decorators.idempotent_id('9e2ea42f-0a4f-468c-a768-51859ce492e0')45 def test_list_ec2_credentials(self):46 """Get the list of user ec2 credentials."""47 created_creds = []48 # create first ec2 credentials49 creds1 = self.non_admin_users_client.create_user_ec2_credential(50 self.creds.user_id,51 tenant_id=self.creds.tenant_id)["credential"]52 created_creds.append(creds1['access'])53 self.addCleanup(54 self.non_admin_users_client.delete_user_ec2_credential,55 self.creds.user_id, creds1['access'])56 # create second ec2 credentials57 creds2 = self.non_admin_users_client.create_user_ec2_credential(58 self.creds.user_id,59 tenant_id=self.creds.tenant_id)["credential"]60 created_creds.append(creds2['access'])61 self.addCleanup(62 self.non_admin_users_client.delete_user_ec2_credential,63 self.creds.user_id, creds2['access'])64 # get the list of user ec2 credentials65 resp = self.non_admin_users_client.list_user_ec2_credentials(66 self.creds.user_id)["credentials"]67 fetched_creds = [cred['access'] for cred in resp]68 # created credentials should be in a fetched list69 missing = [cred for cred in created_creds70 if cred not in fetched_creds]71 self.assertEmpty(missing,72 "Failed to find ec2_credentials %s in fetched list" %73 ', '.join(cred for cred in missing))74 @decorators.idempotent_id('cb284075-b613-440d-83ca-fe0b33b3c2b8')75 def test_show_ec2_credential(self):76 """Get the definite user ec2 credential."""77 resp = self.non_admin_users_client.create_user_ec2_credential(78 self.creds.user_id,79 tenant_id=self.creds.tenant_id)["credential"]80 self.addCleanup(81 self.non_admin_users_client.delete_user_ec2_credential,82 self.creds.user_id, resp['access'])83 ec2_creds = self.non_admin_users_client.show_user_ec2_credential(84 self.creds.user_id, resp['access']85 )["credential"]86 for key in ['access', 'secret', 'user_id', 'tenant_id']:87 self.assertEqual(ec2_creds[key], resp[key])88 @decorators.idempotent_id('6aba0d4c-b76b-4e46-aa42-add79bc1551d')89 def test_delete_ec2_credential(self):90 """Delete user ec2 credential."""91 resp = self.non_admin_users_client.create_user_ec2_credential(92 self.creds.user_id,93 tenant_id=self.creds.tenant_id)["credential"]94 access = resp['access']95 self.non_admin_users_client.delete_user_ec2_credential(96 self.creds.user_id, access)97 self.assertRaises(98 lib_exc.NotFound,99 self.non_admin_users_client.show_user_ec2_credential,100 self.creds.user_id,...

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