diff options
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/base_storage_test.py | 4 | ||||
-rw-r--r-- | tests/integration/test_dynamodb.py | 14 |
2 files changed, 13 insertions, 5 deletions
diff --git a/tests/integration/base_storage_test.py b/tests/integration/base_storage_test.py index a96ffd9..ce881e8 100644 --- a/tests/integration/base_storage_test.py +++ b/tests/integration/base_storage_test.py @@ -135,8 +135,8 @@ class BaseStorageTest: cache_2 = self.init_cache(connection=getattr(cache_1, 'connection', None)) for i in range(5): - cache_1[i] = f'value_{i}' - cache_2[i] = f'value_{i}' + cache_1[f'key_{i}'] = f'value_{i}' + cache_2[f'key_{i}'] = f'value_{i}' assert len(cache_1) == len(cache_2) == 5 cache_1.clear() diff --git a/tests/integration/test_dynamodb.py b/tests/integration/test_dynamodb.py index 42e22eb..af54e67 100644 --- a/tests/integration/test_dynamodb.py +++ b/tests/integration/test_dynamodb.py @@ -5,7 +5,7 @@ from unittest.mock import patch import pytest from requests_cache.backends import DynamoDbCache, DynamoDbDict -from tests.conftest import fail_if_no_connection +from tests.conftest import CACHE_NAME, fail_if_no_connection from tests.integration.base_cache_test import BaseCacheTest from tests.integration.base_storage_test import BaseStorageTest @@ -31,10 +31,18 @@ class TestDynamoDbDict(BaseStorageTest): storage_class = DynamoDbDict init_kwargs = AWS_OPTIONS + def init_cache(self, cache_name=CACHE_NAME, index=0, clear=True, **kwargs): + """For tests that use multiple tables, make index part of the table name""" + kwargs = {**self.init_kwargs, **kwargs} + cache = self.storage_class(f'{cache_name}_{index}', **kwargs) + if clear: + cache.clear() + return cache + @patch('requests_cache.backends.dynamodb.boto3.resource') def test_connection_kwargs(self, mock_resource): """A spot check to make sure optional connection kwargs gets passed to connection""" - DynamoDbDict('test_table', 'namespace', region_name='us-east-2', invalid_kwarg='???') + DynamoDbDict('test_table', region_name='us-east-2', invalid_kwarg='???') mock_resource.assert_called_with('dynamodb', region_name='us-east-2') def test_create_table_error(self): @@ -69,7 +77,7 @@ class TestDynamoDbDict(BaseStorageTest): # 'ttl' is a reserved word, so to retrieve it we need to alias it item = cache._table.get_item( - Key=cache._composite_key('key'), + Key={'key': 'key'}, ProjectionExpression='#t', ExpressionAttributeNames={'#t': 'ttl'}, ) |