Ticket #10571: unicode_payload_put.2.patch
File unicode_payload_put.2.patch, 5.7 KB (added by , 13 years ago) |
---|
-
django/test/client.py
207 207 "Construct a generic request object." 208 208 return WSGIRequest(self._base_environ(**request)) 209 209 210 def _encode_data(self, data, content_type, ): 211 if content_type is MULTIPART_CONTENT: 212 return encode_multipart(BOUNDARY, data) 213 else: 214 # Encode the content so that the byte representation is correct. 215 match = CONTENT_TYPE_RE.match(content_type) 216 if match: 217 charset = match.group(1) 218 else: 219 charset = settings.DEFAULT_CHARSET 220 return smart_str(data, encoding=charset) 221 210 222 def _get_path(self, parsed): 211 223 # If there are parameters, add them 212 224 if parsed[3]: … … 232 244 **extra): 233 245 "Construct a POST request." 234 246 235 if content_type is MULTIPART_CONTENT: 236 post_data = encode_multipart(BOUNDARY, data) 237 else: 238 # Encode the content so that the byte representation is correct. 239 match = CONTENT_TYPE_RE.match(content_type) 240 if match: 241 charset = match.group(1) 242 else: 243 charset = settings.DEFAULT_CHARSET 244 post_data = smart_str(data, encoding=charset) 247 post_data = self._encode_data(data, content_type) 245 248 246 249 parsed = urlparse(path) 247 250 r = { … … 286 289 **extra): 287 290 "Construct a PUT request." 288 291 289 if content_type is MULTIPART_CONTENT: 290 post_data = encode_multipart(BOUNDARY, data) 291 else: 292 post_data = data 292 put_data = self._encode_data(data, content_type) 293 293 294 # Make `data` into a querystring only if it's not already a string. If295 # it is a string, we'll assume that the caller has already encoded it.296 query_string = None297 if not isinstance(data, basestring):298 query_string = urlencode(data, doseq=True)299 300 294 parsed = urlparse(path) 301 295 r = { 302 'CONTENT_LENGTH': len(p ost_data),296 'CONTENT_LENGTH': len(put_data), 303 297 'CONTENT_TYPE': content_type, 304 298 'PATH_INFO': self._get_path(parsed), 305 'QUERY_STRING': query_string orparsed[4],299 'QUERY_STRING': parsed[4], 306 300 'REQUEST_METHOD': 'PUT', 307 'wsgi.input': FakePayload(p ost_data),301 'wsgi.input': FakePayload(put_data), 308 302 } 309 303 r.update(extra) 310 304 return self.request(**r) -
tests/regressiontests/test_client_regress/models.py
757 757 758 758 class QueryStringTests(TestCase): 759 759 def test_get_like_requests(self): 760 for method_name in ('get','head','options','put','delete'): 760 # See: https://code.djangoproject.com/ticket/10571. 761 # Removed 'put' and 'delete' here as they are 'GET-like requests' 762 for method_name in ('get','head','options'): 761 763 # A GET-like request can pass a query string as data 762 764 method = getattr(self.client, method_name) 763 765 response = method("/test_client_regress/request_data/", data={'foo':'whiz'}) … … 814 816 response = self.client.post("/test_client_regress/parse_unicode_json/", json, 815 817 content_type="application/json") 816 818 self.assertEqual(response.content, json) 819 response = self.client.put("/test_client_regress/parse_unicode_json/", json, 820 content_type="application/json") 821 self.assertEqual(response.content, json) 817 822 818 823 def test_unicode_payload_utf8(self): 819 824 "A non-ASCII unicode data encoded as UTF-8 can be POSTed" … … 822 827 response = self.client.post("/test_client_regress/parse_unicode_json/", json, 823 828 content_type="application/json; charset=utf-8") 824 829 self.assertEqual(response.content, json.encode('utf-8')) 830 response = self.client.put("/test_client_regress/parse_unicode_json/", json, 831 content_type="application/json; charset=utf-8") 832 self.assertEqual(response.content, json.encode('utf-8')) 825 833 826 834 def test_unicode_payload_utf16(self): 827 835 "A non-ASCII unicode data encoded as UTF-16 can be POSTed" … … 830 838 response = self.client.post("/test_client_regress/parse_unicode_json/", json, 831 839 content_type="application/json; charset=utf-16") 832 840 self.assertEqual(response.content, json.encode('utf-16')) 841 response = self.client.put("/test_client_regress/parse_unicode_json/", json, 842 content_type="application/json; charset=utf-16") 843 self.assertEqual(response.content, json.encode('utf-16')) 833 844 834 845 def test_unicode_payload_non_utf(self): 835 846 "A non-ASCII unicode data as a non-UTF based encoding can be POSTed" … … 838 849 response = self.client.post("/test_client_regress/parse_unicode_json/", json, 839 850 content_type="application/json; charset=koi8-r") 840 851 self.assertEqual(response.content, json.encode('koi8-r')) 852 response = self.client.put("/test_client_regress/parse_unicode_json/", json, 853 content_type="application/json; charset=koi8-r") 854 self.assertEqual(response.content, json.encode('koi8-r')) 841 855 842 856 class DummyFile(object): 843 857 def __init__(self, filename):