Ticket #11371: patch.diff

File patch.diff, 2.2 KB (added by Johann Heller, 15 years ago)

A patch with both the tests and the fix.

  • django/test/client.py

     
    362362        else:
    363363            post_data = data
    364364
     365        query_string = None
     366        if not isinstance(data, basestring):
     367            query_string = urlencode(data, doseq=True)
     368
    365369        parsed = urlparse(path)
    366370        r = {
    367371            'CONTENT_LENGTH': len(post_data),
    368372            'CONTENT_TYPE':   content_type,
    369373            'PATH_INFO':      urllib.unquote(parsed[2]),
    370             'QUERY_STRING':   urlencode(data, doseq=True) or parsed[4],
     374            'QUERY_STRING':   query_string or parsed[4],
    371375            'REQUEST_METHOD': 'PUT',
    372376            'wsgi.input':     FakePayload(post_data),
    373377        }
  • tests/regressiontests/test_client_regress/models.py

     
    574574        self.assertEqual(response.status_code, 200)
    575575        self.assertEqual(response.content, 'request method: DELETE')
    576576
     577class RequestMethodStringDataTests(TestCase):
     578    def test_post(self):
     579        "Request a view with string data via request method POST"
     580        # Regression test for #11371
     581        data = u'{"test": "json"}'
     582        response = self.client.post('/test_client_regress/request_methods/', data=data, content_type='application/json')
     583        self.assertEqual(response.status_code, 200)
     584        self.assertEqual(response.content, 'request method: POST')
     585
     586    def test_put(self):
     587        "Request a view with string data via request method PUT"
     588        # Regression test for #11371
     589        data = u'{"test": "json"}'
     590        response = self.client.put('/test_client_regress/request_methods/', data=data, content_type='application/json')
     591        self.assertEqual(response.status_code, 200)
     592        self.assertEqual(response.content, 'request method: PUT')
     593
    577594class QueryStringTests(TestCase):
    578595    def test_get_like_requests(self):
    579596        for method_name in ('get','head','options','put','delete'):
Back to Top