Fixed #27132 -- Allowed testing MemcachedCache and PyLibMCCache during the same test run.
This commit is contained in:
parent
cfd1f93d55
commit
047c1d48a6
|
@ -1142,21 +1142,18 @@ class LocMemCacheTests(BaseCacheTests, TestCase):
|
||||||
# To check the memcached backend, the test settings file will
|
# To check the memcached backend, the test settings file will
|
||||||
# need to contain at least one cache backend setting that points at
|
# need to contain at least one cache backend setting that points at
|
||||||
# your memcache server.
|
# your memcache server.
|
||||||
memcached_params = {}
|
configured_caches = {}
|
||||||
for _cache_params in settings.CACHES.values():
|
for _cache_params in settings.CACHES.values():
|
||||||
if _cache_params['BACKEND'].startswith('django.core.cache.backends.memcached.'):
|
configured_caches[_cache_params['BACKEND']] = _cache_params
|
||||||
memcached_params = _cache_params
|
|
||||||
|
MemcachedCache_params = configured_caches.get('django.core.cache.backends.memcached.MemcachedCache')
|
||||||
|
PyLibMCCache_params = configured_caches.get('django.core.cache.backends.memcached.PyLibMCCache')
|
||||||
|
|
||||||
# The memcached backends don't support cull-related options like `MAX_ENTRIES`.
|
# The memcached backends don't support cull-related options like `MAX_ENTRIES`.
|
||||||
memcached_excluded_caches = {'cull', 'zero_cull'}
|
memcached_excluded_caches = {'cull', 'zero_cull'}
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(memcached_params, "memcached not available")
|
class BaseMemcachedTests(BaseCacheTests):
|
||||||
@override_settings(CACHES=caches_setting_for_tests(
|
|
||||||
base=memcached_params,
|
|
||||||
exclude=memcached_excluded_caches,
|
|
||||||
))
|
|
||||||
class MemcachedCacheTests(BaseCacheTests, TestCase):
|
|
||||||
|
|
||||||
def test_invalid_key_characters(self):
|
def test_invalid_key_characters(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1177,36 +1174,24 @@ class MemcachedCacheTests(BaseCacheTests, TestCase):
|
||||||
with self.assertRaises(Exception):
|
with self.assertRaises(Exception):
|
||||||
cache.set('a' * 251, 'value')
|
cache.set('a' * 251, 'value')
|
||||||
|
|
||||||
# Explicitly display a skipped test if no configured cache uses MemcachedCache
|
|
||||||
@unittest.skipUnless(
|
|
||||||
memcached_params.get('BACKEND') == 'django.core.cache.backends.memcached.MemcachedCache',
|
|
||||||
"cache with python-memcached library not available")
|
|
||||||
def test_memcached_uses_highest_pickle_version(self):
|
|
||||||
# Regression test for #19810
|
|
||||||
for cache_key, cache_config in settings.CACHES.items():
|
|
||||||
if cache_config['BACKEND'] == 'django.core.cache.backends.memcached.MemcachedCache':
|
|
||||||
self.assertEqual(caches[cache_key]._cache.pickleProtocol,
|
|
||||||
pickle.HIGHEST_PROTOCOL)
|
|
||||||
|
|
||||||
@override_settings(CACHES=caches_setting_for_tests(
|
|
||||||
base=memcached_params,
|
|
||||||
exclude=memcached_excluded_caches,
|
|
||||||
TIMEOUT=None,
|
|
||||||
))
|
|
||||||
def test_default_never_expiring_timeout(self):
|
def test_default_never_expiring_timeout(self):
|
||||||
# Regression test for #22845
|
# Regression test for #22845
|
||||||
cache.set('infinite_foo', 'bar')
|
with self.settings(CACHES=caches_setting_for_tests(
|
||||||
self.assertEqual(cache.get('infinite_foo'), 'bar')
|
base=self.base_params,
|
||||||
|
exclude=memcached_excluded_caches,
|
||||||
|
TIMEOUT=None)):
|
||||||
|
cache.set('infinite_foo', 'bar')
|
||||||
|
self.assertEqual(cache.get('infinite_foo'), 'bar')
|
||||||
|
|
||||||
@override_settings(CACHES=caches_setting_for_tests(
|
|
||||||
base=memcached_params,
|
|
||||||
exclude=memcached_excluded_caches,
|
|
||||||
TIMEOUT=31536000, # 60*60*24*365, 1 year
|
|
||||||
))
|
|
||||||
def test_default_far_future_timeout(self):
|
def test_default_far_future_timeout(self):
|
||||||
# Regression test for #22845
|
# Regression test for #22845
|
||||||
cache.set('future_foo', 'bar')
|
with self.settings(CACHES=caches_setting_for_tests(
|
||||||
self.assertEqual(cache.get('future_foo'), 'bar')
|
base=self.base_params,
|
||||||
|
exclude=memcached_excluded_caches,
|
||||||
|
# 60*60*24*365, 1 year
|
||||||
|
TIMEOUT=31536000)):
|
||||||
|
cache.set('future_foo', 'bar')
|
||||||
|
self.assertEqual(cache.get('future_foo'), 'bar')
|
||||||
|
|
||||||
def test_cull(self):
|
def test_cull(self):
|
||||||
# culling isn't implemented, memcached deals with it.
|
# culling isn't implemented, memcached deals with it.
|
||||||
|
@ -1235,6 +1220,29 @@ class MemcachedCacheTests(BaseCacheTests, TestCase):
|
||||||
self.assertTrue(value is None or value == large_value)
|
self.assertTrue(value is None or value == large_value)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipUnless(MemcachedCache_params, "MemcachedCache backend not configured")
|
||||||
|
@override_settings(CACHES=caches_setting_for_tests(
|
||||||
|
base=MemcachedCache_params,
|
||||||
|
exclude=memcached_excluded_caches,
|
||||||
|
))
|
||||||
|
class MemcachedCacheTests(BaseMemcachedTests, TestCase):
|
||||||
|
base_params = MemcachedCache_params
|
||||||
|
|
||||||
|
def test_memcached_uses_highest_pickle_version(self):
|
||||||
|
# Regression test for #19810
|
||||||
|
for cache_key, cache_config in settings.CACHES.items():
|
||||||
|
self.assertEqual(caches[cache_key]._cache.pickleProtocol, pickle.HIGHEST_PROTOCOL)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipUnless(PyLibMCCache_params, "PyLibMCCache backend not configured")
|
||||||
|
@override_settings(CACHES=caches_setting_for_tests(
|
||||||
|
base=PyLibMCCache_params,
|
||||||
|
exclude=memcached_excluded_caches,
|
||||||
|
))
|
||||||
|
class PyLibMCCacheTests(BaseMemcachedTests, TestCase):
|
||||||
|
base_params = PyLibMCCache_params
|
||||||
|
|
||||||
|
|
||||||
@override_settings(CACHES=caches_setting_for_tests(
|
@override_settings(CACHES=caches_setting_for_tests(
|
||||||
BACKEND='django.core.cache.backends.filebased.FileBasedCache',
|
BACKEND='django.core.cache.backends.filebased.FileBasedCache',
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in New Issue