# HG changeset patch
# User js  <johan@s2hc.com>
# Date 1333297370 -7200
# Node ID 439293e4935bd15456857296d78195b86a6f024c
# Parent  ec7e13dc23c15307c53a7ddbe5acb692c7222451
added delete as get_like request
removed check for 'request method: HEAD since head method won't return body

diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
--- a/tests/regressiontests/test_client_regress/models.py
+++ b/tests/regressiontests/test_client_regress/models.py
@@ -814,7 +814,6 @@
         data = u'{"test": "json"}'
         response = self.client.head('/test_client_regress/request_methods/', data=data, content_type='application/json')
         self.assertEqual(response.status_code, 200)
-        self.assertEqual(response.content, 'request method: HEAD')
 
     def test_options(self):
         "Request a view with string data via request method options"
@@ -836,7 +835,7 @@
     def test_get_like_requests(self):
         # See: https://code.djangoproject.com/ticket/10571.
         # Removed 'put' and 'delete' here as they are 'GET-like requests'
-        for method_name in ('get','head','options'):
+        for method_name in ('get','head','options', 'delete'):
             # A GET-like request can pass a query string as data
             method = getattr(self.client, method_name)
             response = method("/test_client_regress/request_data/", data={'foo':'whiz'})
# HG changeset patch
# User js  <johan@s2hc.com>
# Date 1333297558 -7200
# Node ID e311d2c21ae61b695bccdc110b8128c8a14abc24
# Parent  439293e4935bd15456857296d78195b86a6f024c
refactoring test client request methods (get, put, post, delete, head, options) to use generic method, also allowing delete, head, options and get to send body in request

diff --git a/django/test/client.py b/django/test/client.py
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -229,61 +229,51 @@
         else:
             return urllib.unquote(parsed[2])
 
-    def get(self, path, data={}, **extra):
+    def _generic_method(self, method, path, data, content_type, **extra):
+        "a generic method for building the kwargs for request"
+
+        parsed = urlparse(path)
+
+        if content_type == 'querystring':
+            r = {
+                'CONTENT_TYPE': 'text/html; charset=utf-8',
+                'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
+                }
+        else:
+            encoded_data = self._encode_data(data, content_type)
+            r = {
+                'CONTENT_TYPE': content_type,
+                'CONTENT_LENGTH': len(encoded_data),
+                'QUERY_STRING': parsed[4],
+                'wsgi.input': FakePayload(encoded_data),
+                }
+        r.update({
+                 'PATH_INFO': self._get_path(parsed),
+                 'REQUEST_METHOD': method.upper()
+                 })
+        r.update(extra)
+        return self.request(**r)
+
+    def get(self, path, data={}, content_type='querystring', **extra):
         "Construct a GET request"
 
-        parsed = urlparse(path)
-        r = {
-            'CONTENT_TYPE':    'text/html; charset=utf-8',
-            'PATH_INFO':       self._get_path(parsed),
-            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
-            'REQUEST_METHOD': 'GET',
-        }
-        r.update(extra)
-        return self.request(**r)
+        return self._generic_method('get', path, data, content_type, **extra)
 
     def post(self, path, data={}, content_type=MULTIPART_CONTENT,
              **extra):
         "Construct a POST request."
 
-        post_data = self._encode_data(data, content_type)
+        return self._generic_method('post', path, data, content_type, **extra)
 
-        parsed = urlparse(path)
-        r = {
-            'CONTENT_LENGTH': len(post_data),
-            'CONTENT_TYPE':   content_type,
-            'PATH_INFO':      self._get_path(parsed),
-            'QUERY_STRING':   parsed[4],
-            'REQUEST_METHOD': 'POST',
-            'wsgi.input':     FakePayload(post_data),
-        }
-        r.update(extra)
-        return self.request(**r)
-
-    def head(self, path, data={}, **extra):
+    def head(self, path, data={}, content_type='querystring', **extra):
         "Construct a HEAD request."
 
-        parsed = urlparse(path)
-        r = {
-            'CONTENT_TYPE':    'text/html; charset=utf-8',
-            'PATH_INFO':       self._get_path(parsed),
-            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
-            'REQUEST_METHOD': 'HEAD',
-        }
-        r.update(extra)
-        return self.request(**r)
+        return self._generic_method('head', path, data, content_type, **extra)
 
-    def options(self, path, data={}, **extra):
+    def options(self, path, data={}, content_type='querystring', **extra):
         "Constrict an OPTIONS request"
 
-        parsed = urlparse(path)
-        r = {
-            'PATH_INFO':       self._get_path(parsed),
-            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
-            'REQUEST_METHOD': 'OPTIONS',
-        }
-        r.update(extra)
-        return self.request(**r)
+        return self._generic_method('options', path, data, content_type, **extra)
 
     def put(self, path, data={}, content_type=MULTIPART_CONTENT,
             **extra):
@@ -301,19 +291,13 @@
             'wsgi.input':     FakePayload(put_data),
         }
         r.update(extra)
-        return self.request(**r)
+        #return self.request(**r)
+        return self._generic_method('put', path, data, content_type, **extra)
 
-    def delete(self, path, data={}, **extra):
+    def delete(self, path, data={}, content_type='querystring', **extra):
         "Construct a DELETE request."
 
-        parsed = urlparse(path)
-        r = {
-            'PATH_INFO':       self._get_path(parsed),
-            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
-            'REQUEST_METHOD': 'DELETE',
-        }
-        r.update(extra)
-        return self.request(**r)
+        return self._generic_method('delete', path, data, content_type, **extra)
 
 
 class Client(RequestFactory):
