Django

Code

Ticket #5888: django.test.client.patch

File django.test.client.patch, 4.0 kB (added by Scott Barr <scott@divisionbyzero.com.au>, 2 years ago)

Changed the patch so that the file path is relative to the django source directory.

  • django/test/client.py

    old new  
    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 
     302    def head(self, path, data={}, **extra): 
     303        "Request a response from the server using HEAD." 
     304        r = { 
     305            'CONTENT_LENGTH':  None, 
     306            'CONTENT_TYPE':    'text/html; charset=utf-8', 
     307            'PATH_INFO':       path, 
     308            'QUERY_STRING':    urlencode(data, doseq=True), 
     309            'REQUEST_METHOD': 'HEAD', 
     310        } 
     311        r.update(extra) 
     312 
     313        return self.request(**r) 
     314 
     315    def options(self, path, data={}, **extra): 
     316        "Request a response from the server using OPTIONS." 
     317        r = { 
     318            'CONTENT_LENGTH':  None, 
     319            'CONTENT_TYPE':    None, 
     320            'PATH_INFO':       path, 
     321            'QUERY_STRING':    urlencode(data, doseq=True), 
     322            'REQUEST_METHOD': 'OPTIONS', 
     323        } 
     324        r.update(extra) 
     325 
     326        return self.request(**r) 
     327 
     328    def put(self, path, data={}, content_type=MULTIPART_CONTENT, **extra): 
     329        """Send a resource to the server using PUT.""" 
     330 
     331        if content_type is MULTIPART_CONTENT: 
     332            post_data = encode_multipart(BOUNDARY, data) 
     333        else: 
     334            post_data = data 
     335 
     336        r = { 
     337            'CONTENT_LENGTH': len(post_data), 
     338            'CONTENT_TYPE':   content_type, 
     339            'PATH_INFO':      path, 
     340            'REQUEST_METHOD': 'PUT', 
     341            'wsgi.input':     StringIO(post_data), 
     342        } 
     343        r.update(extra) 
     344 
     345        return self.request(**r) 
     346 
     347    def delete(self, path, **extra): 
     348        """Send a DELETE request to the server.""" 
     349 
     350        r = { 
     351            'PATH_INFO':      path, 
     352            'REQUEST_METHOD': 'DELETE', 
     353 
     354            'CONTENT_LENGTH':  None, 
     355            'CONTENT_TYPE':    None, 
     356            'PATH_INFO':       path, 
     357            'REQUEST_METHOD': 'DELETE', 
     358 
     359        } 
     360        r.update(extra) 
     361 
     362        return self.request(**r) 
     363 
    240364    def login(self, **credentials): 
    241365        """Set the Client to appear as if it has sucessfully logged into a site. 
    242366