Skip to content

Instantly share code, notes, and snippets.

@joshourisman
Created September 15, 2011 20:51
Show Gist options
  • Save joshourisman/1220450 to your computer and use it in GitHub Desktop.
Save joshourisman/1220450 to your computer and use it in GitHub Desktop.
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