Refs #31907 -- Added cache key validation tests for cache operations.
This commit is contained in:
parent
7ca42974ee
commit
9e04b242ee
|
@ -650,9 +650,22 @@ 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:
|
||||
for operation, args in tests:
|
||||
with self.subTest(operation=operation):
|
||||
with self.assertWarns(CacheKeyWarning) as cm:
|
||||
cache.set(key, 'value')
|
||||
getattr(cache, operation)(*args)
|
||||
self.assertEqual(str(cm.warning), expected_warning)
|
||||
finally:
|
||||
cache.key_func = old_func
|
||||
|
@ -1291,8 +1304,18 @@ class BaseMemcachedTests(BaseCacheTests):
|
|||
key.
|
||||
"""
|
||||
msg = expected_warning.replace(key, cache.make_key(key))
|
||||
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:
|
||||
cache.set(key, 'value')
|
||||
getattr(cache, operation)(*args)
|
||||
self.assertEqual(str(cm.exception), msg)
|
||||
|
||||
def test_default_never_expiring_timeout(self):
|
||||
|
|
Loading…
Reference in New Issue