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_refs(input, self.supported_resource_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_refs(input, self.supported_resource_refs_mock))
class TestRefCanResolveResourceRefs(TestCase): def setUp(self): self.supported_resource_refs_mock = Mock() self.ref = RefAction() @patch.object(RefAction, "_parse_resource_reference") def test_must_replace_refs(self, _parse_resource_reference_mock): resolved_value = "SomeOtherValue" input = { "Ref": "LogicalId.Property" } expected = { "Ref": resolved_value } _parse_resource_reference_mock.return_value = ("LogicalId", "Property") self.supported_resource_refs_mock.get.return_value = resolved_value output = self.ref.resolve_resource_refs(input, self.supported_resource_refs_mock) self.assertEqual(expected, output) self.supported_resource_refs_mock.get.assert_called_once_with("LogicalId", "Property") _parse_resource_reference_mock.assert_called_once_with("LogicalId.Property") @patch.object(RefAction, "_parse_resource_reference") def test_handle_unsupported_references(self, _parse_resource_reference_mock): input = { "Ref": "LogicalId.Property" } expected = { "Ref": "LogicalId.Property" } _parse_resource_reference_mock.return_value = ("LogicalId", "Property") self.supported_resource_refs_mock.get.return_value = None output = self.ref.resolve_resource_refs(input, self.supported_resource_refs_mock) self.assertEqual(expected, output) self.supported_resource_refs_mock.get.assert_called_once_with("LogicalId", "Property") _parse_resource_reference_mock.assert_called_once_with("LogicalId.Property") @patch.object(RefAction, "_parse_resource_reference") def test_handle_unparsable_reference_value(self, _parse_resource_reference_mock): input = { "Ref": "some value" } expected = { "Ref": "some value" } _parse_resource_reference_mock.return_value = (None, None) output = self.ref.resolve_resource_refs(input, self.supported_resource_refs_mock) self.assertEqual(expected, output) self.supported_resource_refs_mock.get.assert_not_called() _parse_resource_reference_mock.assert_called_once_with("some value") @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_refs(input, self.supported_resource_refs_mock))
class TestRefCanResolveResourceRefs(TestCase): def setUp(self): self.supported_resource_refs_mock = Mock() self.ref = RefAction() @patch.object(RefAction, "_parse_resource_reference") def test_must_replace_refs(self, _parse_resource_reference_mock): resolved_value = "SomeOtherValue" input = {"Ref": "LogicalId.Property"} expected = {"Ref": resolved_value} _parse_resource_reference_mock.return_value = ("LogicalId", "Property") self.supported_resource_refs_mock.get.return_value = resolved_value output = self.ref.resolve_resource_refs( input, self.supported_resource_refs_mock) self.assertEqual(expected, output) self.supported_resource_refs_mock.get.assert_called_once_with( "LogicalId", "Property") _parse_resource_reference_mock.assert_called_once_with( "LogicalId.Property") @patch.object(RefAction, "_parse_resource_reference") def test_handle_unsupported_references(self, _parse_resource_reference_mock): input = {"Ref": "LogicalId.Property"} expected = {"Ref": "LogicalId.Property"} _parse_resource_reference_mock.return_value = ("LogicalId", "Property") self.supported_resource_refs_mock.get.return_value = None output = self.ref.resolve_resource_refs( input, self.supported_resource_refs_mock) self.assertEqual(expected, output) self.supported_resource_refs_mock.get.assert_called_once_with( "LogicalId", "Property") _parse_resource_reference_mock.assert_called_once_with( "LogicalId.Property") @patch.object(RefAction, "_parse_resource_reference") def test_handle_unparsable_reference_value(self, _parse_resource_reference_mock): input = {"Ref": "some value"} expected = {"Ref": "some value"} _parse_resource_reference_mock.return_value = (None, None) output = self.ref.resolve_resource_refs( input, self.supported_resource_refs_mock) self.assertEqual(expected, output) self.supported_resource_refs_mock.get.assert_not_called() _parse_resource_reference_mock.assert_called_once_with("some value") @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_refs(input, self.supported_resource_refs_mock))