Exemple #1
0
    def test_sub_all_refs_with_dict_input(self):
        parameters = {"key1": "value1", "key2": "value2"}
        input = {"Fn::Sub": {"a": "key1", "b": "key2"}}
        expected = {"Fn::Sub": {"a": "key1", "b": "key2"}}

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
Exemple #2
0
    def test_sub_all_refs_with_pseudo_parameters(self):
        parameters = {"key1": "value1", "AWS::Region": "ap-southeast-1"}
        input = {"Fn::Sub": "hello ${AWS::Region} ${key1}"}
        expected = {"Fn::Sub": "hello ap-southeast-1 value1"}

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
Exemple #3
0
    def test_return_value_if_cannot_handle(self, can_handle_mock):
        parameters = {"key": "value"}
        input = {"Fn::Sub": "${key}"}
        expected = {"Fn::Sub": "${key}"}

        sub = SubAction()
        can_handle_mock.return_value = False  # Simulate failure to handle the input. Result should be same as input
        self.assertEqual(expected,
                         sub.resolve_parameter_refs(input, parameters))
Exemple #4
0
    def test_must_resolve_string_value(self):
        parameters = {"key1": "value1"}
        input = {"Fn::Sub": "Hello ${key1}"}
        expected = {"Fn::Sub": "Hello value1"}

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
Exemple #5
0
    def test_must_resolve_array_value(self):
        parameters = {"key1": "value1"}
        input = {"Fn::Sub": ["Hello ${key1} ${a}", {"a": "b"}]}

        expected = {"Fn::Sub": ["Hello value1 ${a}", {"a": "b"}]}

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
Exemple #6
0
    def test_sub_all_refs_with_literals(self):
        parameters = {"key1": "value1", "key2": "value2"}
        input = {"Fn::Sub": "hello ${key1} ${key2} ${!key1} ${!key2}"}
        expected = {
            # ${! is the prefix for literal. These won't be substituted
            "Fn::Sub": "hello value1 value2 ${!key1} ${!key2}"
        }

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
    def test_return_value_if_cannot_handle(self, can_handle_mock):
        parameters = {
            "key": "value"
        }
        input = {
            "Fn::Sub": "${key}"
        }
        expected = {
            "Fn::Sub": "${key}"
        }

        sub = SubAction()
        can_handle_mock.return_value = False # Simulate failure to handle the input. Result should be same as input
        self.assertEqual(expected, sub.resolve_parameter_refs(input, parameters))
    def test_must_resolve_string_value(self):
        parameters = {
            "key1": "value1"
        }
        input = {
            "Fn::Sub": "Hello ${key1}"
        }
        expected = {
            "Fn::Sub": "Hello value1"
        }

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
Exemple #9
0
    def test_sub_all_refs_multiple_references(self):
        parameters = {"key1": "value1", "key2": "value2"}
        input = {
            "Fn::Sub":
            "hello ${key1} ${key2} ${key1}${key2} ${unknown} ${key1.attr}"
        }
        expected = {
            "Fn::Sub":
            "hello value1 value2 value1value2 ${unknown} ${key1.attr}"
        }

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
    def test_sub_all_refs_with_pseudo_parameters(self):
        parameters = {
            "key1": "value1",
            "AWS::Region": "ap-southeast-1"
        }
        input = {
            "Fn::Sub": "hello ${AWS::Region} ${key1}"
        }
        expected = {
            "Fn::Sub": "hello ap-southeast-1 value1"
        }

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
    def test_sub_all_refs_with_dict_input(self):
        parameters = {
            "key1": "value1",
            "key2": "value2"
        }
        input = {
            "Fn::Sub": {"a": "key1", "b": "key2"}
        }
        expected = {
            "Fn::Sub": {"a": "key1", "b": "key2"}
        }

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
    def test_sub_all_refs_multiple_references(self):
        parameters = {
            "key1": "value1",
            "key2": "value2"
        }
        input = {
            "Fn::Sub": "hello ${key1} ${key2} ${key1}${key2} ${unknown} ${key1.attr}"
        }
        expected = {
            "Fn::Sub": "hello value1 value2 value1value2 ${unknown} ${key1.attr}"
        }

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
    def test_must_resolve_array_value(self):
        parameters = {
            "key1": "value1"
        }
        input = {
            "Fn::Sub": ["Hello ${key1} ${a}", {"a":"b"}]
        }

        expected = {
            "Fn::Sub": ["Hello value1 ${a}", {"a": "b"}]
        }

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)
    def test_sub_all_refs_with_literals(self):
        parameters = {
            "key1": "value1",
            "key2": "value2"
        }
        input = {
            "Fn::Sub": "hello ${key1} ${key2} ${!key1} ${!key2}"
        }
        expected = {
            # ${! is the prefix for literal. These won't be substituted
            "Fn::Sub": "hello value1 value2 ${!key1} ${!key2}"
        }

        sub = SubAction()
        result = sub.resolve_parameter_refs(input, parameters)

        self.assertEqual(expected, result)