def test_find_resource_no_expected_type_optional_not_present(self): test_value = 'test-value' target = stack_info.ResourceInfoList(MOCK_STACK_ARN) target.append(mock.MagicMock(test_attr='unexpected-1')) target.append(mock.MagicMock(test_attr='unexpected-2')) actual_resource = target._ResourceInfoList__find_resource( 'test_attr', test_value, None, True) self.assertIsNone(actual_resource)
def test_find_resource_no_expected_type_not_optional_not_present(self): test_value = 'test-value' target = stack_info.ResourceInfoList(MOCK_STACK_ARN) target.append(mock.MagicMock(test_attr='unexpected-1')) target.append(mock.MagicMock(test_attr='unexpected-2')) with self.assertRaisesRegexp(ValidationError, test_value): target._ResourceInfoList__find_resource('test_attr', test_value, None, False)
def test_get_by_logical_id_default(self): expected_resource = 'test-resource' logical_id = 'test-id' with mock.patch( 'stack_info.ResourceInfoList._ResourceInfoList__find_resource', return_value=expected_resource) as mock_find_resource: target = stack_info.ResourceInfoList(MOCK_STACK_ARN) actual_resource = target.get_by_logical_id(logical_id) self.assertIs(actual_resource, expected_resource) mock_find_resource.assert_called_once_with('logical_id', logical_id, None, False)
def test_find_resource_expected_type_not_optional_wrong_type(self): test_value = 'test-value' expected_type = 'test-type' expected_resource = mock.MagicMock(test_attr=test_value, type='unexpected-type') target = stack_info.ResourceInfoList(MOCK_STACK_ARN) target.append(mock.MagicMock(test_attr='unexpected-1')) target.append(expected_resource) target.append(mock.MagicMock(test_attr='unexpected-2')) with self.assertRaisesRegexp(ValidationError, expected_type): target._ResourceInfoList__find_resource('test_attr', test_value, expected_type, False)
def test_find_resource_expected_type_not_optional_present(self): test_value = 'test-value' expected_type = 'test-type' expected_resource = mock.MagicMock(test_attr=test_value, type=expected_type) target = stack_info.ResourceInfoList(MOCK_STACK_ARN) target.append(mock.MagicMock(test_attr='unexpected-1')) target.append(expected_resource) target.append(mock.MagicMock(test_attr='unexpected-2')) actual_resource = target._ResourceInfoList__find_resource( 'test_attr', test_value, expected_type, False) self.assertIs(actual_resource, expected_resource)
def test_get_by_type(self): test_value = 'test-value' expected_type = 'test-type' expected_resource = mock.MagicMock(test_attr=test_value, type=expected_type) expected_list = [expected_resource] target = stack_info.ResourceInfoList(MOCK_STACK_ARN) target.append( mock.MagicMock(test_attr='unexpected-1', type='unexpected-type')) target.append(expected_resource) target.append( mock.MagicMock(test_attr='unexpected-2', type='unexpected-type')) actual_list = target.get_by_type(expected_type) self.assertItemsEqual(actual_list, expected_list)
def test_get_by_physical_id_with_args(self): expected_resource = 'test-resource' physical_id = 'test-id' expected_type = 'test-type' optional = True with mock.patch( 'stack_info.ResourceInfoList._ResourceInfoList__find_resource', return_value=expected_resource) as mock_find_resource: target = stack_info.ResourceInfoList(MOCK_STACK_ARN) actual_resource = target.get_by_physical_id( physical_id, expected_type=expected_type, optional=optional) self.assertIs(actual_resource, expected_resource) mock_find_resource.assert_called_once_with('physical_id', physical_id, expected_type, optional)
def test_constructor(self): target = stack_info.ResourceInfoList(MOCK_STACK_ARN) self.assertIs(target.stack_arn, MOCK_STACK_ARN)