Ticket #15863: ticket_15863.diff
File ticket_15863.diff, 3.0 KB (added by , 13 years ago) |
---|
-
django/http/__init__.py
diff -r b33d4705456a django/http/__init__.py
a b 587 587 def __getitem__(self, header): 588 588 return self._headers[header.lower()][1] 589 589 590 def __getstate__(self): 591 # SimpleCookie is not pickeable with pickle.HIGHEST_PROTOCOL, so we 592 # serialise to a string instead 593 state = self.__dict__.copy() 594 state['cookies'] = str(state['cookies']) 595 return state 596 597 def __setstate__(self, state): 598 self.__dict__.update(state) 599 self.cookies = SimpleCookie(self.cookies) 600 590 601 def has_header(self, header): 591 602 """Case-insensitive check for a header.""" 592 603 return header.lower() in self._headers -
tests/regressiontests/cache/tests.py
diff -r b33d4705456a tests/regressiontests/cache/tests.py
a b 176 176 class BaseCacheTests(object): 177 177 # A common set of tests to apply to all cache backends 178 178 179 def _get_request_cache(self, path): 180 request = HttpRequest() 181 request.META = { 182 'SERVER_NAME': 'testserver', 183 'SERVER_PORT': 80, 184 } 185 request.path = request.path_info = path 186 request._cache_update_cache = True 187 request.method = 'GET' 188 return request 189 179 190 def test_simple(self): 180 191 # Simple cache set/get works 181 192 self.cache.set("key", "value") … … 741 752 self.assertEqual(self.custom_key_cache2.get('answer2'), 42) 742 753 743 754 755 def test_cache_write_unpickable_object(self): 756 update_middleware = UpdateCacheMiddleware() 757 update_middleware.cache = self.cache 758 759 fetch_middleware = FetchFromCacheMiddleware() 760 fetch_middleware.cache = self.cache 761 762 request = self._get_request_cache('/cache/test') 763 get_cache_data = FetchFromCacheMiddleware().process_request(request) 764 self.assertEqual(get_cache_data, None) 765 766 response = HttpResponse() 767 content = 'Testing cookie serialization.' 768 response.content = content 769 response.set_cookie('foo', 'bar') 770 771 update_middleware.process_response(request, response) 772 773 get_cache_data = fetch_middleware.process_request(request) 774 self.assertNotEqual(get_cache_data, None) 775 self.assertEqual(get_cache_data.content, content) 776 self.assertEqual(get_cache_data.cookies, response.cookies) 777 778 update_middleware.process_response(request, get_cache_data) 779 get_cache_data = fetch_middleware.process_request(request) 780 self.assertNotEqual(get_cache_data, None) 781 self.assertEqual(get_cache_data.content, content) 782 self.assertEqual(get_cache_data.cookies, response.cookies) 783 744 784 def custom_key_func(key, key_prefix, version): 745 785 "A customized cache key function" 746 786 return 'CUSTOM-' + '-'.join([key_prefix, str(version), key])