Best Python code snippet using tempest_python
test_credential.py
Source:test_credential.py
...84 'user_id': user_id,85 }86 return cred87 @abc.abstractmethod88 def test_identity_create_credential(self):89 """Test identity:create_credential policy.90 This test must check:91 * whether the persona can create a credential for themself92 * whether the persona can create acredential for another user in93 their own domain94 * whether the persona can create acredential for another user in95 another domain96 """97 pass98 @abc.abstractmethod99 def test_identity_get_credential(self):100 """Test identity:get_credential policy.101 This test must check:102 * whether the persona can get their own credential103 * whether the persona can get a credential for a user in another104 domain105 * whether the persona can get a credential for a user in their own106 domain107 * whether the persona can get a credential that does not exist108 """109 pass110 @abc.abstractmethod111 def test_identity_list_credentials(self):112 """Test identity:list_credentials policy.113 This test must check:114 * whether the persona can list all credentials for themself115 * whether the persona can list credentials for a user in their own116 domain117 * whether the persona can list credentials for a user in another118 domain119 """120 pass121 @abc.abstractmethod122 def test_identity_update_credential(self):123 """Test identity:update_credential policy.124 This test must check:125 * whether the persona can update their own credential126 * whether the persona can update a credential for a user in another127 domain128 * whether the persona can update a credential for a user in their own129 domain130 * whether the persona can update a credential that does not exist131 """132 pass133 @abc.abstractmethod134 def test_identity_delete_credential(self):135 """Test identity:delete_credential policy.136 This test must check137 * whether the persona can delete their own credential138 * whether the persona can delete a credential for a user in another139 domain140 * whether the persona can delete a credential for a user in their own141 domain142 * whether the persona can delete a credential that does not exist143 """144 pass145class SystemAdminTests(IdentityV3RbacCredentialTest, base.BaseIdentityTest):146 credentials = ['system_admin']147 def test_identity_create_credential(self):148 # user can create their own credential149 user_id = self.persona.credentials.user_id150 resp = self.do_request(151 'create_credential',152 expected_status=201,153 **self.credential(user_id=user_id))['credential']154 self.addCleanup(self.client.delete_credential, resp['id'])155 # user can create credential for other user in own domain156 resp = self.do_request(157 'create_credential',158 expected_status=201,159 **self.credential(user_id=self.test_user_1))['credential']160 self.addCleanup(self.client.delete_credential, resp['id'])161 # user can create credential for other user in other domain162 resp = self.do_request(163 'create_credential',164 expected_status=201,165 **self.credential(user_id=self.test_user_2))['credential']166 self.addCleanup(self.client.delete_credential, resp['id'])167 def test_identity_get_credential(self):168 # user can get their own credential, credential for user in own domain,169 # or credential for user in other domain170 user_id = self.persona.credentials.user_id171 for u in [user_id, self.test_user_1, self.test_user_2]:172 cred = self.admin_credentials_client.create_credential(173 **self.credential(user_id=u))['credential']174 self.addCleanup(175 self.admin_credentials_client.delete_credential, cred['id'])176 self.do_request('show_credential', credential_id=cred['id'])177 # non-existent credential is Not Found178 self.do_request(179 'show_credential',180 expected_status=exceptions.NotFound,181 credential_id=data_utils.rand_uuid_hex())182 def test_identity_list_credentials(self):183 # user can list their own credentials, credentials for user in own184 # domain, or credentials for user in other domain185 user_id = self.persona.credentials.user_id186 for u in [user_id, self.test_user_1, self.test_user_2]:187 cred = self.admin_credentials_client.create_credential(188 **self.credential(user_id=u))['credential']189 self.addCleanup(190 self.admin_credentials_client.delete_credential, cred['id'])191 resp = self.do_request('list_credentials')['credentials']192 self.assertIn(cred['id'], [c['id'] for c in resp])193 def test_identity_update_credential(self):194 # user can update their own credential, credential for user in own195 # domain, or credential for user in other domain196 user_id = self.persona.credentials.user_id197 for u in [user_id, self.test_user_1, self.test_user_2]:198 cred = self.credential(user_id=u)199 resp = self.client.create_credential(**cred)['credential']200 self.addCleanup(self.client.delete_credential, resp['id'])201 cred['blob'] = data_utils.rand_uuid_hex()202 self.do_request(203 'update_credential', credential_id=resp['id'], **cred)204 # non-existent credential is Not Found205 self.do_request(206 'update_credential',207 expected_status=exceptions.NotFound,208 credential_id=data_utils.rand_uuid_hex(),209 **self.credential(user_id=self.test_user_2))210 def test_identity_delete_credential(self):211 # user can delete their own credential, credential for user in own212 # domain, or credential for user in other domain213 user_id = self.persona.credentials.user_id214 for u in [user_id, self.test_user_1, self.test_user_2]:215 cred = self.credential(user_id=u)216 resp = self.client.create_credential(**cred)['credential']217 self.do_request(218 'delete_credential',219 expected_status=204,220 credential_id=resp['id'])221 # non-existent credential is Not Found222 self.do_request(223 'delete_credential',224 expected_status=exceptions.NotFound,225 credential_id=data_utils.rand_uuid_hex())226class SystemMemberTests(SystemAdminTests):227 credentials = ['system_member', 'system_admin']228 def test_identity_create_credential(self):229 # user can create their own credential230 user_id = self.persona.credentials.user_id231 resp = self.do_request(232 'create_credential',233 expected_status=201,234 **self.credential(user_id=user_id))['credential']235 self.addCleanup(self.client.delete_credential, resp['id'])236 # user cannot create credential for other user237 for u in [self.test_user_1, self.test_user_2]:238 self.do_request(239 'create_credential',240 expected_status=exceptions.Forbidden,241 **self.credential(user_id=u))242 def test_identity_update_credential(self):243 # user can update their own credential244 user_id = self.persona.credentials.user_id245 cred = self.credential(user_id=user_id)246 resp = self.admin_credentials_client.create_credential(247 **cred)['credential']248 self.addCleanup(249 self.admin_credentials_client.delete_credential, resp['id'])250 cred['blob'] = data_utils.rand_uuid_hex()251 self.do_request(252 'update_credential',253 credential_id=resp['id'], **cred)254 # user cannot update credential for other user255 for u in [self.test_user_1, self.test_user_2]:256 cred = self.credential(user_id=u)257 resp = self.admin_credentials_client.create_credential(258 **cred)['credential']259 self.addCleanup(260 self.admin_credentials_client.delete_credential, resp['id'])261 cred['blob'] = data_utils.rand_uuid_hex()262 self.do_request(263 'update_credential',264 expected_status=exceptions.Forbidden,265 credential_id=resp['id'], **cred)266 # non-existent credential is Forbidden267 self.do_request(268 'update_credential',269 expected_status=exceptions.Forbidden,270 credential_id=data_utils.rand_uuid_hex(),271 **self.credential(user_id=self.test_user_2))272 def test_identity_delete_credential(self):273 # user can delete their own credential274 user_id = self.persona.credentials.user_id275 cred = self.credential(user_id=user_id)276 resp = self.admin_credentials_client.create_credential(277 **cred)['credential']278 self.do_request(279 'delete_credential',280 expected_status=204,281 credential_id=resp['id'])282 # user cannot delete credential for other user283 for u in [self.test_user_1, self.test_user_2]:284 cred = self.credential(user_id=u)285 resp = self.admin_credentials_client.create_credential(286 **cred)['credential']287 self.addCleanup(288 self.admin_credentials_client.delete_credential, resp['id'])289 self.do_request(290 'delete_credential',291 expected_status=exceptions.Forbidden,292 credential_id=resp['id'])293 # non-existent credential is Forbidden294 self.do_request(295 'delete_credential',296 expected_status=exceptions.Forbidden,297 credential_id=data_utils.rand_uuid_hex())298class SystemReaderTests(SystemMemberTests):299 credentials = ['system_reader', 'system_admin']300class DomainAdminTests(IdentityV3RbacCredentialTest, base.BaseIdentityTest):301 credentials = ['domain_admin', 'system_admin']302 def test_identity_create_credential(self):303 # domain admins cannot create credentials304 user_id = self.persona.credentials.user_id305 for u in [user_id, self.test_user_1, self.test_user_2]:306 self.do_request(307 'create_credential',308 expected_status=exceptions.Forbidden,309 **self.credential(user_id=u))310 def test_identity_get_credential(self):311 # domain admins cannot get credentials312 user_id = self.persona.credentials.user_id313 for u in [user_id, self.test_user_1, self.test_user_2]:314 cred = self.admin_credentials_client.create_credential(315 **self.credential(user_id=u))['credential']316 self.addCleanup(317 self.admin_credentials_client.delete_credential, cred['id'])318 self.do_request(319 'show_credential',320 expected_status=exceptions.Forbidden,321 credential_id=cred['id'])322 # non-existent credential is Forbidden323 self.do_request(324 'show_credential',325 expected_status=exceptions.Forbidden,326 credential_id=data_utils.rand_uuid_hex())327 def test_identity_list_credentials(self):328 # domain admins cannot list credentials329 user_id = self.persona.credentials.user_id330 for u in [user_id, self.test_user_1, self.test_user_2]:331 cred = self.admin_credentials_client.create_credential(332 **self.credential(user_id=u))['credential']333 self.addCleanup(334 self.admin_credentials_client.delete_credential, cred['id'])335 self.do_request(336 'list_credentials',337 expected_status=exceptions.Forbidden)338 def test_identity_update_credential(self):339 # domain admins cannot update credentials340 user_id = self.persona.credentials.user_id341 for u in [user_id, self.test_user_1, self.test_user_2]:342 cred = self.credential(user_id=u)343 resp = self.admin_credentials_client.create_credential(344 **cred)['credential']345 self.addCleanup(346 self.admin_credentials_client.delete_credential, resp['id'])347 cred['blob'] = data_utils.rand_uuid_hex()348 self.do_request(349 'update_credential',350 expected_status=exceptions.Forbidden,351 credential_id=resp['id'], **cred)352 # non-existent credential is Forbidden353 self.do_request(354 'update_credential',355 expected_status=exceptions.Forbidden,356 credential_id=data_utils.rand_uuid_hex(),357 **self.credential(user_id=user_id))358 def test_identity_delete_credential(self):359 # domain admins cannot delete credentials360 user_id = self.persona.credentials.user_id361 for u in [user_id, self.test_user_1, self.test_user_2]:362 cred = self.credential(user_id=u)363 resp = self.admin_credentials_client.create_credential(364 **cred)['credential']365 self.addCleanup(366 self.admin_credentials_client.delete_credential, resp['id'])367 self.do_request(368 'delete_credential',369 expected_status=exceptions.Forbidden,370 credential_id=resp['id'])371 # non-existent credential is Forbidden372 self.do_request(373 'delete_credential',374 expected_status=exceptions.Forbidden,375 credential_id=data_utils.rand_uuid_hex())376class DomainMemberTests(DomainAdminTests):377 credentials = ['domain_member', 'system_admin']378class DomainReaderTests(DomainAdminTests):379 credentials = ['domain_reader', 'system_admin']380class ProjectAdminTests(SystemReaderTests):381 credentials = ['project_admin', 'system_admin']382 def test_identity_get_credential(self):383 # user can get their own credential384 user_id = self.persona.credentials.user_id385 cred = self.admin_credentials_client.create_credential(386 **self.credential(user_id=user_id))['credential']387 self.addCleanup(388 self.admin_credentials_client.delete_credential, cred['id'])389 self.do_request('show_credential', credential_id=cred['id'])390 # user cannot get credential for another user391 for u in [self.test_user_1, self.test_user_2]:392 cred = self.admin_credentials_client.create_credential(393 **self.credential(user_id=u))['credential']394 self.addCleanup(395 self.admin_credentials_client.delete_credential, cred['id'])396 self.do_request(397 'show_credential',398 expected_status=exceptions.Forbidden,399 credential_id=cred['id'])400 # non-existent credential is Forbidden401 self.do_request(402 'show_credential',403 expected_status=exceptions.Forbidden,404 credential_id=data_utils.rand_uuid_hex())405 def test_identity_list_credentials(self):406 # user can list their own credentials407 user_id = self.persona.credentials.user_id408 cred = self.admin_credentials_client.create_credential(409 **self.credential(user_id=user_id))['credential']410 self.addCleanup(411 self.admin_credentials_client.delete_credential, cred['id'])412 resp = self.do_request('list_credentials')['credentials']413 self.assertIn(cred['id'], [c['id'] for c in resp])414 # user cannot list credentials for other users415 for u in [self.test_user_1, self.test_user_2]:416 cred = self.admin_credentials_client.create_credential(417 **self.credential(user_id=u))['credential']418 self.addCleanup(419 self.admin_credentials_client.delete_credential, cred['id'])420 resp = self.do_request('list_credentials')['credentials']421 self.assertNotIn(cred['id'], [c['id'] for c in resp])422class ProjectMemberTests(ProjectAdminTests):423 credentials = ['project_member', 'system_admin']424class ProjectReaderTests(ProjectAdminTests):...
test_domain.py
Source:test_domain.py
...30 assert account.proof_of_address_date_2 == date_231@pytest.mark.django_db32class TestCredentialCreation:33 def test_consecutive_s3_filename_generation(self, account):34 cred1 = create_credential(account, 'awesome.jpg', 'normal')35 cred2 = create_credential(account, 'sexy.jpg', 'normal')36 assert cred1.s3_key == 'normal_12345678_1.jpg'37 assert cred2.s3_key == 'normal_12345678_2.jpg'38 def test_consecutive_s3_filename_generation_for_priority(self, account):39 cred1 = create_credential(account, 'awesome.jpg', 'priority')40 cred2 = create_credential(account, 'sexy.jpg', 'priority')41 assert cred1.s3_key == 'priority_12345678_1.jpg'42 assert cred2.s3_key == 'priority_12345678_2.jpg'43 def test_marked_as_blocked_if_blocked_extension(self, account):44 cred = create_credential(account, 'awesome.exe', 'normal')45 assert cred.is_blocked is True46class TestPreseignedS3UrlGeneration:47 @patch('idv.common.aws.generate_presigned_s3_url')48 def test_parameters(self, generation_func_mock, settings):49 assert generate_presigned_s3_put_url('cat', 'json', 'X') is not None50 generation_func_mock.assert_called_once_with(51 'put_object', 'BUCK', 'cat', ContentType='json',52 ContentMD5='X')53 def test_no_settings_returns_none(self, settings):54 settings.S3_BUCKET = None55 assert generate_presigned_s3_put_url('cooking', 'json', 'X') is None56@pytest.mark.django_db57class TestWhitelistedExtensions:58 def test_whitelisted_lowercase_extension(self, account):59 cred = create_credential(account, 'file.jpg', 'normal')60 assert has_whitelisted_extension(cred) is True61 def test_whitelisted_mixedcase_extension(self, account):62 cred = create_credential(account, 'fILe.pNg', 'normal')63 assert has_whitelisted_extension(cred) is True64 def test_non_whitelisted_mixedcase_extension(self, account):65 cred = create_credential(account, 'file.exE', 'normal')66 assert has_whitelisted_extension(cred) is False67 def test_missing_extension(self, account):68 cred = create_credential(account, 'file', 'normal')...
credentials.py
Source:credentials.py
1from alertlogic.services import Credentials2import alertlogiccli.command3import requests4import json5class create_credential(alertlogiccli.command.Command):6 """Command to create credential in credential service"""7 def configure_parser(self, subparsers):8 parser = subparsers.add_parser("create_credential", help="Creates a credential")9 parser.set_defaults(command=self)10 parser.add_argument("--name", required=True, help="Credential name")11 parser.add_argument("--arn", required=True, help="")12 def execute(self, context):13 args = context.get_final_args()14 credentials = Credentials(context.get_session())15 try:16 response = credentials.create_credential(17 account_id=args["account_id"],18 name=args["name"],19 arn=args["arn"]20 )21 response.raise_for_status()22 except requests.exceptions.HTTPError as e:23 raise alertlogiccli.command.InvalidHTTPResponse("create_credential", e.message)24 return json.dumps(response.json(), sort_keys=True, separators=(',',':'))25class delete_credential():26 """Command to delete credential in credentials service"""27 def configure_parser(self, subparsers):28 parser = subparsers.add_parser("delete_credential", help="Deletes credential")29 parser.set_defaults(command=self)30 parser.add_argument("--credential_id", required=True, help="Credential id")...
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!!