Changeset 9224
- Timestamp:
- 10/10/08 16:41:12 (3 months ago)
- Files:
-
- django/trunk/django/contrib/sessions/tests.py (modified) (3 diffs)
- django/trunk/tests/regressiontests/cache/tests.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/sessions/tests.py
r8459 r9224 55 55 >>> DatabaseSession('1').get('cat') 56 56 57 # Do file session tests in an isolated directory, and kill it after we're done. 58 >>> original_session_file_path = settings.SESSION_FILE_PATH 59 >>> import tempfile 60 >>> temp_session_store = settings.SESSION_FILE_PATH = tempfile.mkdtemp() 61 57 62 >>> file_session = FileSession() 58 63 >>> file_session.modified … … 106 111 ImproperlyConfigured: The session storage path '/if/this/directory/exists/you/have/a/weird/computer' doesn't exist. Please set your SESSION_FILE_PATH setting to an existing directory in which Django can store session data. 107 112 113 # Clean up after the file tests 114 >>> settings.SESSION_FILE_PATH = original_session_file_path 115 >>> import shutil 116 >>> shutil.rmtree(temp_session_store) 117 118 # 119 # Cache-based tests 120 # NB: be careful to delete any sessions created; stale sessions fill up the 121 # /tmp and eventually overwhelm it after lots of runs (think buildbots) 122 # 123 108 124 >>> cache_session = CacheSession() 109 125 >>> cache_session.modified … … 145 161 >>> cache_session = CacheSession(cache_session.session_key) 146 162 >>> cache_session.save() 147 >>> CacheSession('1').get('cat')163 >>> cache_session.delete(cache_session.session_key) 148 164 149 165 >>> s = SessionBase() django/trunk/tests/regressiontests/cache/tests.py
r8278 r9224 10 10 import unittest 11 11 12 from django.core.cache import cache 12 from django.core.cache import cache, get_cache 13 13 from django.core.cache.backends.filebased import CacheClass as FileCache 14 14 from django.http import HttpResponse … … 24 24 25 25 class Cache(unittest.TestCase): 26 def setUp(self): 27 # Special-case the file cache so we can clean up after ourselves. 28 if isinstance(cache, FileCache): 29 self.cache_dir = tempfile.mkdtemp() 30 self.cache = get_cache("file:///%s" % self.cache_dir) 31 else: 32 self.cache_dir = None 33 self.cache = cache 34 35 def tearDown(self): 36 if self.cache_dir is not None: 37 shutil.rmtree(self.cache_dir) 38 26 39 def test_simple(self): 27 40 # simple set/get 28 cache.set("key", "value")29 self.assertEqual( cache.get("key"), "value")41 self.cache.set("key", "value") 42 self.assertEqual(self.cache.get("key"), "value") 30 43 31 44 def test_add(self): 32 45 # test add (only add if key isn't already in cache) 33 cache.add("addkey1", "value")34 result = cache.add("addkey1", "newvalue")46 self.cache.add("addkey1", "value") 47 result = self.cache.add("addkey1", "newvalue") 35 48 self.assertEqual(result, False) 36 self.assertEqual( cache.get("addkey1"), "value")49 self.assertEqual(self.cache.get("addkey1"), "value") 37 50 38 51 def test_non_existent(self): 39 52 # get with non-existent keys 40 self.assertEqual( cache.get("does_not_exist"), None)41 self.assertEqual( cache.get("does_not_exist", "bang!"), "bang!")53 self.assertEqual(self.cache.get("does_not_exist"), None) 54 self.assertEqual(self.cache.get("does_not_exist", "bang!"), "bang!") 42 55 43 56 def test_get_many(self): 44 57 # get_many 45 cache.set('a', 'a')46 cache.set('b', 'b')47 cache.set('c', 'c')48 cache.set('d', 'd')49 self.assertEqual( cache.get_many(['a', 'c', 'd']), {'a' : 'a', 'c' : 'c', 'd' : 'd'})50 self.assertEqual( cache.get_many(['a', 'b', 'e']), {'a' : 'a', 'b' : 'b'})58 self.cache.set('a', 'a') 59 self.cache.set('b', 'b') 60 self.cache.set('c', 'c') 61 self.cache.set('d', 'd') 62 self.assertEqual(self.cache.get_many(['a', 'c', 'd']), {'a' : 'a', 'c' : 'c', 'd' : 'd'}) 63 self.assertEqual(self.cache.get_many(['a', 'b', 'e']), {'a' : 'a', 'b' : 'b'}) 51 64 52 65 def test_delete(self): 53 66 # delete 54 cache.set("key1", "spam")55 cache.set("key2", "eggs")56 self.assertEqual( cache.get("key1"), "spam")57 cache.delete("key1")58 self.assertEqual( cache.get("key1"), None)59 self.assertEqual( cache.get("key2"), "eggs")67 self.cache.set("key1", "spam") 68 self.cache.set("key2", "eggs") 69 self.assertEqual(self.cache.get("key1"), "spam") 70 self.cache.delete("key1") 71 self.assertEqual(self.cache.get("key1"), None) 72 self.assertEqual(self.cache.get("key2"), "eggs") 60 73 61 74 def test_has_key(self): 62 75 # has_key 63 cache.set("hello1", "goodbye1")64 self.assertEqual( cache.has_key("hello1"), True)65 self.assertEqual( cache.has_key("goodbye1"), False)76 self.cache.set("hello1", "goodbye1") 77 self.assertEqual(self.cache.has_key("hello1"), True) 78 self.assertEqual(self.cache.has_key("goodbye1"), False) 66 79 67 80 def test_in(self): 68 cache.set("hello2", "goodbye2")69 self.assertEqual("hello2" in cache, True)70 self.assertEqual("goodbye2" in cache, False)81 self.cache.set("hello2", "goodbye2") 82 self.assertEqual("hello2" in self.cache, True) 83 self.assertEqual("goodbye2" in self.cache, False) 71 84 72 85 def test_data_types(self): … … 80 93 'class' : C, 81 94 } 82 cache.set("stuff", stuff)83 self.assertEqual( cache.get("stuff"), stuff)95 self.cache.set("stuff", stuff) 96 self.assertEqual(self.cache.get("stuff"), stuff) 84 97 85 98 def test_expiration(self): 86 cache.set('expire1', 'very quickly', 1)87 cache.set('expire2', 'very quickly', 1)88 cache.set('expire3', 'very quickly', 1)99 self.cache.set('expire1', 'very quickly', 1) 100 self.cache.set('expire2', 'very quickly', 1) 101 self.cache.set('expire3', 'very quickly', 1) 89 102 90 103 time.sleep(2) 91 self.assertEqual( cache.get("expire1"), None)104 self.assertEqual(self.cache.get("expire1"), None) 92 105 93 cache.add("expire2", "newvalue")94 self.assertEqual( cache.get("expire2"), "newvalue")95 self.assertEqual( cache.has_key("expire3"), False)106 self.cache.add("expire2", "newvalue") 107 self.assertEqual(self.cache.get("expire2"), "newvalue") 108 self.assertEqual(self.cache.has_key("expire3"), False) 96 109 97 110 def test_unicode(self): … … 103 116 } 104 117 for (key, value) in stuff.items(): 105 cache.set(key, value)106 self.assertEqual( cache.get(key), value)118 self.cache.set(key, value) 119 self.assertEqual(self.cache.get(key), value) 107 120 108 121 … … 112 125 """ 113 126 def setUp(self): 114 self.dirname = tempfile.mktemp() 115 os.mkdir(self.dirname) 127 self.dirname = tempfile.mkdtemp() 116 128 self.cache = FileCache(self.dirname, {}) 117 129
