1
0
mirror of https://github.com/django/django.git synced 2025-04-09 07:56:43 +00:00

[4.1.x] Improved async request factory and client docs.

Backport of 0931d5b087a37545af0bef597deac03b5f0f7db0 from main
This commit is contained in:
David Wobrock 2022-11-10 09:29:49 +01:00 committed by Mariusz Felisiak
parent 9fb57fcc70
commit 8c8427c35e
2 changed files with 9 additions and 0 deletions

View File

@ -70,6 +70,8 @@ The following is a unit test using the request factory::
AsyncRequestFactory
-------------------
.. class:: AsyncRequestFactory
``RequestFactory`` creates WSGI-like requests. If you want to create ASGI-like
requests, including having a correct ASGI ``scope``, you can instead use
``django.test.AsyncRequestFactory``.
@ -78,6 +80,9 @@ This class is directly API-compatible with ``RequestFactory``, with the only
difference being that it returns ``ASGIRequest`` instances rather than
``WSGIRequest`` instances. All of its methods are still synchronous callables.
Arbitrary keyword arguments in ``defaults`` are added directly into the ASGI
scope.
Testing class-based views
=========================

View File

@ -1906,9 +1906,13 @@ If you are testing from an asynchronous function, you must also use the
asynchronous test client. This is available as ``django.test.AsyncClient``,
or as ``self.async_client`` on any test.
.. class:: AsyncClient(enforce_csrf_checks=False, raise_request_exception=True, **defaults)
``AsyncClient`` has the same methods and signatures as the synchronous (normal)
test client, with two exceptions:
* In the initialization, arbitrary keyword arguments in ``defaults`` are added
directly into the ASGI scope.
* The ``follow`` parameter is not supported.
* Headers passed as ``extra`` keyword arguments should not have the ``HTTP_``
prefix required by the synchronous client (see :meth:`Client.get`). For