summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAndy McKay <amckay@mozilla.com>2015-05-08 22:33:26 -0700
committerTim Graham <timograham@gmail.com>2015-05-25 10:42:30 -0400
commit4525a0c4669dccb3a4c5d865184f8bb8e4a89ec8 (patch)
treef54f254b0043ffbb78e1f7a81f27c705650254c8 /docs
parent46ce72e8d2588bf62e4d4e7f08019e7ad2ef0fe6 (diff)
Fixed #24773 -- Added a json() method on test client responses.
Diffstat (limited to 'docs')
-rw-r--r--docs/releases/1.9.txt3
-rw-r--r--docs/topics/testing/tools.txt14
2 files changed, 16 insertions, 1 deletions
diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt
index e36c4512ca..5b58f79fc0 100644
--- a/docs/releases/1.9.txt
+++ b/docs/releases/1.9.txt
@@ -289,7 +289,8 @@ Requests and Responses
Tests
^^^^^
-* ...
+* Added the :meth:`json() <django.test.Response.json>` method to test client
+ responses to give access to the response body as JSON.
URLs
^^^^
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index aa66afb1d9..e2ad15d5b5 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -425,6 +425,20 @@ Specifically, a ``Response`` object has the following attributes:
>>> response.context['name']
'Arthur'
+ .. method:: json(**kwargs)
+
+ .. versionadded:: 1.9
+
+ The body of the response, parsed as JSON. Extra keyword arguments are
+ passed to :func:`json.loads`. For example::
+
+ >>> response = client.get('/foo/')
+ >>> response.json()['name']
+ 'Arthur'
+
+ If the ``Content-Type`` header is not ``"application/json"``, then a
+ :exc:`ValueError` will be raised when trying to parse the response.
+
.. attribute:: request
The request data that stimulated the response.