summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-10-07 08:47:05 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-10-07 08:47:05 +0000
commited48b0b37ebbb7ec5a8001b7957bb5f9e021e644 (patch)
tree48397ebf8ac70f934e902a9633e9c5a9e3564fd0 /django/test
parent66c77d03d2b7e9643a5d942591e7f77816d52fad (diff)
Fixed #5888 -- Added methods to the test client to support HEAD, PUT, DELETE
and OPTIONS support. Thanks Scott Barr and Leah Culver. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9186 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test')
-rw-r--r--django/test/client.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/django/test/client.py b/django/test/client.py
index 6a3401a2ff..0cb8db3f4e 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -284,6 +284,69 @@ class Client(object):
return self.request(**r)
+ def head(self, path, data={}, **extra):
+ """
+ Request a response from the server using HEAD.
+ """
+ r = {
+ 'CONTENT_LENGTH': None,
+ 'CONTENT_TYPE': 'text/html; charset=utf-8',
+ 'PATH_INFO': urllib.unquote(path),
+ 'QUERY_STRING': urlencode(data, doseq=True),
+ 'REQUEST_METHOD': 'HEAD',
+ }
+ r.update(extra)
+
+ return self.request(**r)
+
+ def options(self, path, data={}, **extra):
+ """
+ Request a response from the server using OPTIONS.
+ """
+ r = {
+ 'CONTENT_LENGTH': None,
+ 'CONTENT_TYPE': None,
+ 'PATH_INFO': urllib.unquote(path),
+ 'QUERY_STRING': urlencode(data, doseq=True),
+ 'REQUEST_METHOD': 'OPTIONS',
+ }
+ r.update(extra)
+
+ return self.request(**r)
+
+ def put(self, path, data={}, content_type=MULTIPART_CONTENT, **extra):
+ """
+ Send a resource to the server using PUT.
+ """
+ if content_type is MULTIPART_CONTENT:
+ post_data = encode_multipart(BOUNDARY, data)
+ else:
+ post_data = data
+ r = {
+ 'CONTENT_LENGTH': len(post_data),
+ 'CONTENT_TYPE': content_type,
+ 'PATH_INFO': urllib.unquote(path),
+ 'REQUEST_METHOD': 'PUT',
+ 'wsgi.input': FakePayload(post_data),
+ }
+ r.update(extra)
+
+ return self.request(**r)
+
+ def delete(self, path, data={}, **extra):
+ """
+ Send a DELETE request to the server.
+ """
+ r = {
+ 'CONTENT_LENGTH': None,
+ 'CONTENT_TYPE': None,
+ 'PATH_INFO': urllib.unquote(path),
+ 'REQUEST_METHOD': 'DELETE',
+ }
+ r.update(extra)
+
+ return self.request(**r)
+
def login(self, **credentials):
"""
Sets the Client to appear as if it has successfully logged into a site.