Django

Code

Show
Ignore:
Timestamp:
10/07/08 04:23:40 (3 months ago)
Author:
mtredinnick
Message:

Fixed #5888 -- Added methods to the test client to support HEAD, PUT, DELETE
and OPTIONS support. Thanks Scott Barr and Leah Culver.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/test/client.py

    r9066 r9188  
    285285        return self.request(**r) 
    286286 
     287    def head(self, path, data={}, **extra): 
     288        """ 
     289        Request a response from the server using HEAD. 
     290        """ 
     291        r = { 
     292            'CONTENT_LENGTH':  None, 
     293            'CONTENT_TYPE':    'text/html; charset=utf-8', 
     294            'PATH_INFO':       urllib.unquote(path), 
     295            'QUERY_STRING':    urlencode(data, doseq=True), 
     296            'REQUEST_METHOD': 'HEAD', 
     297        } 
     298        r.update(extra) 
     299 
     300        return self.request(**r) 
     301 
     302    def options(self, path, data={}, **extra): 
     303        """ 
     304        Request a response from the server using OPTIONS. 
     305        """ 
     306        r = { 
     307            'CONTENT_LENGTH':  None, 
     308            'CONTENT_TYPE':    None, 
     309            'PATH_INFO':       urllib.unquote(path), 
     310            'QUERY_STRING':    urlencode(data, doseq=True), 
     311            'REQUEST_METHOD': 'OPTIONS', 
     312        } 
     313        r.update(extra) 
     314 
     315        return self.request(**r) 
     316 
     317    def put(self, path, data={}, content_type=MULTIPART_CONTENT, **extra): 
     318        """ 
     319        Send a resource to the server using PUT. 
     320        """ 
     321        if content_type is MULTIPART_CONTENT: 
     322            post_data = encode_multipart(BOUNDARY, data) 
     323        else: 
     324            post_data = data 
     325        r = { 
     326            'CONTENT_LENGTH': len(post_data), 
     327            'CONTENT_TYPE':   content_type, 
     328            'PATH_INFO':      urllib.unquote(path), 
     329            'REQUEST_METHOD': 'PUT', 
     330            'wsgi.input':     FakePayload(post_data), 
     331        } 
     332        r.update(extra) 
     333 
     334        return self.request(**r) 
     335 
     336    def delete(self, path, data={}, **extra): 
     337        """ 
     338        Send a DELETE request to the server. 
     339        """ 
     340        r = { 
     341            'CONTENT_LENGTH':  None, 
     342            'CONTENT_TYPE':    None, 
     343            'PATH_INFO':       urllib.unquote(path), 
     344            'REQUEST_METHOD': 'DELETE', 
     345            } 
     346        r.update(extra) 
     347 
     348        return self.request(**r) 
     349 
    287350    def login(self, **credentials): 
    288351        """