def test_version_update(self, boto3_client, send_mock): client = Mock() boto3_client.return_value = client context = MockContext() event = { 'RequestType': 'Update', 'ResourceProperties': { 'FunctionName': 'function_name', } } client.get_function.return_value = { 'Configuration': { 'CodeSha256': '123' } } client.publish_version.return_value = {'Version': 'version123'} version.handler(event, context, sleep=0.1) client.publish_version.assert_called_once_with( FunctionName='function_name', CodeSha256='123' ) send_mock.assert_called_once_with( event, context, SUCCESS, response_data={'Version': 'version123'} )
def test_version_delete(self, boto3_client, send_mock): client = Mock() boto3_client.return_value = client context = MockContext() event = { 'RequestType': 'Delete', 'ResourceProperties': { 'FunctionName': 'function_name', } } version.handler(event, context, sleep=0.1) client.get_function.assert_not_called() client.publish_version.assert_not_called() send_mock.assert_called_once_with(event, context, SUCCESS)
def test_bucket_notification_configuration_delete(self, boto3_client, send_mock): client = Mock() boto3_client.return_value = client context = MockContext() event = { 'RequestType': 'Delete', 'ResourceProperties': { 'Bucket': 'bucket', } } client.get_bucket_notification_configuration.return_value = {} bucket_notification_configuration.handler(event, context) client.put_bucket_notification_configuration.assert_called_once_with( Bucket='bucket', NotificationConfiguration={}) send_mock.assert_called_once_with( event, context, SUCCESS, physical_resource_id='bucket-bucket-notification-configuration')
def test_bucket_notification_configuration_existing_non_gordon_configuration( self, boto3_client, send_mock): client = Mock() boto3_client.return_value = client context = MockContext() event = { 'RequestType': 'Create', 'ResourceProperties': { 'Bucket': 'bucket' } } client.get_bucket_notification_configuration.return_value = { 'LambdaFunctionConfigurations': [{ 'Id': 'custom-id' }], 'TopicConfigurations': [{ 'Id': 'custom-id' }], 'QueueConfigurations': [{ 'Id': 'custom-id' }], } bucket_notification_configuration.handler(event, context) send_mock.assert_called_once_with( event, context, FAILED, physical_resource_id='bucket-bucket-notification-configuration', reason=("Bucket bucket contains a notification called custom-id " "which was not created by gordon, hence the risk " "of trying it to add/modify/delete new notifications. " "Please check the documentation in order to understand " "why gordon refuses to proceed."))
def _test_bucket_notification_configuration(self, boto3_client, send_mock, request_type): client = Mock() boto3_client.return_value = client context = MockContext() event = { 'RequestType': request_type, 'ResourceProperties': { 'Bucket': 'bucket', 'LambdaFunctionConfigurations': [{ 'Id': 'lambda-id', 'DestinationArn': 'lambda-arn', 'Events': ['event1', 'event2'], 'KeyFilters': ['filters1'] }], 'TopicConfigurations': [{ 'Id': 'topic-id', 'DestinationArn': 'topic-arn', 'Events': ['event1', 'event2'], 'KeyFilters': ['filters2'] }], 'QueueConfigurations': [{ 'Id': 'topic-id', 'DestinationArn': 'topic-arn', 'Events': ['event1', 'event2'], 'KeyFilters': [] }] } } client.get_bucket_notification_configuration.return_value = { 'LambdaFunctionConfigurations': [{ 'Id': 'gordon-configuration' }], 'TopicConfigurations': [{ 'Id': 'gordon-configuration' }], 'QueueConfigurations': [], } bucket_notification_configuration.handler(event, context) client.put_bucket_notification_configuration.assert_called_once_with( Bucket='bucket', NotificationConfiguration={ 'LambdaFunctionConfigurations': [{ 'Id': 'lambda-id', 'LambdaFunctionArn': 'lambda-arn', 'Events': ['event1', 'event2'], 'Filter': { 'Key': { 'FilterRules': ['filters1'] } } }], 'TopicConfigurations': [{ 'Id': 'topic-id', 'TopicArn': 'topic-arn', 'Events': ['event1', 'event2'], 'Filter': { 'Key': { 'FilterRules': ['filters2'] } } }], 'QueueConfigurations': [{ 'Id': 'topic-id', 'QueueArn': 'topic-arn', 'Events': ['event1', 'event2'], }] }) send_mock.assert_called_once_with( event, context, SUCCESS, physical_resource_id='bucket-bucket-notification-configuration')
def test_sleep_delete(self, sleep_mock, send_mock): context = MockContext() event = {'RequestType': 'Delete', 'ResourceProperties': {'Time': 1}} sleep.handler(event, context) send_mock.assert_called_once_with(event, context, SUCCESS) sleep_mock.assert_not_called()