summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEd Morley <emorley@mozilla.com>2016-08-31 13:12:40 +0100
committerTim Graham <timograham@gmail.com>2016-08-31 12:50:14 -0400
commit65ec8fa8ca56a5378345375e1079025c96d0b833 (patch)
treed803828eb0106f89ee909dfe7c0b69f953b280e6 /tests
parent1d54fb4483f034d2dced86f1b012671c8ee6ef5d (diff)
Fixed #20892 -- Allowed configuring memcached client using OPTIONS.
Previously, the MemcachedCache backend ignored `OPTIONS` and PyLibMCCache used them to set pylibmc behaviors. Both backends now pass `OPTIONS` as keyword arguments to the client constructors.
Diffstat (limited to 'tests')
-rw-r--r--tests/cache/tests.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 1de1f01490..c5fb42f476 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -40,6 +40,7 @@ from django.utils.cache import (
get_cache_key, learn_cache_key, patch_cache_control,
patch_response_headers, patch_vary_headers,
)
+from django.utils.deprecation import RemovedInDjango21Warning
from django.utils.encoding import force_text
from django.views.decorators.cache import cache_page
@@ -1241,6 +1242,14 @@ class MemcachedCacheTests(BaseMemcachedTests, TestCase):
for cache_key in settings.CACHES:
self.assertEqual(caches[cache_key]._cache.pickleProtocol, pickle.HIGHEST_PROTOCOL)
+ @override_settings(CACHES=caches_setting_for_tests(
+ base=MemcachedCache_params,
+ exclude=memcached_excluded_caches,
+ OPTIONS={'server_max_value_length': 9999},
+ ))
+ def test_memcached_options(self):
+ self.assertEqual(cache._cache.server_max_value_length, 9999)
+
@unittest.skipUnless(PyLibMCCache_params, "PyLibMCCache backend not configured")
@override_settings(CACHES=caches_setting_for_tests(
@@ -1259,6 +1268,36 @@ class PyLibMCCacheTests(BaseMemcachedTests, TestCase):
def test_invalid_key_characters(self):
pass
+ @override_settings(CACHES=caches_setting_for_tests(
+ base=PyLibMCCache_params,
+ exclude=memcached_excluded_caches,
+ OPTIONS={
+ 'binary': True,
+ 'behaviors': {'tcp_nodelay': True},
+ },
+ ))
+ def test_pylibmc_options(self):
+ self.assertTrue(cache._cache.binary)
+ self.assertEqual(cache._cache.behaviors['tcp_nodelay'], int(True))
+
+ @override_settings(CACHES=caches_setting_for_tests(
+ base=PyLibMCCache_params,
+ exclude=memcached_excluded_caches,
+ OPTIONS={'tcp_nodelay': True},
+ ))
+ def test_pylibmc_legacy_options(self):
+ deprecation_message = (
+ "Specifying pylibmc cache behaviors as a top-level property "
+ "within `OPTIONS` is deprecated. Move `tcp_nodelay` into a dict named "
+ "`behaviors` inside `OPTIONS` instead."
+ )
+ with warnings.catch_warnings(record=True) as warns:
+ warnings.simplefilter("always")
+ self.assertEqual(cache._cache.behaviors['tcp_nodelay'], int(True))
+ self.assertEqual(len(warns), 1)
+ self.assertIsInstance(warns[0].message, RemovedInDjango21Warning)
+ self.assertEqual(str(warns[0].message), deprecation_message)
+
@override_settings(CACHES=caches_setting_for_tests(
BACKEND='django.core.cache.backends.filebased.FileBasedCache',