Fixed #24773 -- Added a json() method on test client responses.

This commit is contained in:
Andy McKay 2015-05-08 22:33:26 -07:00 committed by Tim Graham
parent 46ce72e8d2
commit 4525a0c466
6 changed files with 40 additions and 2 deletions

View file

@ -1270,6 +1270,16 @@ class RequestMethodStringDataTests(SimpleTestCase):
response = self.client.head('/body/', data='', content_type='application/json')
self.assertEqual(response.content, b'')
def test_json(self):
response = self.client.get('/json_response/')
self.assertEqual(response.json(), {'key': 'value'})
def test_json_wrong_header(self):
response = self.client.get('/body/')
msg = 'Content-Type header is "text/html; charset=utf-8", not "application/json"'
with self.assertRaisesMessage(ValueError, msg):
self.assertEqual(response.json(), {'key': 'value'})
@override_settings(ROOT_URLCONF='test_client_regress.urls',)
class QueryStringTests(SimpleTestCase):