1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #15012 -- Added post-rendering callbacks to TemplateResponse so that decorators (in particular, the cache decorator) can defer processing until after rendering has occurred. Thanks to Joshua Ginsberg for the draft patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15295 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2011-01-24 14:24:35 +00:00
parent 3d7afd5d2b
commit 3f528e10d5
9 changed files with 256 additions and 8 deletions

View File

@@ -1,3 +1,4 @@
import time
import unittest
from django.core.exceptions import ImproperlyConfigured
@@ -158,7 +159,7 @@ class TemplateViewTest(TestCase):
def _assert_about(self, response):
response.render()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, '<h1>About</h1>')
self.assertContains(response, '<h1>About</h1>')
def test_get(self):
"""
@@ -197,6 +198,28 @@ class TemplateViewTest(TestCase):
self.assertEqual(response.context['params'], {'foo': 'bar'})
self.assertEqual(response.context['key'], 'value')
def test_cached_views(self):
"""
A template view can be cached
"""
response = self.client.get('/template/cached/bar/')
self.assertEqual(response.status_code, 200)
time.sleep(1.0)
response2 = self.client.get('/template/cached/bar/')
self.assertEqual(response2.status_code, 200)
self.assertEqual(response.content, response2.content)
time.sleep(2.0)
# Let the cache expire and test again
response2 = self.client.get('/template/cached/bar/')
self.assertEqual(response2.status_code, 200)
self.assertNotEqual(response.content, response2.content)
class RedirectViewTest(unittest.TestCase):
rf = RequestFactory()