diff -r d197531525b3 tests/regressiontests/generic_views/base.py
a
|
b
|
|
| 1 | import time |
1 | 2 | import unittest |
2 | 3 | |
3 | 4 | from django.core.exceptions import ImproperlyConfigured |
… |
… |
|
158 | 159 | def _assert_about(self, response): |
159 | 160 | response.render() |
160 | 161 | self.assertEqual(response.status_code, 200) |
161 | | self.assertEqual(response.content, '<h1>About</h1>') |
| 162 | self.assertContains(response, '<h1>About</h1>') |
162 | 163 | |
163 | 164 | def test_get(self): |
164 | 165 | """ |
… |
… |
|
197 | 198 | self.assertEqual(response.context['params'], {'foo': 'bar'}) |
198 | 199 | self.assertEqual(response.context['key'], 'value') |
199 | 200 | |
| 201 | def test_cached_views(self): |
| 202 | """ |
| 203 | A template view can be cached |
| 204 | """ |
| 205 | response = self.client.get('/template/cached/bar/') |
| 206 | self.assertEqual(response.status_code, 200) |
| 207 | |
| 208 | time.sleep(0.2) |
| 209 | |
| 210 | response2 = self.client.get('/template/cached/bar/') |
| 211 | self.assertEqual(response2.status_code, 200) |
| 212 | |
| 213 | self.assertEqual(response.content, response2.content) |
| 214 | |
| 215 | time.sleep(1.0) |
| 216 | |
| 217 | # Let the cache expire and test again |
| 218 | response2 = self.client.get('/template/cached/bar/') |
| 219 | self.assertEqual(response2.status_code, 200) |
| 220 | |
| 221 | self.assertNotEqual(response.content, response2.content) |
| 222 | |
200 | 223 | class RedirectViewTest(unittest.TestCase): |
201 | 224 | rf = RequestFactory() |
202 | 225 | |
diff -r d197531525b3 tests/regressiontests/generic_views/templates/generic_views/about.html
a
|
b
|
|
1 | | <h1>About</h1> |
2 | | No newline at end of file |
| 1 | <h1>About</h1> |
| 2 | {% now "U.u" %} |
diff -r d197531525b3 tests/regressiontests/generic_views/urls.py
a
|
b
|
|
1 | 1 | from django.conf.urls.defaults import * |
2 | 2 | from django.views.generic import TemplateView |
| 3 | from django.views.decorators.cache import cache_page |
3 | 4 | |
4 | 5 | import views |
5 | 6 | |
… |
… |
|
15 | 16 | (r'^template/custom/(?P<foo>\w+)/$', |
16 | 17 | views.CustomTemplateView.as_view(template_name='generic_views/about.html')), |
17 | 18 | |
| 19 | (r'^template/cached/(?P<foo>\w+)/$', |
| 20 | cache_page(TemplateView.as_view(template_name='generic_views/about.html'), 1)), |
| 21 | |
18 | 22 | # DetailView |
19 | 23 | (r'^detail/obj/$', |
20 | 24 | views.ObjectDetail.as_view()), |