예제 #1
0
    def test_prefix_cannot_contain_special_characters(self, prefix):
        # Setup
        stack = Stack(Resources={"SomeName": SimpleResource()})

        # Exercise & Verify
        with pytest.raises(ValueError) as excinfo:
            _ = stack.with_prefixed_names(prefix)

        assert "alphanumeric" in str(excinfo.value).lower()
예제 #2
0
    def test_prefix_must_be_string(self, prefix):
        # Setup
        stack = Stack(Resources={"SomeName": SimpleResource()})

        # Exercise & Verify
        with pytest.raises(TypeError) as excinfo:
            _ = stack.with_prefixed_names(prefix)

        assert "string" in str(excinfo.value).lower()
예제 #3
0
    def test_prefix_cannot_be_empty(self):
        # Setup
        stack = Stack(Resources={"SomeName": SimpleResource()})

        # Exercise & Verify
        with pytest.raises(ValueError) as excinfo:
            _ = stack.with_prefixed_names("")

        assert "empty" in str(excinfo.value).lower()
예제 #4
0
    def test_prefix_must_have_leading_capital(self):
        # Setup
        stack = Stack(Resources={"SomeName": SimpleResource()})

        # Exercise & Verify
        with pytest.raises(ValueError) as excinfo:
            _ = stack.with_prefixed_names(
                "lowercasedCamelsAreBactrianButInvalid")

        assert "uppercase" in str(excinfo.value).lower()
예제 #5
0
    def test_return_value_is_a_new_stack(self):
        # Setup
        stack = Stack(Resources={"SomeName": SimpleResource()})

        # Exercise
        new_stack = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        assert isinstance(new_stack, Stack)
        assert new_stack is not stack
예제 #6
0
    def test_dont_create_export_name_for_output_when_it_is_not_set(self):
        # Setup
        name = "SomeItemName"
        stack = Stack(Outputs={name: (Output(Value="HelloWorld"))})

        # Exercise
        new_stack = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        new_output = new_stack.Outputs[self.STACK_PREFIX + name]
        assert getattr(new_output, "Export", None) is None
예제 #7
0
    def test_modify_content_of_description(self):
        # Setup
        stack = Stack(Description=LOREM_IPSUM)

        # Exercise
        new_stack = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        assert self.STACK_PREFIX in new_stack.Description
        assert LOREM_IPSUM in new_stack.Description
        assert stack.Description == LOREM_IPSUM, "Old stack should not be modified"
예제 #8
0
    def test_create_description_when_it_is_not_set(self):
        # Setup
        stack = Stack()

        # Exercise
        new_stack = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        assert self.STACK_PREFIX == new_stack.Description
        assert (not hasattr(stack, "Description") or
                stack.Description is None), "Old stack should not be modified"
예제 #9
0
    def test_copy_cfn_template_version(self):
        """AWSTemplateFormatVersion should be a string which we copy across unchanged"""
        # Setup
        version_string = "WhatIfThisWaSemanticallyVersioned.1.0"
        stack = Stack(AWSTemplateFormatVersion=version_string)

        # Exercise
        new_stack = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        assert new_stack.AWSTemplateFormatVersion == version_string
        assert stack.AWSTemplateFormatVersion == version_string, "Old stack should not be modified"
예제 #10
0
    def test_prefix_export_name_for_output(self):
        # Setup
        name = "SomeItemName"
        export_name = "SomeGloballyScopedValue"
        output = Output(Value="HelloWorld", Export={"Name": export_name})
        stack = Stack(Outputs={name: output})

        # Exercise
        new_stack = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        assert new_stack.Outputs[
            self.STACK_PREFIX +
            name]["Export"]["Name"] == self.STACK_PREFIX + export_name
예제 #11
0
    def test_copy_sam_version_in_transform(self):
        """If set, Transform should be the version of the Serverless Application Model
        being used, which we copy across unchanged.
        """
        # Setup
        version_string = "AWS::Serverless-1999-12-31"
        stack = Stack(Transform=version_string)

        # Exercise
        new_stack = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        assert new_stack.Transform == version_string
        assert stack.Transform == version_string, "Old stack should not be modified"
예제 #12
0
    def test_item_is_not_removed_from_original_stack(self, stack_attribute,
                                                     item):
        # Setup
        item_name = "SomeItemName"
        stack = Stack()
        stack[stack_attribute] = {item_name: item}

        # Exercise
        _ = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        assert len(stack[stack_attribute]) == 1
        assert stack[stack_attribute][item_name] is item
        assert stack[stack_attribute][item_name] == item
예제 #13
0
    def test_item_is_prefixed_in_the_new_stack(self, stack_attribute, item):
        # Setup
        item_name = "SomeItemName"
        stack = Stack()
        stack[stack_attribute] = {item_name: item}

        # Exercise
        new_stack = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        new_name = self.STACK_PREFIX + item_name

        assert len(new_stack[stack_attribute]) == 1
        assert item_name not in new_stack[stack_attribute]
        assert new_stack[stack_attribute][new_name] is item
예제 #14
0
    def test_output_is_prefixed_in_the_new_stack_but_not_same_object(
            self, stack_attribute, item):
        # Setup
        item_name = "SomeItemName"
        stack = Stack()
        stack[stack_attribute] = {item_name: item}

        # Exercise
        new_stack = stack.with_prefixed_names(self.STACK_PREFIX)

        # Verify
        new_name = self.STACK_PREFIX + item_name

        assert len(new_stack[stack_attribute]) == 1
        assert item_name not in new_stack[stack_attribute]

        new_item = new_stack[stack_attribute][new_name]
        assert new_item is not item
        assert getattr(new_item, "Description",
                       None) == getattr(item, "Description", None)
        assert getattr(new_item, "Value", None) is getattr(item, "Value", None), \
            "This should be the same because it might be a Reference function or some such"
예제 #15
0
    def test_prefix_is_an_underscored_alphanumeric_string(self, prefix):
        # Setup
        stack = Stack(Resources={"SomeName": SimpleResource()})

        # Exercise & Verify
        _ = stack.with_prefixed_names(prefix)  # Should not throw an error