Best Python code snippet using localstack_python
test_secretsmanager.py
Source:test_secretsmanager.py
...300 assert len(vs_in_res) == 1301 v_in_res = vs_in_res[0]302 assert v_in_res["VersionStages"] == version["VersionStages"]303 return res_json304 def secretsmanager_http_put_secret_value(305 self, secret_id: str, secret_string: str306 ) -> requests.Response:307 http_body: json = {308 "SecretId": secret_id,309 "SecretString": secret_string,310 }311 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)312 @staticmethod313 def secretsmanager_http_put_secret_value_val_res(314 res: requests.Response, secret_name: str315 ) -> json:316 assert res.status_code == 200317 res_json: json = res.json()318 assert res_json["Name"] == secret_name319 return res_json320 def secretsmanager_http_put_pending_secret_value(321 self, secret_id: str, secret_string: str322 ) -> requests.Response:323 http_body: json = {324 "SecretId": secret_id,325 "SecretString": secret_string,326 "VersionStages": ["AWSPENDING"],327 }328 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)329 @staticmethod330 def secretsmanager_http_put_pending_secret_value_val_res(331 res: requests.Response, secret_name: str332 ) -> json:333 return TestSecretsManager.secretsmanager_http_put_secret_value_val_res(res, secret_name)334 def secretsmanager_http_put_secret_value_with(335 self, secret_id: str, secret_string: str, client_request_token: Optional[str]336 ) -> requests.Response:337 http_body: json = {338 "SecretId": secret_id,339 "SecretString": secret_string,340 "ClientRequestToken": client_request_token,341 }342 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)343 @staticmethod344 def secretsmanager_http_put_secret_value_with_val_res(345 res: requests.Response, secret_name: str, client_request_token: str346 ) -> json:347 assert res.status_code == 200348 res_json: json = res.json()349 assert res_json["Name"] == secret_name350 assert res_json["VersionId"] == client_request_token351 return res_json352 def secretsmanager_http_put_secret_value_with_version(353 self,354 secret_id: str,355 secret_string: str,356 client_request_token: Optional[str],357 version_stages: [str],358 ) -> requests.Response:359 http_body: json = {360 "SecretId": secret_id,361 "SecretString": secret_string,362 "ClientRequestToken": client_request_token,363 "VersionStages": version_stages,364 }365 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)366 @staticmethod367 def secretsmanager_http_put_secret_value_with_version_val_res(368 res: requests.Response,369 secret_name: str,370 client_request_token: Optional[str],371 version_stages: [str],372 ) -> json:373 req_version_id: str374 if client_request_token is None:375 assert res.status_code == 200376 req_version_id = res.json()["VersionId"]377 else:378 req_version_id = client_request_token379 res_json = TestSecretsManager.secretsmanager_http_put_secret_value_with_val_res(380 res, secret_name, req_version_id381 )382 assert res_json["VersionStages"] == version_stages383 return res_json384 def test_http_put_secret_value_with_new_custom_client_request_token(self):385 secret_name: str = "test_http_put_secret_value_with_new_custom_client_request_token"386 # Create v0.387 secret_string_v0: str = "MySecretString"388 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(389 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),390 secret_name,391 )392 #393 # Check v0 base consistency.394 self.secretsmanager_http_get_secret_value_val_res(395 self.secretsmanager_http_get_secret_value(secret_name),396 secret_name,397 secret_string_v0,398 cr_v0_res_json["VersionId"],399 )400 # Update v0 with predefined ClientRequestToken.401 secret_string_v1: str = "MyNewSecretString"402 #403 crt_v1: str = str(uuid.uuid4())404 while crt_v1 == cr_v0_res_json["VersionId"]:405 crt_v1 = str(uuid.uuid4())406 #407 self.secretsmanager_http_put_secret_value_val_res(408 self.secretsmanager_http_put_secret_value_with(secret_name, secret_string_v1, crt_v1),409 secret_name,410 )411 #412 # Check v1 base consistency.413 self.secretsmanager_http_get_secret_value_val_res(414 self.secretsmanager_http_get_secret_value(secret_name),415 secret_name,416 secret_string_v1,417 crt_v1,418 )419 #420 # Check versioning base consistency.421 versions_v0_v1: json = [422 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSPREVIOUS"]},423 {"VersionId": crt_v1, "VersionStages": ["AWSCURRENT"]},424 ]425 self.secretsmanager_http_list_secret_version_ids_val_res(426 self.secretsmanager_http_list_secret_version_ids(secret_name),427 secret_name,428 versions_v0_v1,429 )430 self.secretsmanager_http_delete_secret_val_res(431 self.secretsmanager_http_delete_secret(secret_name), secret_name432 )433 def test_http_put_secret_value_with_duplicate_client_request_token(self):434 secret_name: str = "test_http_put_secret_value_with_duplicate_client_request_token"435 # Create v0.436 secret_string_v0: str = "MySecretString"437 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(438 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),439 secret_name,440 )441 #442 # Check v0 base consistency.443 self.secretsmanager_http_get_secret_value_val_res(444 self.secretsmanager_http_get_secret_value(secret_name),445 secret_name,446 secret_string_v0,447 cr_v0_res_json["VersionId"],448 )449 # Update v0 with duplicate ClientRequestToken.450 secret_string_v1: str = "MyNewSecretString"451 #452 crt_v1: str = cr_v0_res_json["VersionId"]453 #454 self.secretsmanager_http_put_secret_value_val_res(455 self.secretsmanager_http_put_secret_value_with(secret_name, secret_string_v1, crt_v1),456 secret_name,457 )458 #459 # Check v1 base consistency.460 self.secretsmanager_http_get_secret_value_val_res(461 self.secretsmanager_http_get_secret_value(secret_name),462 secret_name,463 secret_string_v1,464 crt_v1,465 )466 #467 # Check versioning base consistency.468 versions_v0_v1: json = [{"VersionId": crt_v1, "VersionStages": ["AWSCURRENT"]}]469 self.secretsmanager_http_list_secret_version_ids_val_res(470 self.secretsmanager_http_list_secret_version_ids(secret_name),471 secret_name,472 versions_v0_v1,473 )474 self.secretsmanager_http_delete_secret_val_res(475 self.secretsmanager_http_delete_secret(secret_name), secret_name476 )477 def test_http_put_secret_value_with_null_client_request_token(self):478 secret_name: str = "test_http_put_secret_value_with_null_client_request_token"479 # Create v0.480 secret_string_v0: str = "MySecretString"481 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(482 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),483 secret_name,484 )485 #486 # Check v0 base consistency.487 self.secretsmanager_http_get_secret_value_val_res(488 self.secretsmanager_http_get_secret_value(secret_name),489 secret_name,490 secret_string_v0,491 cr_v0_res_json["VersionId"],492 )493 # Update v0 with null ClientRequestToken.494 secret_string_v1: str = "MyNewSecretString"495 #496 pv_v1_res_json = self.secretsmanager_http_put_secret_value_val_res(497 self.secretsmanager_http_put_secret_value_with(secret_name, secret_string_v1, None),498 secret_name,499 )500 #501 # Check v1 base consistency.502 self.secretsmanager_http_get_secret_value_val_res(503 self.secretsmanager_http_get_secret_value(secret_name),504 secret_name,505 secret_string_v1,506 pv_v1_res_json["VersionId"],507 )508 #509 # Check versioning base consistency.510 versions_v0_v1: json = [511 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSPREVIOUS"]},512 {"VersionId": pv_v1_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},513 ]514 self.secretsmanager_http_list_secret_version_ids_val_res(515 self.secretsmanager_http_list_secret_version_ids(secret_name),516 secret_name,517 versions_v0_v1,518 )519 self.secretsmanager_http_delete_secret_val_res(520 self.secretsmanager_http_delete_secret(secret_name), secret_name521 )522 def test_http_put_secret_value_with_undefined_client_request_token(self):523 secret_name: str = "test_http_put_secret_value_with_undefined_client_request_token"524 # Create v0.525 secret_string_v0: str = "MySecretString"526 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(527 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),528 secret_name,529 )530 #531 # Check v0 base consistency.532 self.secretsmanager_http_get_secret_value_val_res(533 self.secretsmanager_http_get_secret_value(secret_name),534 secret_name,535 secret_string_v0,536 cr_v0_res_json["VersionId"],537 )538 # Update v0 with undefined ClientRequestToken.539 secret_string_v1: str = "MyNewSecretString"540 #541 pv_v1_res_json = self.secretsmanager_http_put_secret_value_val_res(542 self.secretsmanager_http_put_secret_value(secret_name, secret_string_v1), secret_name543 )544 #545 # Check v1 base consistency.546 self.secretsmanager_http_get_secret_value_val_res(547 self.secretsmanager_http_get_secret_value(secret_name),548 secret_name,549 secret_string_v1,550 pv_v1_res_json["VersionId"],551 )552 #553 # Check versioning base consistency.554 versions_v0_v1: json = [555 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSPREVIOUS"]},556 {"VersionId": pv_v1_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},...
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!!