summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorAdam Chainz <me@adamj.eu>2016-11-21 13:14:03 +0000
committerTim Graham <timograham@gmail.com>2016-11-21 08:14:03 -0500
commit19e2114634c322d5a58f3dd282a3a3cfd0f5aa24 (patch)
treeb48a1f7882e5bd399b1a51a4dc4b81df5ea19963 /django/test
parent0783aa7debc6720306e7f345e5beace07febba64 (diff)
Fixed #27516 -- Made test client's response.json() cache the parsed JSON.
Diffstat (limited to 'django/test')
-rw-r--r--django/test/client.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/django/test/client.py b/django/test/client.py
index be5b6198bf..d27d462689 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -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."