Ticket #5888: django.test.client.2.patch

File django.test.client.2.patch, 2.2 KB (added by Scott Barr <scott@…>, 16 years ago)

Last "fixed" patch was incorrect.

  • django/test/client.py

     
    237237
    238238        return self.request(**r)
    239239
     240    def head(self, path, data={}, **extra):
     241        "Request a response from the server using HEAD."
     242        r = {
     243            'CONTENT_LENGTH':  None,
     244            'CONTENT_TYPE':    'text/html; charset=utf-8',
     245            'PATH_INFO':       path,
     246            'QUERY_STRING':    urlencode(data, doseq=True),
     247            'REQUEST_METHOD': 'HEAD',
     248        }
     249        r.update(extra)
     250
     251        return self.request(**r)
     252
     253    def options(self, path, data={}, **extra):
     254        "Request a response from the server using OPTIONS."
     255        r = {
     256            'CONTENT_LENGTH':  None,
     257            'CONTENT_TYPE':    None,
     258            'PATH_INFO':       path,
     259            'QUERY_STRING':    urlencode(data, doseq=True),
     260            'REQUEST_METHOD': 'OPTIONS',
     261        }
     262        r.update(extra)
     263
     264        return self.request(**r)
     265
     266    def put(self, path, data={}, content_type=MULTIPART_CONTENT, **extra):
     267        """Send a resource to the server using PUT."""
     268
     269        if content_type is MULTIPART_CONTENT:
     270            post_data = encode_multipart(BOUNDARY, data)
     271        else:
     272            post_data = data
     273
     274        r = {
     275            'CONTENT_LENGTH': len(post_data),
     276            'CONTENT_TYPE':   content_type,
     277            'PATH_INFO':      path,
     278            'REQUEST_METHOD': 'PUT',
     279            'wsgi.input':     StringIO(post_data),
     280        }
     281        r.update(extra)
     282
     283        return self.request(**r)
     284
     285    def delete(self, path, **extra):
     286        """Send a DELETE request to the server."""
     287
     288        r = {
     289            'PATH_INFO':      path,
     290            'REQUEST_METHOD': 'DELETE',
     291
     292            'CONTENT_LENGTH':  None,
     293            'CONTENT_TYPE':    None,
     294            'PATH_INFO':       path,
     295            'REQUEST_METHOD': 'DELETE',
     296
     297        }
     298        r.update(extra)
     299
     300        return self.request(**r)
     301
    240302    def login(self, **credentials):
    241303        """Set the Client to appear as if it has sucessfully logged into a site.
    242304
Back to Top