Example #1
0
    def test_get_client_time_to_live_called(
        self,
        mock_set_table_ttl,
        mock_validate_ttl_methods,
        mock_get_or_create_table,
        mock_boto_client,
    ):
        backend = DynamoDBBackend(
            app=self.app, url='dynamodb://*****:*****@test?ttl_seconds=30')
        backend._get_client()

        mock_validate_ttl_methods.assert_called_once()
        mock_set_table_ttl.assert_called_once()
Example #2
0
 def test_get_client_local(self):
     table_creation_path = \
         'celery.backends.dynamodb.DynamoDBBackend._get_or_create_table'
     with patch('boto3.client') as mock_boto_client, \
             patch(table_creation_path):
         backend = DynamoDBBackend(app=self.app,
                                   url='dynamodb://@localhost:8000')
         client = backend._get_client()
         assert backend.client is client
         mock_boto_client.assert_called_once_with(
             'dynamodb',
             endpoint_url='http://localhost:8000',
             region_name='us-east-1')
         assert backend.endpoint_url == 'http://localhost:8000'
Example #3
0
 def test_get_client_credentials(self):
     table_creation_path = \
         'celery.backends.dynamodb.DynamoDBBackend._get_or_create_table'
     with patch('boto3.client') as mock_boto_client, \
             patch(table_creation_path):
         backend = DynamoDBBackend(app=self.app,
                                   url='dynamodb://*****:*****@test')
         client = backend._get_client()
         assert client is backend.client
         mock_boto_client.assert_called_once_with(
             'dynamodb',
             aws_access_key_id='key',
             aws_secret_access_key='secret',
             region_name='test')
         assert backend.aws_region == 'test'
Example #4
0
 def test_init_no_boto3(self):
     prev, module.boto3 = module.boto3, None
     try:
         with pytest.raises(ImproperlyConfigured):
             DynamoDBBackend(app=self.app)
     finally:
         module.boto3 = prev
Example #5
0
    def test_get_client_explicit_endpoint(self):
        table_creation_path = \
            'celery.backends.dynamodb.DynamoDBBackend._get_or_create_table'
        with patch('boto3.client') as mock_boto_client, \
                patch(table_creation_path):

            self.app.conf.dynamodb_endpoint_url = 'http://my.domain.com:666'
            backend = DynamoDBBackend(app=self.app,
                                      url='dynamodb://@us-east-1')
            client = backend._get_client()
            assert backend.client is client
            mock_boto_client.assert_called_once_with(
                'dynamodb',
                endpoint_url='http://my.domain.com:666',
                region_name='us-east-1')
            assert backend.endpoint_url == 'http://my.domain.com:666'
Example #6
0
 def test_get_client_local(self):
     table_creation_path = \
         'celery.backends.dynamodb.DynamoDBBackend._get_or_create_table'
     with patch('boto3.client') as mock_boto_client, \
             patch(table_creation_path):
         backend = DynamoDBBackend(
             app=self.app,
             url='dynamodb://@localhost:8000'
         )
         client = backend._get_client()
         assert backend.client is client
         mock_boto_client.assert_called_once_with(
             'dynamodb',
             endpoint_url='http://localhost:8000',
             region_name='us-east-1'
         )
         assert backend.endpoint_url == 'http://localhost:8000'
Example #7
0
 def test_get_client_credentials(self):
     table_creation_path = \
         'celery.backends.dynamodb.DynamoDBBackend._get_or_create_table'
     with patch('boto3.client') as mock_boto_client, \
             patch(table_creation_path):
         backend = DynamoDBBackend(
             app=self.app,
             url='dynamodb://*****:*****@test'
         )
         client = backend._get_client()
         assert client is backend.client
         mock_boto_client.assert_called_once_with(
             'dynamodb',
             aws_access_key_id='key',
             aws_secret_access_key='secret',
             region_name='test'
         )
         assert backend.aws_region == 'test'
Example #8
0
    def test_get_client_explicit_endpoint(self):
        table_creation_path = \
            'celery.backends.dynamodb.DynamoDBBackend._get_or_create_table'
        with patch('boto3.client') as mock_boto_client, \
                patch(table_creation_path):

            self.app.conf.dynamodb_endpoint_url = 'http://my.domain.com:666'
            backend = DynamoDBBackend(
                app=self.app,
                url='dynamodb://@us-east-1'
            )
            client = backend._get_client()
            assert backend.client is client
            mock_boto_client.assert_called_once_with(
                'dynamodb',
                endpoint_url='http://my.domain.com:666',
                region_name='us-east-1'
            )
            assert backend.endpoint_url == 'http://my.domain.com:666'
Example #9
0
 def test_init_aws_credentials(self):
     with pytest.raises(ImproperlyConfigured):
         DynamoDBBackend(
             app=self.app,
             url='dynamodb://a:@'
         )
Example #10
0
 def test_init_invalid_ttl_seconds_raises(self):
     with pytest.raises(ValueError):
         DynamoDBBackend(app=self.app, url='dynamodb://@?ttl_seconds=1d')