summaryrefslogtreecommitdiff
path: root/tests/cache
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2020-08-20 17:18:25 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-08-24 09:33:55 +0200
commit9e04b242eedc42d8d77431ef71ffa5f23eadacdb (patch)
treee0379bb2726b9e815324378e6336220f11296ee7 /tests/cache
parent7ca42974ee087a82b6f7f6874ca2b25e42a9a584 (diff)
Refs #31907 -- Added cache key validation tests for cache operations.
Diffstat (limited to 'tests/cache')
-rw-r--r--tests/cache/tests.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 60a4ce51bb..260717c0b6 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -650,10 +650,23 @@ class BaseCacheTests:
old_func = cache.key_func
cache.key_func = func
+ tests = [
+ ('add', [key, 1]),
+ ('get', [key]),
+ ('set', [key, 1]),
+ ('incr', [key]),
+ ('decr', [key]),
+ ('delete', [key]),
+ ('get_many', [[key, 'b']]),
+ ('set_many', [{key: 1, 'b': 2}]),
+ ('delete_many', [{key: 1, 'b': 2}]),
+ ]
try:
- with self.assertWarns(CacheKeyWarning) as cm:
- cache.set(key, 'value')
- self.assertEqual(str(cm.warning), expected_warning)
+ for operation, args in tests:
+ with self.subTest(operation=operation):
+ with self.assertWarns(CacheKeyWarning) as cm:
+ getattr(cache, operation)(*args)
+ self.assertEqual(str(cm.warning), expected_warning)
finally:
cache.key_func = old_func
@@ -1291,9 +1304,19 @@ class BaseMemcachedTests(BaseCacheTests):
key.
"""
msg = expected_warning.replace(key, cache.make_key(key))
- with self.assertRaises(InvalidCacheKey) as cm:
- cache.set(key, 'value')
- self.assertEqual(str(cm.exception), msg)
+ tests = [
+ ('add', [key, 1]),
+ ('set', [key, 1]),
+ ('incr', [key]),
+ ('decr', [key]),
+ ('get_many', [[key, 'b']]),
+ ('set_many', [{key: 1, 'b': 2}]),
+ ]
+ for operation, args in tests:
+ with self.subTest(operation=operation):
+ with self.assertRaises(InvalidCacheKey) as cm:
+ getattr(cache, operation)(*args)
+ self.assertEqual(str(cm.exception), msg)
def test_default_never_expiring_timeout(self):
# Regression test for #22845