Optimized some cache tests with set_many().
@@ -92,10 +92,7 @@ class DummyCacheTests(SimpleTestCase):
def test_get_many(self):
"get_many returns nothing for the dummy cache backend"
- cache.set('a', 'a')
- cache.set('b', 'b')
- cache.set('c', 'c')
- cache.set('d', 'd')
+ cache.set_many({'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd'})
self.assertEqual(cache.get_many(['a', 'c', 'd']), {})
self.assertEqual(cache.get_many(['a', 'b', 'e']), {})
@@ -105,8 +102,7 @@ class DummyCacheTests(SimpleTestCase):
def test_delete(self):
"Cache deletion is transparently ignored on the dummy cache backend"
- cache.set("key1", "spam")
- cache.set("key2", "eggs")
+ cache.set_many({'key1': 'spam', 'key2': 'eggs'})
self.assertIsNone(cache.get("key1"))
cache.delete("key1")
self.assertIsNone(cache.get("key1"))
@@ -306,18 +302,14 @@ class BaseCacheTests:
def test_get_many(self):
# Multiple cache keys can be returned using get_many
- cache.set('a', 'a')
- cache.set('b', 'b')
- cache.set('c', 'c')
- cache.set('d', 'd')
+ cache.set_many({'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd'})
self.assertEqual(cache.get_many(['a', 'c', 'd']), {'a': 'a', 'c': 'c', 'd': 'd'})
self.assertEqual(cache.get_many(['a', 'b', 'e']), {'a': 'a', 'b': 'b'})
self.assertEqual(cache.get_many(iter(['a', 'b', 'e'])), {'a': 'a', 'b': 'b'})
def test_delete(self):
# Cache keys can be deleted
- cache.set("key1", "spam")
- cache.set("key2", "eggs")
+ cache.set_many({'key1': 'spam', 'key2': 'eggs'})
self.assertEqual(cache.get("key1"), "spam")
cache.delete("key1")
self.assertIsNone(cache.get("key1"))
@@ -521,9 +513,7 @@ class BaseCacheTests:
def test_delete_many(self):
# Multiple keys can be deleted using delete_many
- cache.set("key1", "spam")
- cache.set("key2", "eggs")
- cache.set("key3", "ham")
+ cache.set_many({'key1': 'spam', 'key2': 'eggs', 'key3': 'ham'})
cache.delete_many(["key1", "key2"])
self.assertIsNone(cache.get("key1"))
self.assertIsNone(cache.get("key2"))
@@ -531,8 +521,7 @@ class BaseCacheTests:
def test_clear(self):
# The cache can be emptied using clear
- cache.set("key1", "spam")
- cache.set("key2", "eggs")
+ cache.set_many({'key1': 'spam', 'key2': 'eggs'})
cache.clear()
self.assertIsNone(cache.get("key1"))
self.assertIsNone(cache.get("key2"))
