Fixed #29687 -- Allowed the test client to serialize list/tuple as JSON.

This commit is contained in:
Dan Palmer 2018-08-18 13:15:24 +01:00 committed by Tim Graham
parent 08f788b169
commit e181666973
6 changed files with 33 additions and 15 deletions

View file

@ -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``