Ejemplo n.º 1
0
 def test_current_config(self):
     api_config = {
         'Id': 'test-id',
         'LambdaFunctionArn': 'test-arn',
         'Events': [],
         'Filter': {
             'Key': {
                 'FilterRules': [{
                     'Name': 'Prefix',
                     'Value': ''
                 }, {
                     'Name': 'Suffix',
                     'Value': ''
                 }]
             }
         }
     }
     client = MagicMock()
     client.get_bucket_notification_configuration.return_value = {
         'LambdaFunctionConfigurations': [api_config]
     }
     bucket = AmazonBucket(self.module, client)
     current = bucket.current_config('test-id')
     assert current.raw == api_config
     assert client.get_bucket_notification_configuration.call_count == 1
Ejemplo n.º 2
0
 def test_current_config_empty(self):
     client = MagicMock()
     client.get_bucket_notification_configuration.return_value = {
         'LambdaFunctionConfigurations': []
     }
     bucket = AmazonBucket(self.module, client)
     current = bucket.current_config('test-id')
     assert current is None
     assert client.get_bucket_notification_configuration.call_count == 1
Ejemplo n.º 3
0
    def test_apply_config_add_event(self):
        api_config = {
            'Id': 'test-id',
            'LambdaFunctionArn': 'test-arn',
            'Events': ['s3:ObjectRemoved:*'],
            'Filter': {
                'Key': {
                    'FilterRules': [{
                        'Name': 'Prefix',
                        'Value': ''
                    }, {
                        'Name': 'Suffix',
                        'Value': ''
                    }]
                }
            }
        }
        client = MagicMock()
        client.get_bucket_notification_configuration.return_value = {
            'LambdaFunctionConfigurations': [api_config]
        }

        bucket = AmazonBucket(self.module, client)
        config = Config.from_params(
            **{
                'event_name': 'test-id',
                'lambda_function_arn': 'test-arn',
                'lambda_version': 1,
                'events': ['s3:ObjectRemoved:*', 's3:ObjectCreated:*'],
                'prefix': '',
                'suffix': ''
            })
        bucket.apply_config(config)
        assert client.get_bucket_notification_configuration.call_count == 1
        assert client.put_bucket_notification_configuration.call_count == 1
        client.put_bucket_notification_configuration.assert_called_with(
            Bucket='test-bucket',
            NotificationConfiguration={
                'LambdaFunctionConfigurations': [{
                    'Id':
                    'test-id',
                    'LambdaFunctionArn':
                    'test-arn:1',
                    'Events': ['s3:ObjectCreated:*', 's3:ObjectRemoved:*'],
                    'Filter': {
                        'Key': {
                            'FilterRules': [{
                                'Name': 'Prefix',
                                'Value': ''
                            }, {
                                'Name': 'Suffix',
                                'Value': ''
                            }]
                        }
                    }
                }]
            })
Ejemplo n.º 4
0
 def test_apply_invalid_config(self):
     client = MagicMock()
     client.get_bucket_notification_configuration.return_value = {
         'LambdaFunctionConfigurations': []
     }
     client.put_bucket_notification_configuration.side_effect = AnsibleFailJson(
         {}, '')
     bucket = AmazonBucket(self.module, client)
     config = Config.from_params(
         **{
             'event_name': 'test_event',
             'lambda_function_arn': 'lambda_arn',
             'lambda_version': 1,
             'events': ['s3:ObjectRemoved:*', 's3:ObjectCreated:*'],
             'prefix': '',
             'suffix': ''
         })
     with pytest.raises(AnsibleFailJson):
         bucket.apply_config(config)
Ejemplo n.º 5
0
    def test_apply_config(self):
        client = MagicMock()
        client.get_bucket_notification_configuration.return_value = {
            'LambdaFunctionConfigurations': []
        }

        bucket = AmazonBucket(self.module, client)
        config = Config.from_params(
            **{
                'event_name': 'test_event',
                'lambda_function_arn': 'lambda_arn',
                'lambda_version': 1,
                'events': ['s3:ObjectRemoved:*', 's3:ObjectCreated:*'],
                'prefix': '',
                'suffix': ''
            })
        bucket.apply_config(config)
        assert client.get_bucket_notification_configuration.call_count == 1
        assert client.put_bucket_notification_configuration.call_count == 1
Ejemplo n.º 6
0
 def test_delete_config(self):
     api_config = {
         'Id': 'test-id',
         'LambdaFunctionArn': 'test-arn',
         'Events': [],
         'Filter': {
             'Key': {
                 'FilterRules': [{
                     'Name': 'Prefix',
                     'Value': ''
                 }, {
                     'Name': 'Suffix',
                     'Value': ''
                 }]
             }
         }
     }
     client = MagicMock()
     client.get_bucket_notification_configuration.return_value = {
         'LambdaFunctionConfigurations': [api_config]
     }
     bucket = AmazonBucket(client, 'test-bucket')
     config = Config.from_params(
         **{
             'event_name': 'test-id',
             'lambda_function_arn': 'lambda_arn',
             'lambda_version': 1,
             'events': [],
             'prefix': '',
             'suffix': ''
         })
     bucket.delete_config(config)
     assert client.get_bucket_notification_configuration.call_count == 1
     assert client.put_bucket_notification_configuration.call_count == 1
     client.put_bucket_notification_configuration.assert_called_with(
         Bucket='test-bucket',
         NotificationConfiguration={'LambdaFunctionConfigurations': []})