summaryrefslogtreecommitdiff
path: root/tests/regressiontests/cache
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-01-27 08:21:35 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-01-27 08:21:35 +0000
commit8e8d4b5888b73e5c0b2cfc77be4c6d5898546654 (patch)
tree5f7f6537575ab01e2e4a45d05baa70ef2db5ed2b /tests/regressiontests/cache
parentc6ee1f6f242a6fa5336ce7a670cebae72568ef0c (diff)
Fixed #12671 -- Added set_many(), get_many(), and clear() methods to the cache backend interface. Thanks to Jeff Balogh for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12306 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/cache')
-rw-r--r--tests/regressiontests/cache/tests.py51
1 files changed, 47 insertions, 4 deletions
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index 593b7262aa..86d8ca27e0 100644
--- a/tests/regressiontests/cache/tests.py
+++ b/tests/regressiontests/cache/tests.py
@@ -129,9 +129,24 @@ class DummyCacheTests(unittest.TestCase):
self.cache.set(key, value)
self.assertEqual(self.cache.get(key), None)
+ def test_set_many(self):
+ "set_many does nothing for the dummy cache backend"
+ self.cache.set_many({'a': 1, 'b': 2})
+
+ def test_delete_many(self):
+ "delete_many does nothing for the dummy cache backend"
+ self.cache.delete_many(['a', 'b'])
+
+ def test_clear(self):
+ "clear does nothing for the dummy cache backend"
+ self.cache.clear()
+
class BaseCacheTests(object):
# A common set of tests to apply to all cache backends
+ def tearDown(self):
+ self.cache.clear()
+
def test_simple(self):
# Simple cache set/get works
self.cache.set("key", "value")
@@ -278,6 +293,37 @@ class BaseCacheTests(object):
self.cache.set(key, value)
self.assertEqual(self.cache.get(key), value)
+ def test_set_many(self):
+ # Multiple keys can be set using set_many
+ self.cache.set_many({"key1": "spam", "key2": "eggs"})
+ self.assertEqual(self.cache.get("key1"), "spam")
+ self.assertEqual(self.cache.get("key2"), "eggs")
+
+ def test_set_many_expiration(self):
+ # set_many takes a second ``timeout`` parameter
+ self.cache.set_many({"key1": "spam", "key2": "eggs"}, 1)
+ time.sleep(2)
+ self.assertEqual(self.cache.get("key1"), None)
+ self.assertEqual(self.cache.get("key2"), None)
+
+ def test_delete_many(self):
+ # Multiple keys can be deleted using delete_many
+ self.cache.set("key1", "spam")
+ self.cache.set("key2", "eggs")
+ self.cache.set("key3", "ham")
+ self.cache.delete_many(["key1", "key2"])
+ self.assertEqual(self.cache.get("key1"), None)
+ self.assertEqual(self.cache.get("key2"), None)
+ self.assertEqual(self.cache.get("key3"), "ham")
+
+ def test_clear(self):
+ # The cache can be emptied using clear
+ self.cache.set("key1", "spam")
+ self.cache.set("key2", "eggs")
+ self.cache.clear()
+ self.assertEqual(self.cache.get("key1"), None)
+ self.assertEqual(self.cache.get("key2"), None)
+
class DBCacheTests(unittest.TestCase, BaseCacheTests):
def setUp(self):
management.call_command('createcachetable', 'test_cache_table', verbosity=0, interactive=False)
@@ -286,7 +332,7 @@ class DBCacheTests(unittest.TestCase, BaseCacheTests):
def tearDown(self):
from django.db import connection
cursor = connection.cursor()
- cursor.execute('DROP TABLE test_cache_table');
+ cursor.execute('DROP TABLE test_cache_table')
class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
def setUp(self):
@@ -309,9 +355,6 @@ class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):
self.dirname = tempfile.mkdtemp()
self.cache = get_cache('file://%s' % self.dirname)
- def tearDown(self):
- shutil.rmtree(self.dirname)
-
def test_hashing(self):
"""Test that keys are hashed into subdirectories correctly"""
self.cache.set("foo", "bar")