summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDan Palmer <dan@danpalmer.me>2018-08-18 13:15:24 +0100
committerTim Graham <timograham@gmail.com>2018-08-25 10:57:05 -0400
commite1816669732c54c40122c8a22dcba42f6ee3c326 (patch)
tree80d66304077c63580144f72ba744d40a63d04c68 /docs
parent08f788b169a30d26f50433083aca253a4e4031b2 (diff)
Fixed #29687 -- Allowed the test client to serialize list/tuple as JSON.
Diffstat (limited to 'docs')
-rw-r--r--docs/releases/2.2.txt4
-rw-r--r--docs/topics/testing/tools.txt14
2 files changed, 14 insertions, 4 deletions
diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt
index 4ca3bb9662..ff692151ed 100644
--- a/docs/releases/2.2.txt
+++ b/docs/releases/2.2.txt
@@ -224,6 +224,10 @@ Tests
URL, ignoring the ordering of the query string.
:meth:`~.SimpleTestCase.assertRedirects` uses the new assertion.
+* The test :class:`~.django.test.Client` now supports automatic JSON
+ serialization of list and tuple ``data`` when
+ ``content_type='application/json'``.
+
URLs
~~~~
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 92e96e8c98..38b437e18c 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -213,10 +213,11 @@ Use the ``django.test.Client`` class to make requests.
name=fred&passwd=secret
- If you provide ``content_type`` as :mimetype:`application/json`, a
- ``data`` dictionary is serialized using :func:`json.dumps` with
- :class:`~django.core.serializers.json.DjangoJSONEncoder`. You can
- change the encoder by providing a ``json_encoder`` argument to
+ If you provide ``content_type`` as :mimetype:`application/json`, the
+ ``data`` is serialized using :func:`json.dumps` if it's a dict, list,
+ or tuple. Serialization is performed with
+ :class:`~django.core.serializers.json.DjangoJSONEncoder` by default,
+ and can be overridden by providing a ``json_encoder`` argument to
:class:`Client`. This serialization also happens for :meth:`put`,
:meth:`patch`, and :meth:`delete` requests.
@@ -226,6 +227,11 @@ Use the ``django.test.Client`` class to make requests.
you can call :func:`json.dumps` on ``data`` before passing it to
``post()`` to achieve the same thing.
+ .. versionchanged:: 2.2
+
+ The JSON serialization was extended to support lists and tuples. In
+ older versions, only dicts are serialized.
+
If you provide any other ``content_type`` (e.g. :mimetype:`text/xml`
for an XML payload), the contents of ``data`` are sent as-is in the
POST request, using ``content_type`` in the HTTP ``Content-Type``