|
15 | 15 | from django.conf import settings
|
16 | 16 | from django.core import management, signals
|
17 | 17 | from django.core.cache import (
|
18 |
| - DEFAULT_CACHE_ALIAS, CacheKeyWarning, cache, caches, |
| 18 | + DEFAULT_CACHE_ALIAS, CacheKeyWarning, InvalidCacheKey, cache, caches, |
19 | 19 | )
|
20 | 20 | from django.core.cache.utils import make_template_fragment_key
|
21 | 21 | from django.db import close_old_connections, connection, connections
|
@@ -610,10 +610,10 @@ def test_zero_cull(self):
|
610 | 610 |
|
611 | 611 | def _perform_invalid_key_test(self, key, expected_warning):
|
612 | 612 | """
|
613 |
| - All the builtin backends (except memcached, see below) should warn on |
614 |
| - keys that would be refused by memcached. This encourages portable |
615 |
| - caching code without making it too difficult to use production backends |
616 |
| - with more liberal key rules. Refs #6447. |
| 613 | + All the builtin backends should warn (except memcached that should |
| 614 | + error) on keys that would be refused by memcached. This encourages |
| 615 | + portable caching code without making it too difficult to use production |
| 616 | + backends with more liberal key rules. Refs #6447. |
617 | 617 | """
|
618 | 618 | # mimic custom ``make_key`` method being defined since the default will
|
619 | 619 | # never show the below warnings
|
@@ -1256,24 +1256,14 @@ def test_location_multiple_servers(self):
|
1256 | 1256 | with self.settings(CACHES={'default': params}):
|
1257 | 1257 | self.assertEqual(cache._servers, ['server1.tld', 'server2:11211'])
|
1258 | 1258 |
|
1259 |
| - def test_invalid_key_characters(self): |
| 1259 | + def _perform_invalid_key_test(self, key, expected_warning): |
1260 | 1260 | """
|
1261 |
| - On memcached, we don't introduce a duplicate key validation |
1262 |
| - step (for speed reasons), we just let the memcached API |
1263 |
| - library raise its own exception on bad keys. Refs #6447. |
1264 |
| -
|
1265 |
| - In order to be memcached-API-library agnostic, we only assert |
1266 |
| - that a generic exception of some kind is raised. |
| 1261 | + Whilst other backends merely warn, memcached should raise for an |
| 1262 | + invalid key. |
1267 | 1263 | """
|
1268 |
| - # memcached does not allow whitespace or control characters in keys |
1269 |
| - # when using the ascii protocol. |
1270 |
| - with self.assertRaises(Exception): |
1271 |
| - cache.set('key with spaces', 'value') |
1272 |
| - |
1273 |
| - def test_invalid_key_length(self): |
1274 |
| - # memcached limits key length to 250 |
1275 |
| - with self.assertRaises(Exception): |
1276 |
| - cache.set('a' * 251, 'value') |
| 1264 | + msg = expected_warning.replace(key, ':1:%s' % key) |
| 1265 | + with self.assertRaisesMessage(InvalidCacheKey, msg): |
| 1266 | + cache.set(key, 'value') |
1277 | 1267 |
|
1278 | 1268 | def test_default_never_expiring_timeout(self):
|
1279 | 1269 | # Regression test for #22845
|
@@ -1390,15 +1380,6 @@ class PyLibMCCacheTests(BaseMemcachedTests, TestCase):
|
1390 | 1380 | # libmemcached manages its own connections.
|
1391 | 1381 | should_disconnect_on_close = False
|
1392 | 1382 |
|
1393 |
| - # By default, pylibmc/libmemcached don't verify keys client-side and so |
1394 |
| - # this test triggers a server-side bug that causes later tests to fail |
1395 |
| - # (#19914). The `verify_keys` behavior option could be set to True (which |
1396 |
| - # would avoid triggering the server-side bug), however this test would |
1397 |
| - # still fail due to https://github.com/lericson/pylibmc/issues/219. |
1398 |
| - @unittest.skip("triggers a memcached-server bug, causing subsequent tests to fail") |
1399 |
| - def test_invalid_key_characters(self): |
1400 |
| - pass |
1401 |
| - |
1402 | 1383 | @override_settings(CACHES=caches_setting_for_tests(
|
1403 | 1384 | base=PyLibMCCache_params,
|
1404 | 1385 | exclude=memcached_excluded_caches,
|
|
0 commit comments