Created
September 15, 2011 20:51
-
-
Save joshourisman/1220450 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from django.core.cache import get_cache | |
from django.utils import unittest | |
class CacheTestCase(unittest.TestCase): | |
def setUp(self): | |
self.cache = get_cache('default') | |
def testGet(self): | |
key = 'foo' | |
value = 'bar' | |
self.cache.set(key, value) | |
retrieved_value = self.cache.get(key) | |
self.assertEqual(value, retrieved_value) | |
def testGetMany(self): | |
num_keys = 10000 | |
keys = ['cached-value-%d' % i for i in range(num_keys)] | |
value = json.dumps({ | |
'this': 'is', | |
'a': 'test', | |
'json': 'object', | |
'it': 'has', | |
'a': 'bunch', | |
'of': 'key', | |
'value': 'pairs', | |
}) | |
for key in keys: | |
self.cache.set(key, value) | |
retrieved_value = self.cache.get_many(keys) | |
self.assertEqual(len(retrieved_value), num_keys) | |
for key in keys: | |
self.assertTrue(key in retrieved_value) | |
self.assertEqual(value, retrieved_value[key]) | |
class NewCacheTestCase(CacheTestCase): | |
def setUp(self): | |
self.cache = get_cache('newcache') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment