summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook.git@proton.me>2023-01-13 16:08:35 -0600
committerJordan Cook <jordan.cook.git@proton.me>2023-03-01 15:22:07 -0600
commit048b772fa751f860ebe73e268a8719c9bc8bc35c (patch)
treede8960f9c5d3436eacbbe27e891b81d641e8eac4 /tests
parentddacec4f0e3c1a9f16ec4aad44803a0b14224e12 (diff)
downloadrequests-cache-048b772fa751f860ebe73e268a8719c9bc8bc35c.tar.gz
Change DynamoDB table to use cache key as partition key
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/base_storage_test.py4
-rw-r--r--tests/integration/test_dynamodb.py14
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'},
)