Best Python code snippet using localstack_python
test_changeset_stack.py
Source:test_changeset_stack.py
1from fzfaws.utils.pyfzf import Pyfzf2import io3import sys4import unittest5from unittest.mock import call, patch6from fzfaws.cloudformation.changeset_stack import changeset_stack7class TestCloudformationChangesetStack(unittest.TestCase):8 def setUp(self):9 self.capturedOutput = io.StringIO()10 sys.stdout = self.capturedOutput11 self.list_change_sets_value = {12 "Summaries": [13 {14 "ChangeSetName": "foo",15 "StackName": "testing1",16 "ExecutionStatus": "AVAILABLE",17 "Status": "CREATE_COMPLETE",18 "Description": "boo",19 }20 ]21 }22 def tearDown(self):23 sys.stdout = sys.__stdout__24 @patch.object(Pyfzf, "process_list")25 @patch.object(Pyfzf, "execute_fzf")26 @patch("fzfaws.cloudformation.changeset_stack.Cloudformation")27 def test_changset_info(self, MockedCloudformation, mocked_execute, mocked_process):28 self.capturedOutput.truncate(0)29 self.capturedOutput.seek(0)30 cloudformation = MockedCloudformation()31 cloudformation.stack_name = "testing1"32 cloudformation.client.list_change_sets.return_value = (33 self.list_change_sets_value34 )35 mocked_execute.return_value = "fooboo"36 cloudformation.client.describe_change_set.return_value = {"Changes": {}}37 changeset_stack(info=True)38 cloudformation.set_stack.assert_called_once()39 cloudformation.client.list_change_sets.assert_called_once_with(40 StackName="testing1"41 )42 mocked_process.assert_called_once_with(43 self.list_change_sets_value["Summaries"],44 "ChangeSetName",45 "StackName",46 "ExecutionStatus",47 "Status",48 "Description",49 )50 mocked_execute.assert_called_once()51 cloudformation.client.describe_change_set.assert_called_once_with(52 ChangeSetName="fooboo", StackName="testing1"53 )54 self.assertRegex(self.capturedOutput.getvalue(), r"StackName: testing1")55 self.assertRegex(self.capturedOutput.getvalue(), r"ChangeSetName: fooboo")56 @patch("fzfaws.cloudformation.changeset_stack.get_confirmation")57 @patch.object(Pyfzf, "process_list")58 @patch.object(Pyfzf, "execute_fzf")59 @patch("fzfaws.cloudformation.changeset_stack.Cloudformation")60 def test_execute_changeset(61 self, MockedCloudformation, mocked_execute, mocked_list, mocked_confirm62 ):63 mocked_confirm.return_value = True64 cloudformation = MockedCloudformation()65 cloudformation.stack_name = "testing1"66 cloudformation.client.list_change_sets.return_value = (67 self.list_change_sets_value68 )69 mocked_execute.return_value = "fooboo"70 changeset_stack(execute=True, delete=True)71 cloudformation.client.delete_change_set.assert_not_called()72 cloudformation.set_stack.assert_called_once()73 cloudformation.client.list_change_sets.assert_called_once_with(74 StackName="testing1"75 )76 mocked_list.assert_called_once_with(77 self.list_change_sets_value["Summaries"],78 "ChangeSetName",79 "StackName",80 "ExecutionStatus",81 "Status",82 "Description",83 )84 cloudformation.client.execute_change_set.assert_called_once_with(85 ChangeSetName="fooboo", StackName="testing1"86 )87 cloudformation.wait.assert_called_once_with(88 "stack_update_complete", "Wating for stack to be updated ..."89 )90 @patch("fzfaws.cloudformation.changeset_stack.get_confirmation")91 @patch.object(Pyfzf, "process_list")92 @patch.object(Pyfzf, "execute_fzf")93 @patch("fzfaws.cloudformation.changeset_stack.Cloudformation")94 def test_delete_changeset(95 self, MockedCloudformation, mocked_execute, mocked_process, mocked_confirm,96 ):97 mocked_confirm.return_value = True98 cloudformation = MockedCloudformation()99 cloudformation.stack_name = "testing1"100 cloudformation.client.list_change_sets.return_value = (101 self.list_change_sets_value102 )103 mocked_execute.return_value = ["fooboo", "helloworld"]104 changeset_stack(delete=True)105 mocked_execute.assert_called_once_with(multi_select=True)106 cloudformation.client.delete_change_set.assert_has_calls(107 [108 call(ChangeSetName="fooboo", StackName="testing1"),109 call(ChangeSetName="helloworld", StackName="testing1"),110 ]111 )112 @patch("fzfaws.cloudformation.changeset_stack.update_stack")113 @patch("builtins.input")114 @patch("fzfaws.cloudformation.changeset_stack.Cloudformation")115 def test_create_changeset(self, MockedCloudformation, mocked_input, mocked_udpate):116 cloudformation = MockedCloudformation()117 cloudformation.stack_name = "testing1"118 mocked_input.return_value = "fooboo"119 mocked_udpate.return_value = {120 "Parameters": [121 {"ParameterKey": "SSHLocation", "UsePreviousValue": True},122 {"ParameterKey": "Hello", "UsePreviousValue": True},123 {"ParameterKey": "WebServer", "UsePreviousValue": True},124 ],125 "StackName": "testing1",126 "UsePreviousTemplate": True,127 "cloudformation_action": cloudformation.client.create_change_set,128 }129 cloudformation.execute_with_capabilities.return_value = {}130 changeset_stack(profile="root", region="us-east-1")131 cloudformation.execute_with_capabilities.assert_called_once_with(132 ChangeSetName="fooboo",133 Description="fooboo",134 Parameters=[135 {"ParameterKey": "SSHLocation", "UsePreviousValue": True},136 {"ParameterKey": "Hello", "UsePreviousValue": True},137 {"ParameterKey": "WebServer", "UsePreviousValue": True},138 ],139 StackName="testing1",140 UsePreviousTemplate=True,141 cloudformation_action=cloudformation.client.create_change_set,142 )143 mocked_udpate.assert_called_once_with(144 cloudformation.profile,145 cloudformation.region,146 False,147 False,148 False,149 False,150 False,151 None,152 False,153 cloudformation=cloudformation,154 dryrun=True,155 )156 MockedCloudformation.assert_called_with("root", "us-east-1")157 changeset_stack(158 replace=True, wait=True, extra=True, bucket="kazhala-lol/hello.yaml"159 )160 MockedCloudformation.assert_called_with(False, False)161 mocked_udpate.assert_called_with(162 cloudformation.profile,163 cloudformation.region,164 True,165 False,166 False,167 True,168 True,169 "kazhala-lol/hello.yaml",170 False,171 cloudformation=cloudformation,172 dryrun=True,...
aws_marketplace_catalog_info.py
Source:aws_marketplace_catalog_info.py
...71 return paginator.paginate(72 Catalog=module.params['catalog']73 ), True74 else:75 return client.list_change_sets(76 Catalog=module.params['catalog']77 ), False78 elif module.params['list_entities']:79 if client.can_paginate('list_entities'):80 paginator = client.get_paginator('list_entities')81 return paginator.paginate(82 Catalog=module.params['catalog'],83 EntityType=module.params['entity_type']84 ), True85 else:86 return client.list_entities(87 Catalog=module.params['catalog'],88 EntityType=module.params['entity_type']89 ), False...
__init__.py
Source:__init__.py
...38 self.outputs = stack_data["Outputs"]39 self.resources = stack_data["Resources"]40 self.template = self.cfn.get_template(self.name)41 self._update_events()42 self.change_sets = self.list_change_sets()43 self.loaded = True44 def create(self, template, parameters):45 """46 Create stack in CloudFormation47 :param template: template object48 :param parameters: parameters object49 :return:50 """51 self.cfn.create_stack(self.name, template, parameters)52 def update(self, template, parameters):53 """54 Update stack in CloudFormation55 :type template: Template56 :param template: template object57 :type parameters: Parameters58 :param parameters: parameters object59 :return:60 """61 self.cfn.update_stack(self.name, template, parameters)62 def delete(self):63 """64 Deletes stack from AWS65 :return:66 """67 self.cfn.delete_stack(self.name)68 def get_change_set(self, name):69 """70 Return change details71 :param name:72 :return:73 """74 change = ChangeSet(self, name)75 change.load()76 return change77 def list_change_sets(self):78 """79 Return dict of change sets80 :return:81 """82 change_sets = {}83 raw_change_sets = self.cfn.list_change_sets(self.name)84 for change_set in raw_change_sets:85 change_sets[change_set["ChangeSetName"]] = [86 change_set["ChangeSetName"],87 change_set.get("Description"),88 change_set["ExecutionStatus"]89 ]90 return change_sets91 def _update_events(self):92 """93 Update stack events from AWS API94 :return:95 """96 try:97 for event in self.cfn.describe_stack_events(self.name):...
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!!