def test_yaml_output_doesnt_modify_multiline_string(self):
        # Setup. Use (modified) example from AWS documentation
        func = Sub(
            dedent("""
            #!/bin/bash -xe
            yum update -y aws-cfn-bootstrap
            /opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource LaunchConfig --configsets wordpress_install --region ${AWS::Region}
            /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WebServerGroup --region ${AWS::Region}
            echo hello from ${user}
            """),
            user="******",
        )

        data = SingleAttributeObject(one=func)

        # Exercise
        output = data.export("yaml")

        # Verify
        assert output == dedent("""
            ---
            one: !Sub
            - |
              #!/bin/bash -xe
              yum update -y aws-cfn-bootstrap
              /opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource LaunchConfig --configsets wordpress_install --region ${AWS::Region}
              /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WebServerGroup --region ${AWS::Region}
              echo hello from ${user}
            - user: bobbytables
            """)
예제 #2
0
    def test_yaml_tags_are_not_printed(self):
        @attrs(**ATTRSCONFIG)
        class TestObject(AWSObject):
            dict_value = attrib()
            list_value = attrib()
            number_value = attrib()
            string_value = attrib()

        data = TestObject(
            string_value="some string",
            number_value=42,
            list_value=[1, 2, "abc"],
            dict_value={"a": "b"},
        )

        output = data.export("yaml")

        assert output == dedent("""
            ---
            dict_value:
              a: b
            list_value:
            - 1
            - 2
            - abc
            number_value: 42
            string_value: some string
            """)
예제 #3
0
    def test_empty_export_when_no_aws_attributes_configured(self):
        data = ZeroAttributeObject()

        output = data.export("yaml")

        assert output == dedent("""
            --- {}
            """)
예제 #4
0
    def test_empty_export_when_no_aws_attributes_set(self):
        data = MixedAttributeObject(a=6)

        output = data.export("yaml")

        assert output == dedent("""
            --- {}
            """)
예제 #5
0
    def test_empty_top_level_object_is_exported_as_empty_dict(self):
        data = ZeroAttributeObject()

        output = data.export("yaml")

        assert output == dedent("""
            --- {}
            """)
예제 #6
0
    def test_single_entry_object_is_exported_in_block_style(self):
        data = SingleAttributeObject(one=1)

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 1
            """)
예제 #7
0
    def test_false_values_are_exported(self):
        data = SingleAttributeObject(one=False)

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: false
            """)
예제 #8
0
    def test_attribute_set_to_emptyish_dictionary_is_not_exported(self):
        data = DualAttributeObject(one=42, two={"a": []})

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            """)
예제 #9
0
    def test_leading_and_trailing_whitespace_is_not_stripped(self):
        data = SingleAttributeObject(one="    hello world   ")

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: '    hello world   '
            """)
예제 #10
0
    def test_attribute_set_to_emptyish_object_is_not_exported(self):
        data = DualAttributeObject(one=42, two=SingleAttributeObject(one=[]))

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            """)
예제 #11
0
    def test_empty_string_has_simple_representation(self):
        data = SingleAttributeObject(one="")

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: ''
            """)
예제 #12
0
    def test_empty_list_is_exported_in_flow_style(self):
        data = SingleAttributeObject(one=EMPTY_LIST)

        output = data.export("yaml")

        assert output == dedent("""
                ---
                one: []
                """)
예제 #13
0
    def test_aws_attributes_are_not_exported_when_uninitialised(self):
        data = DualAttributeObject(one=42)

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            """)
예제 #14
0
    def test_internal_attributes_are_not_exported(self):
        data = MixedAttributeObject(one=42, a=6)

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            """)
예제 #15
0
    def test_aws_attributes_are_exported_when_set(self):
        data = SingleAttributeObject(one=42)

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            """)
예제 #16
0
    def test_string_quotes_are_not_used_when_unnecessary(self):
        data = SingleAttributeObject(
            one="Hello world. Here is a namespace AWS::service::Resource")

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: Hello world. Here is a namespace AWS::service::Resource
            """)
예제 #17
0
    def test_empty_export_when_no_aws_attributes_set_and_internal_attributes_set(
            self):
        data = DualAttributeObject()
        data._internal_value = 7

        output = data.export("yaml")

        assert output == dedent("""
            --- {}
            """)
예제 #18
0
    def test_aws_attributes_are_not_exported_when_set_to_none(self):
        data = DualAttributeObject(one=42, two=15)
        data.two = None

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            """)
예제 #19
0
    def test_none_values_are_exported_as_null(self):
        data = SingleAttributeObject()
        data.one = None

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: null
            """)
예제 #20
0
    def test_multi_entry_object_is_exported_in_block_style(self):
        data = DualAttributeObject(one=1, two=2)

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 1
            two: 2
            """)
예제 #21
0
    def test_export_basic_parameter(self):
        """Should be able to create and export a simple parameter."""
        param = Parameter(Type="String", Default="Hello world")
        output = param.export("yaml")

        assert output == dedent("""
        ---
        Type: String
        Default: Hello world
        """)
예제 #22
0
    def test_attribute_can_export_an_empty_list_by_using_signal_value(self):
        data = DualAttributeObject(one=42, two=EMPTY_LIST)

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            two: []
            """)
예제 #23
0
    def test_unknown_attributes_are_exported_even_when_no_known_attributes(
            self):
        data = ZeroAttributeObject()
        data.set_unknown_aws_attribute("special", 8)

        output = data.export("yaml")

        assert output == dedent("""
            ---
            special: 8
            """)
예제 #24
0
    def test_attribute_set_to_list_has_empty_entries_removed_in_export(self):
        data = DualAttributeObject(one=42, two=["a", {}])

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            two:
            - a
            """)
예제 #25
0
    def test_list_is_exported_in_block_style(self):
        data = SingleAttributeObject(one=[2, 3, 4])

        output = data.export("yaml")

        assert output == dedent("""
                ---
                one:
                - 2
                - 3
                - 4
                """)
예제 #26
0
    def test_aws_attributes_are_only_exported_when_set(self):
        data = DualAttributeObject(one=42)
        data._internal_value = 7
        data.set_unknown_aws_attribute("special", 8)

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            special: 8
            """)
예제 #27
0
    def test_attribute_set_to_dictionary_has_empty_values_removed_in_export(
            self):
        data = DualAttributeObject(one=42, two={"a": [], "b": 13})

        output = data.export("yaml")

        assert output == dedent("""
            ---
            one: 42
            two:
              b: 13
            """)
예제 #28
0
    def test_export_basic_stack(self):
        """Should be able to create and export a simple stack example."""
        stack = Stack()
        stack.Resources["SomeName"] = SimpleResource()
        output = stack.export("yaml")

        assert output == dedent("""
        ---
        AWSTemplateFormatVersion: '2010-09-09'
        Resources:
          SomeName:
            Type: NameSpace::Service::Resource
        """)
    def test_yaml_output(self):
        # Setup
        func = ImportValue("SomeStack-export_name")
        data = SingleAttributeObject(one=func)

        # Exercise
        output = data.export("yaml")

        # Verify
        assert output == dedent("""
            ---
            one: !ImportValue SomeStack-export_name
            """)
    def test_yaml_output_doesnt_modify_string(self):
        # Setup
        func = Base64("Some 6HSsort of text_?:%#")
        data = SingleAttributeObject(one=func)

        # Exercise
        output = data.export("yaml")

        # Verify
        assert output == dedent("""
            ---
            one: !Base64 Some 6HSsort of text_?:%#
            """)