class TestRefCanResolveResourceIdRefs(TestCase):

    def setUp(self):
        self.supported_resource_id_refs_mock = Mock()
        self.ref = RefAction()

    def test_must_replace_refs(self):
        resolved_value = "NewLogicalId"
        input = {
            "Ref": "LogicalId"
        }
        expected = {
            "Ref": resolved_value
        }
        self.supported_resource_id_refs_mock.get.return_value = resolved_value

        output = self.ref.resolve_resource_id_refs(input, self.supported_resource_id_refs_mock)

        self.assertEqual(expected, output)
        self.supported_resource_id_refs_mock.get.assert_called_once_with("LogicalId")

    def test_handle_unsupported_references(self):
        input = {
            "Ref": "OtherLogicalId.Property"
        }
        expected = {
            "Ref": "OtherLogicalId.Property"
        }

        self.supported_resource_id_refs_mock.get.return_value = None

        output = self.ref.resolve_resource_id_refs(input, self.supported_resource_id_refs_mock)
        self.assertEqual(expected, output)
        self.supported_resource_id_refs_mock.get.assert_not_called()

    @patch.object(RefAction, "can_handle")
    def test_return_value_if_cannot_handle(self, can_handle_mock):
        input = {
            "Ref": "key"
        }
        expected = {
            "Ref": "key"
        }

        ref = RefAction()
        can_handle_mock.return_value = False # Simulate failure to handle the input. Result should be same as input
        self.assertEqual(expected, ref.resolve_resource_id_refs(input, self.supported_resource_id_refs_mock))
Пример #2
0
    def test_return_value_if_cannot_handle(self, can_handle_mock):
        input = {"Ref": "key"}
        expected = {"Ref": "key"}

        ref = RefAction()
        can_handle_mock.return_value = False  # Simulate failure to handle the input. Result should be same as input
        self.assertEquals(
            expected,
            ref.resolve_resource_id_refs(input,
                                         self.supported_resource_id_refs_mock))
    def test_return_value_if_cannot_handle(self, can_handle_mock):
        input = {
            "Ref": "key"
        }
        expected = {
            "Ref": "key"
        }

        ref = RefAction()
        can_handle_mock.return_value = False # Simulate failure to handle the input. Result should be same as input
        self.assertEqual(expected, ref.resolve_resource_id_refs(input, self.supported_resource_id_refs_mock))
Пример #4
0
class TestRefCanResolveResourceIdRefs(TestCase):
    def setUp(self):
        self.supported_resource_id_refs_mock = Mock()
        self.ref = RefAction()

    def test_must_replace_refs(self):
        resolved_value = "NewLogicalId"
        input = {"Ref": "LogicalId"}
        expected = {"Ref": resolved_value}
        self.supported_resource_id_refs_mock.get.return_value = resolved_value

        output = self.ref.resolve_resource_id_refs(
            input, self.supported_resource_id_refs_mock)

        self.assertEqual(expected, output)
        self.supported_resource_id_refs_mock.get.assert_called_once_with(
            "LogicalId")

    def test_handle_unsupported_references(self):
        input = {"Ref": "OtherLogicalId.Property"}
        expected = {"Ref": "OtherLogicalId.Property"}

        self.supported_resource_id_refs_mock.get.return_value = None

        output = self.ref.resolve_resource_id_refs(
            input, self.supported_resource_id_refs_mock)
        self.assertEqual(expected, output)
        self.supported_resource_id_refs_mock.get.assert_not_called()

    @patch.object(RefAction, "can_handle")
    def test_return_value_if_cannot_handle(self, can_handle_mock):
        input = {"Ref": "key"}
        expected = {"Ref": "key"}

        ref = RefAction()
        can_handle_mock.return_value = False  # Simulate failure to handle the input. Result should be same as input
        self.assertEqual(
            expected,
            ref.resolve_resource_id_refs(input,
                                         self.supported_resource_id_refs_mock))