Ticket #5176: 0001_fix_test_client.diff

File 0001_fix_test_client.diff, 1.8 KB (added by lcordier, 16 years ago)

Fixes SimpleCookie problem in django.test.client.Client.

  • django/test/client.py

     
    177177        return {}
    178178    session = property(_session)
    179179
     180    def _format_cookies(self):
     181        """
     182        Generates a string suitable for a HTTP request from a SimpleCookie
     183        cookie jar.
     184       
     185        Ideally this should be done with a propper cookie jar, where only
     186        the cookies valid for the request path and time are send in the
     187        request. Unfortunatly cookielib.CookieJar isn't the right candidate.
     188        """
     189        cookie_strings = self.cookies.output().split('Set-Cookie: ')
     190        while '' in cookie_strings:
     191            cookie_strings.remove('')
     192       
     193        cookies = []
     194        for cookie in cookie_strings:
     195            cookies.append(cookie.split(';', 1)[0])
     196       
     197        return '; '.join(cookies)
     198
    180199    def request(self, **request):
    181200        """
    182201        The master request method. Composes the environment dictionary
     
    185204        using the arguments to the request.
    186205        """
    187206        environ = {
    188             'HTTP_COOKIE':      self.cookies,
     207            'HTTP_COOKIE':       self._format_cookies(),
    189208            'PATH_INFO':         '/',
    190209            'QUERY_STRING':      '',
    191210            'REQUEST_METHOD':    'GET',
  • AUTHORS

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