Author: jacob
Date: 2009-10-26 10:04:32 -0500 (Mon, 26 Oct 2009)
New Revision: 11657

Modified:
   django/branches/releases/1.1.X/django/test/client.py
   
django/branches/releases/1.1.X/tests/regressiontests/test_client_regress/models.py
Log:
[1.1.X] Fixed #11371: Made `django.test.Client.put()` work for non-form-data 
PUT (i.e. JSON, etc.). Thanks, phyfus. Backport of [11656] from trunk.

Modified: django/branches/releases/1.1.X/django/test/client.py
===================================================================
--- django/branches/releases/1.1.X/django/test/client.py        2009-10-26 
15:02:54 UTC (rev 11656)
+++ django/branches/releases/1.1.X/django/test/client.py        2009-10-26 
15:04:32 UTC (rev 11657)
@@ -362,12 +362,18 @@
         else:
             post_data = data
 
+        # Make `data` into a querystring only if it's not already a string. If
+        # it is a string, we'll assume that the caller has already encoded it.
+        query_string = None
+        if not isinstance(data, basestring):
+            query_string = urlencode(data, doseq=True)
+
         parsed = urlparse(path)
         r = {
             'CONTENT_LENGTH': len(post_data),
             'CONTENT_TYPE':   content_type,
             'PATH_INFO':      urllib.unquote(parsed[2]),
-            'QUERY_STRING':   urlencode(data, doseq=True) or parsed[4],
+            'QUERY_STRING':   query_string or parsed[4],
             'REQUEST_METHOD': 'PUT',
             'wsgi.input':     FakePayload(post_data),
         }

Modified: 
django/branches/releases/1.1.X/tests/regressiontests/test_client_regress/models.py
===================================================================
--- 
django/branches/releases/1.1.X/tests/regressiontests/test_client_regress/models.py
  2009-10-26 15:02:54 UTC (rev 11656)
+++ 
django/branches/releases/1.1.X/tests/regressiontests/test_client_regress/models.py
  2009-10-26 15:04:32 UTC (rev 11657)
@@ -574,6 +574,23 @@
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.content, 'request method: DELETE')
 
+class RequestMethodStringDataTests(TestCase):
+    def test_post(self):
+        "Request a view with string data via request method POST"
+        # Regression test for #11371
+        data = u'{"test": "json"}'
+        response = self.client.post('/test_client_regress/request_methods/', 
data=data, content_type='application/json')
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.content, 'request method: POST')
+
+    def test_put(self):
+        "Request a view with string data via request method PUT"
+        # Regression test for #11371
+        data = u'{"test": "json"}'
+        response = self.client.put('/test_client_regress/request_methods/', 
data=data, content_type='application/json')
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.content, 'request method: PUT')
+
 class QueryStringTests(TestCase):
     def test_get_like_requests(self):
         for method_name in ('get','head','options','put','delete'):


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to