mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #4845 -- Fixed some problems with Unicode usage and caching. Thanks,
Jeremy Dunck. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5718 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
34
tests/regressiontests/cache/tests.py
vendored
34
tests/regressiontests/cache/tests.py
vendored
@@ -1,3 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Unit tests for cache framework
|
||||
# Uses whatever cache backend is set in the test settings file.
|
||||
|
||||
@@ -19,8 +21,8 @@ class Cache(unittest.TestCase):
|
||||
|
||||
def test_non_existent(self):
|
||||
# get with non-existent keys
|
||||
self.assertEqual(cache.get("does not exist"), None)
|
||||
self.assertEqual(cache.get("does not exist", "bang!"), "bang!")
|
||||
self.assertEqual(cache.get("does_not_exist"), None)
|
||||
self.assertEqual(cache.get("does_not_exist", "bang!"), "bang!")
|
||||
|
||||
def test_get_many(self):
|
||||
# get_many
|
||||
@@ -42,14 +44,14 @@ class Cache(unittest.TestCase):
|
||||
|
||||
def test_has_key(self):
|
||||
# has_key
|
||||
cache.set("hello", "goodbye")
|
||||
self.assertEqual(cache.has_key("hello"), True)
|
||||
self.assertEqual(cache.has_key("goodbye"), False)
|
||||
cache.set("hello1", "goodbye1")
|
||||
self.assertEqual(cache.has_key("hello1"), True)
|
||||
self.assertEqual(cache.has_key("goodbye1"), False)
|
||||
|
||||
def test_in(self):
|
||||
cache.set("hello", "goodbye")
|
||||
self.assertEqual("hello" in cache, True)
|
||||
self.assertEqual("goodbye" in cache, False)
|
||||
cache.set("hello2", "goodbye2")
|
||||
self.assertEqual("hello2" in cache, True)
|
||||
self.assertEqual("goodbye2" in cache, False)
|
||||
|
||||
def test_data_types(self):
|
||||
stuff = {
|
||||
@@ -61,9 +63,6 @@ class Cache(unittest.TestCase):
|
||||
'function' : f,
|
||||
'class' : C,
|
||||
}
|
||||
for (key, value) in stuff.items():
|
||||
cache.set(key, value)
|
||||
self.assertEqual(cache.get(key), value)
|
||||
|
||||
def test_expiration(self):
|
||||
# expiration
|
||||
@@ -71,5 +70,16 @@ class Cache(unittest.TestCase):
|
||||
time.sleep(2)
|
||||
self.assertEqual(cache.get("expire"), None)
|
||||
|
||||
def test_unicode(self):
|
||||
stuff = {
|
||||
u'ascii': u'ascii_value',
|
||||
u'unicode_ascii': u'Iñtërnâtiônàlizætiøn1',
|
||||
u'Iñtërnâtiônàlizætiøn': u'Iñtërnâtiônàlizætiøn2',
|
||||
u'ascii': {u'x' : 1 }
|
||||
}
|
||||
for (key, value) in stuff.items():
|
||||
cache.set(key, value)
|
||||
self.assertEqual(cache.get(key), value)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user