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

Regression in b8a41a2872.
This commit is contained in:
Tim Graham 2018-06-27 14:50:03 -04:00
parent dd367e0dae
commit 9294110a57
2 changed files with 5 additions and 1 deletions

View File

@ -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):
"""

View File

@ -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'})