Browse Source

Improved async request factory and client docs.

David Wobrock 2 years ago
parent
commit
0931d5b087
2 changed files with 10 additions and 1 deletions
  1. 5 0
      docs/topics/testing/advanced.txt
  2. 5 1
      docs/topics/testing/tools.txt

+ 5 - 0
docs/topics/testing/advanced.txt

@@ -70,6 +70,8 @@ The following is a unit test using the request factory::
 AsyncRequestFactory
 AsyncRequestFactory
 -------------------
 -------------------
 
 
+.. class:: AsyncRequestFactory
+
 ``RequestFactory`` creates WSGI-like requests. If you want to create ASGI-like
 ``RequestFactory`` creates WSGI-like requests. If you want to create ASGI-like
 requests, including having a correct ASGI ``scope``, you can instead use
 requests, including having a correct ASGI ``scope``, you can instead use
 ``django.test.AsyncRequestFactory``.
 ``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
 difference being that it returns ``ASGIRequest`` instances rather than
 ``WSGIRequest`` instances. All of its methods are still synchronous callables.
 ``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
 Testing class-based views
 =========================
 =========================
 
 

+ 5 - 1
docs/topics/testing/tools.txt

@@ -34,7 +34,7 @@ short:
 * Use Django's test client to establish that the correct template is being
 * Use Django's test client to establish that the correct template is being
   rendered and that the template is passed the correct context data.
   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.
   bypassing the routing and middleware layers.
 
 
 * Use in-browser frameworks like Selenium_ to test *rendered* HTML and the
 * 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``,
 asynchronous test client. This is available as ``django.test.AsyncClient``,
 or as ``self.async_client`` on any test.
 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)
 ``AsyncClient`` has the same methods and signatures as the synchronous (normal)
 test client, with two exceptions:
 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.
 * The ``follow`` parameter is not supported.
 * Headers passed as ``extra`` keyword arguments should not have the ``HTTP_``
 * Headers passed as ``extra`` keyword arguments should not have the ``HTTP_``
   prefix required by the synchronous client (see :meth:`Client.get`). For
   prefix required by the synchronous client (see :meth:`Client.get`). For