summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-10-07 09:23:40 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-10-07 09:23:40 +0000
commitcd8eeaacf53677044eb8022220ef5939a91228ae (patch)
tree67808ebbdf8de780f7c2669c31bac7aff45bfa70 /django
parent30b568226f86f268628ac40890a8fa40c4db0b97 (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/trunk@9188 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-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.