Ticket #15012: t15012.diff

File t15012.diff, 2.6 KB (added by Russell Keith-Magee, 14 years ago)

Test case demonstrating the problem

  • tests/regressiontests/generic_views/base.py

    diff -r d197531525b3 tests/regressiontests/generic_views/base.py
    a b  
     1import time
    12import unittest
    23
    34from django.core.exceptions import ImproperlyConfigured
     
    158159    def _assert_about(self, response):
    159160        response.render()
    160161        self.assertEqual(response.status_code, 200)
    161         self.assertEqual(response.content, '<h1>About</h1>')
     162        self.assertContains(response, '<h1>About</h1>')
    162163
    163164    def test_get(self):
    164165        """
     
    197198        self.assertEqual(response.context['params'], {'foo': 'bar'})
    198199        self.assertEqual(response.context['key'], 'value')
    199200
     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
    200223class RedirectViewTest(unittest.TestCase):
    201224    rf = RequestFactory()
    202225
  • tests/regressiontests/generic_views/templates/generic_views/about.html

    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" %}
  • tests/regressiontests/generic_views/urls.py

    diff -r d197531525b3 tests/regressiontests/generic_views/urls.py
    a b  
    11from django.conf.urls.defaults import *
    22from django.views.generic import TemplateView
     3from django.views.decorators.cache import cache_page
    34
    45import views
    56
     
    1516    (r'^template/custom/(?P<foo>\w+)/$',
    1617        views.CustomTemplateView.as_view(template_name='generic_views/about.html')),
    1718
     19    (r'^template/cached/(?P<foo>\w+)/$',
     20        cache_page(TemplateView.as_view(template_name='generic_views/about.html'), 1)),
     21
    1822    # DetailView
    1923    (r'^detail/obj/$',
    2024        views.ObjectDetail.as_view()),
Back to Top