Kaydet (Commit) 9294110a authored tarafından Tim Graham's avatar Tim Graham

Fixed #29520 -- Fixed test client crash when posting bytes.

Regression in b8a41a28.
üst dd367e0d
......@@ -310,7 +310,7 @@ class RequestFactory:
charset = match.group(1)
else:
charset = settings.DEFAULT_CHARSET
return data.encode(charset)
return force_bytes(data, encoding=charset)
def _encode_json(self, data, content_type):
"""
......
......@@ -1196,6 +1196,10 @@ class RequestMethodStringDataTests(SimpleTestCase):
response = self.client.head('/body/', data='', content_type='application/json')
self.assertEqual(response.content, b'')
def test_json_bytes(self):
response = self.client.post('/body/', data=b"{'value': 37}", content_type='application/json')
self.assertEqual(response.content, b"{'value': 37}")
def test_json(self):
response = self.client.get('/json_response/')
self.assertEqual(response.json(), {'key': 'value'})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment