summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook.git@proton.me>2023-01-01 12:40:47 -0600
committerJordan Cook <jordan.cook.git@proton.me>2023-01-13 14:22:31 -0600
commit9c4f76744a764f8898e5735d838f929c277821c0 (patch)
tree911e03121980c25eafdd8dbd95a82a2308e85514 /tests
parent87ccbd2a03297121aee5f86d007f929f49ca7a1a (diff)
downloadrequests-cache-9c4f76744a764f8898e5735d838f929c277821c0.tar.gz
Set default serializers for each backend using param defaults instead of 'default_serializer' class attributes
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/base_cache_test.py1
-rw-r--r--tests/integration/base_storage_test.py9
-rw-r--r--tests/integration/test_dynamodb.py8
-rw-r--r--tests/integration/test_filesystem.py1
-rw-r--r--tests/integration/test_mongodb.py1
-rw-r--r--tests/integration/test_redis.py1
6 files changed, 7 insertions, 14 deletions
diff --git a/tests/integration/base_cache_test.py b/tests/integration/base_cache_test.py
index 385e8fe..cdc3a98 100644
--- a/tests/integration/base_cache_test.py
+++ b/tests/integration/base_cache_test.py
@@ -48,7 +48,6 @@ class BaseCacheTest:
def init_session(self, cache_name=CACHE_NAME, clear=True, **kwargs) -> CachedSession:
kwargs = {**self.init_kwargs, **kwargs}
kwargs.setdefault('allowable_methods', ALL_METHODS)
- kwargs.setdefault('serializer', 'pickle')
backend = self.backend_class(cache_name, **kwargs)
if clear:
backend.clear()
diff --git a/tests/integration/base_storage_test.py b/tests/integration/base_storage_test.py
index 4070492..a96ffd9 100644
--- a/tests/integration/base_storage_test.py
+++ b/tests/integration/base_storage_test.py
@@ -19,7 +19,6 @@ class BaseStorageTest:
def init_cache(self, cache_name=CACHE_NAME, index=0, clear=True, **kwargs):
kwargs = {**self.init_kwargs, **kwargs}
- kwargs.setdefault('serializer', 'pickle')
cache = self.storage_class(cache_name, f'table_{index}', **kwargs)
if clear:
cache.clear()
@@ -136,8 +135,8 @@ class BaseStorageTest:
cache_2 = self.init_cache(connection=getattr(cache_1, 'connection', None))
for i in range(5):
- cache_1[i] = i
- cache_2[i] = i
+ cache_1[i] = f'value_{i}'
+ cache_2[i] = f'value_{i}'
assert len(cache_1) == len(cache_2) == 5
cache_1.clear()
@@ -147,8 +146,8 @@ class BaseStorageTest:
def test_same_settings(self):
cache_1 = self.init_cache()
cache_2 = self.init_cache(connection=getattr(cache_1, 'connection', None))
- cache_1['key_1'] = 1
- cache_2['key_2'] = 2
+ cache_1['key_1'] = 'value_1'
+ cache_2['key_2'] = 'value_2'
assert cache_1 == cache_2
def test_str(self):
diff --git a/tests/integration/test_dynamodb.py b/tests/integration/test_dynamodb.py
index 561c979..42e22eb 100644
--- a/tests/integration/test_dynamodb.py
+++ b/tests/integration/test_dynamodb.py
@@ -15,10 +15,6 @@ AWS_OPTIONS = {
'aws_access_key_id': 'placeholder',
'aws_secret_access_key': 'placeholder',
}
-DYNAMODB_OPTIONS = {
- **AWS_OPTIONS,
- 'serializer': None, # Use class default serializer
-}
@pytest.fixture(scope='module', autouse=True)
@@ -33,7 +29,7 @@ def ensure_connection():
class TestDynamoDbDict(BaseStorageTest):
storage_class = DynamoDbDict
- init_kwargs = DYNAMODB_OPTIONS
+ init_kwargs = AWS_OPTIONS
@patch('requests_cache.backends.dynamodb.boto3.resource')
def test_connection_kwargs(self, mock_resource):
@@ -87,4 +83,4 @@ class TestDynamoDbDict(BaseStorageTest):
class TestDynamoDbCache(BaseCacheTest):
backend_class = DynamoDbCache
- init_kwargs = DYNAMODB_OPTIONS
+ init_kwargs = AWS_OPTIONS
diff --git a/tests/integration/test_filesystem.py b/tests/integration/test_filesystem.py
index dfe9414..99625c4 100644
--- a/tests/integration/test_filesystem.py
+++ b/tests/integration/test_filesystem.py
@@ -39,7 +39,6 @@ class TestFileDict(BaseStorageTest):
rmtree(CACHE_NAME, ignore_errors=True)
def init_cache(self, index=0, clear=True, **kwargs):
- kwargs.setdefault('serializer', 'pickle')
cache = FileDict(f'{CACHE_NAME}_{index}', use_temp=True, **kwargs)
if clear:
cache.clear()
diff --git a/tests/integration/test_mongodb.py b/tests/integration/test_mongodb.py
index 4a3a114..1dfae87 100644
--- a/tests/integration/test_mongodb.py
+++ b/tests/integration/test_mongodb.py
@@ -51,7 +51,6 @@ class TestMongoDict(BaseStorageTest):
class TestMongoCache(BaseCacheTest):
backend_class = MongoCache
- init_kwargs = {'serializer': None} # Use class default serializer instead of pickle
def test_ttl(self):
session = self.init_session()
diff --git a/tests/integration/test_redis.py b/tests/integration/test_redis.py
index 4c74d68..2a34899 100644
--- a/tests/integration/test_redis.py
+++ b/tests/integration/test_redis.py
@@ -33,6 +33,7 @@ class TestRedisHashDict(TestRedisDict):
storage_class = RedisHashDict
num_instances: int = 10 # Supports multiple instances, since this stores items under hash keys
picklable = True
+ init_kwargs = {'serializer': 'pickle'}
class TestRedisCache(BaseCacheTest):