mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #27516 -- Made test client's response.json() cache the parsed JSON.
This commit is contained in:
@@ -683,12 +683,14 @@ class Client(RequestFactory):
|
||||
self.cookies = SimpleCookie()
|
||||
|
||||
def _parse_json(self, response, **extra):
|
||||
if 'application/json' not in response.get('Content-Type'):
|
||||
raise ValueError(
|
||||
'Content-Type header is "{0}", not "application/json"'
|
||||
.format(response.get('Content-Type'))
|
||||
)
|
||||
return json.loads(response.content.decode(), **extra)
|
||||
if not hasattr(response, '_json'):
|
||||
if 'application/json' not in response.get('Content-Type'):
|
||||
raise ValueError(
|
||||
'Content-Type header is "{0}", not "application/json"'
|
||||
.format(response.get('Content-Type'))
|
||||
)
|
||||
response._json = json.loads(response.content.decode(), **extra)
|
||||
return response._json
|
||||
|
||||
def _handle_redirects(self, response, **extra):
|
||||
"Follows any redirects by requesting responses from the server using GET."
|
||||
|
||||
Reference in New Issue
Block a user