Beispiel #1
0
 def expected_deployed_config(self):
     return StackConfiguration(stack_name=self.external_name,
                               parameters=self.deployed_parameters,
                               stack_tags=deepcopy(self.deployed_tags),
                               notifications=deepcopy(
                                   self.deployed_notification_arns),
                               role_arn=self.deployed_role_arn)
Beispiel #2
0
 def make_config_comparable(self, config: StackConfiguration):
     config_dict = dict(config._asdict())
     without_empty_values = {
         key: value
         for key, value in config_dict.items()
         if value not in (None, [], {}) and key != 'stack_name'
     }
     return without_empty_values
Beispiel #3
0
 def expected_generated_config(self):
     return StackConfiguration(
         stack_name=self.external_name,
         parameters=self.parameters_on_stack_config,
         stack_tags=deepcopy(self.tags),
         notifications=deepcopy(self.notifications),
         role_arn=self.role_arn
     )
Beispiel #4
0
    def setup_method(self, method):
        self.stack_name = 'stack'

        self.is_deployed = True
        self.output_format = 'yaml'

        self.output_stream = StringIO()

        self.config1 = StackConfiguration(stack_name=self.stack_name,
                                          parameters={},
                                          stack_tags={},
                                          notifications=[],
                                          role_arn=None)

        self.config2 = deepcopy(self.config1)

        self.template1 = 'template'
        self.template2 = 'template'
Beispiel #5
0
    def setup_method(self, method):
        self.serialize = cfn_flip.dump_yaml
        self.differ = DifflibStackDiffer()
        self.config1 = StackConfiguration(stack_name='stack',
                                          parameters={'pk1': 'pv1'},
                                          stack_tags={'tk1': 'tv1'},
                                          notifications=['notification'],
                                          role_arn=None)

        self.config2 = StackConfiguration(stack_name='stack',
                                          parameters={
                                              'pk1': 'pv1',
                                              'pk2': 'pv2'
                                          },
                                          stack_tags={'tk1': 'tv1'},
                                          notifications=['notification'],
                                          role_arn='new_role')

        self.template_dict_1 = {
            'AWSTemplateFormat': '2010-09-09',
            'Description': 'deployed',
            'Parameters': {
                'pk1': 'pv1'
            },
            'Resources': {}
        }
        self.template_dict_2 = {
            'AWSTemplateFormat': '2010-09-09',
            'Description': 'deployed',
            'Parameters': {
                'pk1': 'pv1'
            },
            'Resources': {
                'MyBucket': {
                    'Type': 'AWS::S3::Bucket',
                    'Properties': {
                        'BucketName': 'test'
                    }
                }
            }
        }
Beispiel #6
0
    def test_compare_stack_configurations__deployed_is_none__all_configs_are_falsey__returns_diff_with_none(
            self):
        empty_config = StackConfiguration(stack_name='stack',
                                          parameters={},
                                          stack_tags={},
                                          notifications=[],
                                          role_arn=None)
        comparison = self.differ.compare_stack_configurations(
            None, empty_config)

        expected = self.create_expected_diff(
            self.serialize(None),
            self.serialize(self.make_config_comparable(empty_config)),
            already_formatted=True)
        assert comparison == expected
Beispiel #7
0
 def generated_config(self):
     return StackConfiguration(stack_name=self.stack_name,
                               parameters={},
                               stack_tags={},
                               notifications=[],
                               role_arn=None)
Beispiel #8
0
class TestDiffLibWriter:
    def setup_method(self, method):
        self.stack_name = 'stack'

        self.is_deployed = True
        self.output_format = 'yaml'

        self.output_stream = StringIO()

        self.config1 = StackConfiguration(stack_name=self.stack_name,
                                          parameters={},
                                          stack_tags={},
                                          notifications=[],
                                          role_arn=None)

        self.config2 = deepcopy(self.config1)

        self.template1 = 'template'
        self.template2 = 'template'

    @property
    def template_diff(self):
        return list(difflib.unified_diff(self.template1, self.template2))

    @property
    def config_diff(self):
        config_1 = yaml.dump(dict(self.config1._asdict())).splitlines()
        config_2 = yaml.dump(dict(self.config2._asdict())).splitlines()
        return list(difflib.unified_diff(config_1, config_2))

    @property
    def diff(self):
        return StackDiff(self.stack_name, self.template_diff, self.config_diff,
                         self.is_deployed, self.config1, self.template1)

    @property
    def writer(self):
        return DiffLibWriter(
            self.diff,
            self.output_stream,
            self.output_format,
        )

    def test_has_config_difference__config_difference_is_present__returns_true(
            self):
        self.config2.parameters['new_key'] = 'new value'
        assert self.writer.has_config_difference

    def test_has_config_difference__config_difference_is_absent__returns_false(
            self):
        assert self.writer.has_config_difference is False

    def test_has_template_difference__template_difference_is_present__returns_true(
            self):
        self.template2 = 'new'
        assert self.writer.has_template_difference

    def test_has_template_difference__template_difference_is_absent__returns_false(
            self):
        assert self.writer.has_template_difference is False

    def test_dump_diff__returns_joined_list(self):
        result = self.writer.dump_diff(self.diff.config_diff)
        expected = '\n'.join(self.diff.config_diff)
        assert result == expected