Ticket #15863: test-cache-middleware-unpickable-objects.diff
File test-cache-middleware-unpickable-objects.diff, 2.3 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/cache/tests.py
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index c5349d5..d33b9ac 100644
a b class DummyCacheTests(unittest.TestCase): 165 165 class BaseCacheTests(object): 166 166 # A common set of tests to apply to all cache backends 167 167 168 def _get_request_cache(self, path): 169 request = HttpRequest() 170 request.META = { 171 'SERVER_NAME': 'testserver', 172 'SERVER_PORT': 80, 173 } 174 request.path = request.path_info = path 175 request._cache_update_cache = True 176 request.method = 'GET' 177 return request 178 168 179 def test_simple(self): 169 180 # Simple cache set/get works 170 181 self.cache.set("key", "value") … … class BaseCacheTests(object): 724 735 self.assertEqual(self.custom_key_cache.get('answer2'), 42) 725 736 self.assertEqual(self.custom_key_cache2.get('answer2'), 42) 726 737 738 def test_cache_write_unpickable_object(self): 739 update_middleware = UpdateCacheMiddleware() 740 update_middleware.cache = self.cache 741 742 fetch_middleware = FetchFromCacheMiddleware() 743 fetch_middleware.cache = self.cache 744 745 request = self._get_request_cache('/cache/test') 746 get_cache_data = FetchFromCacheMiddleware().process_request(request) 747 self.assertEqual(get_cache_data, None) 748 749 response = HttpResponse() 750 content = 'Testing cookie serialization.' 751 response.content = content 752 response.set_cookie('foo', 'bar') 753 754 update_middleware.process_response(request, response) 755 756 get_cache_data = fetch_middleware.process_request(request) 757 self.assertNotEqual(get_cache_data, None) 758 self.assertEqual(get_cache_data.content, content) 759 self.assertEqual(get_cache_data.cookies, response.cookies) 760 761 update_middleware.process_response(request, get_cache_data) 762 get_cache_data = fetch_middleware.process_request(request) 763 self.assertNotEqual(get_cache_data, None) 764 self.assertEqual(get_cache_data.content, content) 765 self.assertEqual(get_cache_data.cookies, response.cookies) 766 727 767 def custom_key_func(key, key_prefix, version): 728 768 "A customized cache key function" 729 769 return 'CUSTOM-' + '-'.join([key_prefix, str(version), key])