diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-11-02 05:55:08 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-11-02 05:55:08 +0000 |
| commit | 1fc7c4aee44af3d5c55d3532aa8fb5b2d9102a62 (patch) | |
| tree | 3cc1d1fd473ebbd36e14fd8ebac6de9a5d0df817 /tests | |
| parent | ed51dd5d644428a838861c58cda220a21b1523a8 (diff) | |
Fixed #14596 -- Light refactoring of the cache backends.
* Removes some code duplication,
* Provides a convenient base class for db-like cache backends
* Adds tests for an edge case of culling,
* Marks the memcached tests as "skipped", rather than omitting them.
Thanks to Jonas H for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14434 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/cache/tests.py | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index 9818b03661..da4c9a8e7a 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -410,6 +410,10 @@ class DBCacheTests(unittest.TestCase, BaseCacheTests): def test_cull(self): self.perform_cull_test(50, 29) + def test_zero_cull(self): + self.cache = get_cache('db://%s?max_entries=30&cull_frequency=0' % self._table_name) + self.perform_cull_test(50, 18) + class LocMemCacheTests(unittest.TestCase, BaseCacheTests): def setUp(self): self.cache = get_cache('locmem://?max_entries=30') @@ -417,30 +421,33 @@ class LocMemCacheTests(unittest.TestCase, BaseCacheTests): def test_cull(self): self.perform_cull_test(50, 29) + def test_zero_cull(self): + self.cache = get_cache('locmem://?max_entries=30&cull_frequency=0') + self.perform_cull_test(50, 19) + # memcached backend isn't guaranteed to be available. # To check the memcached backend, the test settings file will # need to contain a CACHE_BACKEND setting that points at # your memcache server. -if settings.CACHE_BACKEND.startswith('memcached://'): - class MemcachedCacheTests(unittest.TestCase, BaseCacheTests): - def setUp(self): - self.cache = get_cache(settings.CACHE_BACKEND) - - def test_invalid_keys(self): - """ - On memcached, we don't introduce a duplicate key validation - step (for speed reasons), we just let the memcached API - library raise its own exception on bad keys. Refs #6447. +class MemcachedCacheTests(unittest.TestCase, BaseCacheTests): + def setUp(self): + self.cache = get_cache(settings.CACHE_BACKEND) - In order to be memcached-API-library agnostic, we only assert - that a generic exception of some kind is raised. + def test_invalid_keys(self): + """ + On memcached, we don't introduce a duplicate key validation + step (for speed reasons), we just let the memcached API + library raise its own exception on bad keys. Refs #6447. - """ - # memcached does not allow whitespace or control characters in keys - self.assertRaises(Exception, self.cache.set, 'key with spaces', 'value') - # memcached limits key length to 250 - self.assertRaises(Exception, self.cache.set, 'a' * 251, 'value') + In order to be memcached-API-library agnostic, we only assert + that a generic exception of some kind is raised. + """ + # memcached does not allow whitespace or control characters in keys + self.assertRaises(Exception, self.cache.set, 'key with spaces', 'value') + # memcached limits key length to 250 + self.assertRaises(Exception, self.cache.set, 'a' * 251, 'value') +MemcachedCacheTests = unittest.skipUnless(settings.CACHE_BACKEND.startswith('memcached://'), "memcached not available")(MemcachedCacheTests) class FileBasedCacheTests(unittest.TestCase, BaseCacheTests): """ |
