mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #24773 -- Added a json() method on test client responses.
This commit is contained in:
parent
46ce72e8d2
commit
4525a0c466
6 changed files with 40 additions and 2 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue