Best Python code snippet using localstack_python
test_cloudformation_changesets.py
Source:test_cloudformation_changesets.py
...399 Capabilities=["CAPABILITY_AUTO_EXPAND", "CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"],400 ChangeSetType="CREATE",401 )402 snapshot.match("first_changeset", first_changeset)403 def _check_changeset_available():404 status = cfn_client.describe_change_set(405 StackName=stack_name, ChangeSetName=first_changeset["Id"]406 )["Status"]407 if status == "FAILED":408 raise ShortCircuitWaitException("Change set in unrecoverable status")409 return status == "CREATE_COMPLETE"410 assert wait_until(_check_changeset_available)411 describe_first_cs = cfn_client.describe_change_set(412 StackName=stack_name, ChangeSetName=first_changeset["Id"]413 )414 snapshot.match("describe_first_cs", describe_first_cs)415 assert describe_first_cs["ExecutionStatus"] == "AVAILABLE"416 cfn_client.execute_change_set(StackName=stack_name, ChangeSetName=first_changeset["Id"])417 def _check_changeset_success():418 status = cfn_client.describe_change_set(419 StackName=stack_name, ChangeSetName=first_changeset["Id"]420 )["ExecutionStatus"]421 if status in ["EXECUTE_FAILED", "UNAVAILABLE", "OBSOLETE"]:422 raise ShortCircuitWaitException("Change set in unrecoverable status")423 return status == "EXECUTE_COMPLETE"424 assert wait_until(_check_changeset_success)425 # 2. create a new change set without changes426 nochange_changeset = cfn_client.create_change_set(427 StackName=stack_name,428 ChangeSetName=change_set_name_nochange,429 TemplateBody=template,430 Capabilities=["CAPABILITY_AUTO_EXPAND", "CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"],431 ChangeSetType="UPDATE",432 )433 snapshot.match("nochange_changeset", nochange_changeset)434 describe_nochange = cfn_client.describe_change_set(435 StackName=stack_name, ChangeSetName=nochange_changeset["Id"]436 )437 snapshot.match("describe_nochange", describe_nochange)438 assert describe_nochange["ExecutionStatus"] == "UNAVAILABLE"439 # 3. try to execute the unavailable change set440 with pytest.raises(cfn_client.exceptions.InvalidChangeSetStatusException) as e:441 cfn_client.execute_change_set(StackName=stack_name, ChangeSetName=nochange_changeset["Id"])442 snapshot.match("error_execute_failed", e.value)443@pytest.mark.aws_validated444def test_deleted_changeset(cfn_client, snapshot, cleanups):445 """simple case verifying that proper exception is thrown when trying to get a deleted changeset"""446 snapshot.add_transformer(snapshot.transform.cloudformation_api())447 changeset_name = f"changeset-{short_uid()}"448 stack_name = f"stack-{short_uid()}"449 cleanups.append(lambda: cfn_client.delete_stack(StackName=stack_name))450 snapshot.add_transformer(snapshot.transform.regex(stack_name, "<stack-name>"))451 template_path = os.path.join(os.path.dirname(__file__), "../templates/cdkmetadata.yaml")452 template = load_template_file(template_path)453 # 1. create change set454 create = cfn_client.create_change_set(455 ChangeSetName=changeset_name,456 StackName=stack_name,457 TemplateBody=template,458 Capabilities=["CAPABILITY_AUTO_EXPAND", "CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"],459 ChangeSetType="CREATE",460 )461 snapshot.match("create", create)462 changeset_id = create["Id"]463 def _check_changeset_available():464 status = cfn_client.describe_change_set(StackName=stack_name, ChangeSetName=changeset_id)[465 "Status"466 ]467 if status == "FAILED":468 raise ShortCircuitWaitException("Change set in unrecoverable status")469 return status == "CREATE_COMPLETE"470 assert wait_until(_check_changeset_available)471 # 2. delete change set472 cfn_client.delete_change_set(ChangeSetName=changeset_id, StackName=stack_name)473 with pytest.raises(cfn_client.exceptions.ChangeSetNotFoundException) as e:474 cfn_client.describe_change_set(StackName=stack_name, ChangeSetName=changeset_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!!