Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved async request factory and client docs. #16279

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/topics/testing/advanced.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand All @@ -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
=========================

Expand Down
6 changes: 5 additions & 1 deletion docs/topics/testing/tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down