Ticket #5176: 0002_generate_cache_key.diff

File 0002_generate_cache_key.diff, 3.6 KB (added by lcordier, 6 years ago)

Some basic test code added, simply check that cookies work the they are supposed to work.

  • django/utils/cache.py

     
    2323    set
    2424except NameError:
    2525    from sets import Set as set   # Python 2.3 fallback
     26from Cookie import SimpleCookie
    2627
    2728from django.conf import settings
    2829from django.core.cache import cache
     
    141142    ctx = md5_constructor()
    142143    for header in headerlist:
    143144        value = request.META.get(header, None)
     145        if isinstance(value, SimpleCookie):
     146            value = value.output()
     147       
    144148        if value is not None:
    145149            ctx.update(value)
    146150    return 'views.decorators.cache.cache_page.%s.%s.%s' % (
  • tests/regressiontests/test_client_regress/views.py

     
    4646
    4747def request_methods_view(request):
    4848    "A view that responds with the request method"
    49     return HttpResponse('request method: %s' % request.method)
    50  No newline at end of file
     49    return HttpResponse('request method: %s' % request.method)
     50
     51def set_cookie_view(request):
     52    "A view that sets a cookie."
     53    response = HttpResponse('set cookie')
     54    response.set_cookie('test_cookie', 'test_value')
     55   
     56    return response
  • tests/regressiontests/test_client_regress/models.py

     
    22Regression tests for the Test Client, especially the customized assertions.
    33"""
    44import os
     5from Cookie import SimpleCookie
     6
    57from django.conf import settings
    6 
    78from django.test import Client, TestCase
    89from django.core.urlresolvers import reverse
    910from django.core.exceptions import SuspiciousOperation
     
    261262        # default client.
    262263        self.assertRedirects(response, "http://testserver/test_client_regress/get_view/")
    263264
     265class CookieTests(TestCase):
     266   
     267    def test_cookies(self):
     268        "Check that cookies work in the test client, see ticket #5176."
     269
     270        c = Client()
     271        response = c.get('/test_client_regress/set_cookie/')
     272
     273        self.assert_(isinstance(response.cookies, SimpleCookie))
     274        self.assert_(response.cookies.output().find('Set-Cookie: test_cookie=test_value; Path=/') >= 0)
     275
    264276class URLEscapingTests(TestCase):
    265277    def test_simple_argument_get(self):
    266278        "Get a view that has a simple string argument"
  • tests/regressiontests/test_client_regress/urls.py

     
    1010    (r'^set_session/$', views.set_session_view),
    1111    (r'^check_session/$', views.check_session_view),
    1212    (r'^request_methods/$', views.request_methods_view),
     13    (r'^set_cookie/$', views.set_cookie_view)
    1314)
  • AUTHORS

     
    239239    Lau Bech Lauritzen
    240240    Rune Rønde Laursen <runerl@skjoldhoej.dk>
    241241    Eugene Lazutkin <http://lazutkin.com/blog/>
    242     lcordier@point45.com
     242    Louis Cordier <lcordier@gmail.com>
    243243    Jeong-Min Lee <falsetru@gmail.com>
    244244    Jannis Leidel <jl@websushi.org>
    245245    Christopher Lenz <http://www.cmlenz.net/>
Back to Top