summaryrefslogtreecommitdiff
path: root/docs/topics/testing
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2022-11-10 09:29:49 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-11-10 09:29:49 +0100
commit0931d5b087a37545af0bef597deac03b5f0f7db0 (patch)
treecb72c4f887e24e354ade7c9f788f3e2af872edf4 /docs/topics/testing
parentd6fbfea08d9bae4165df6a0cfbd4520b5e2242b2 (diff)
Improved async request factory and client docs.
Diffstat (limited to 'docs/topics/testing')
-rw-r--r--docs/topics/testing/advanced.txt5
-rw-r--r--docs/topics/testing/tools.txt6
2 files changed, 10 insertions, 1 deletions
diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt
index cdcbc44437..2b2f35fdc3 100644
--- a/docs/topics/testing/advanced.txt
+++ b/docs/topics/testing/advanced.txt
@@ -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
=========================
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 27692d313d..81baca4f3f 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -34,7 +34,7 @@ short:
* Use Django's test client to establish that the correct template is being
rendered and that the template is passed the correct context data.
-* Use :class:`~django.test.RequestFactory` to test view functions directly,
+* Use :class:`~django.test.RequestFactory` to test view functions directly,
bypassing the routing and middleware layers.
* Use in-browser frameworks like Selenium_ to test *rendered* HTML and the
@@ -1905,9 +1905,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