Skip to content

Test client and case suite

Async-aware test utilities for restflow async views. See the Testing guide for picking the right base class and writing signal-driven cache invalidation tests.

AsyncAPIClient

AsyncAPIClient(
    enforce_csrf_checks: bool = False, **defaults: Any
)

Bases: AsyncClient

Async test client for restflow's AsyncAPIView and AsyncViewSet.

Drop-in for Django's AsyncClient and DRF's APIClient. Adds DRF-style format encoding (json by default), force_authenticate(), and credentials() so async views can be exercised end-to-end.

credentials

credentials(**kwargs: Any) -> None

Set headers used on every outgoing request. Keys must start with HTTP_ or CONTENT_ to mirror Django's WSGI environ convention.

force_authenticate

force_authenticate(
    user: Any = None, token: Any = None
) -> None

Forcibly authenticate outgoing requests with the given user or token.

logout

logout() -> None

Clear credentials, force-auth, and any active session.

request async

request(**kwargs: Any) -> _MonkeyPatchedASGIResponse

Make a generic async request, merging stored credentials into headers.

get async

get(
    path: _StrOrPromise,
    data: Any = None,
    follow: bool = False,
    secure: bool = False,
    **extra: Any,
) -> _MonkeyPatchedASGIResponse

Send a GET request.

post async

post(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    follow: bool = False,
    secure: bool = False,
    **extra: Any,
) -> _MonkeyPatchedASGIResponse

Send a POST request with DRF-style format encoding.

put async

put(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    follow: bool = False,
    secure: bool = False,
    **extra: Any,
) -> _MonkeyPatchedASGIResponse

Send a PUT request with DRF-style format encoding.

patch async

patch(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    follow: bool = False,
    secure: bool = False,
    **extra: Any,
) -> _MonkeyPatchedASGIResponse

Send a PATCH request with DRF-style format encoding.

delete async

delete(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    follow: bool = False,
    secure: bool = False,
    **extra: Any,
) -> _MonkeyPatchedASGIResponse

Send a DELETE request with DRF-style format encoding.

options async

options(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    follow: bool = False,
    secure: bool = False,
    **extra: Any,
) -> _MonkeyPatchedASGIResponse

Send an OPTIONS request with DRF-style format encoding.

head async

head(
    path: _StrOrPromise,
    data: Any = None,
    follow: bool = False,
    secure: bool = False,
    **extra: Any,
) -> _MonkeyPatchedASGIResponse

Send a HEAD request.

AsyncAPIRequestFactory

AsyncAPIRequestFactory(
    enforce_csrf_checks: bool = False, **defaults: Any
)

Bases: AsyncRequestFactory

Builds raw ASGI requests for tests that bind a request directly to a view instance and await dispatch.

Mirrors DRF's APIRequestFactory but produces ASGI-style requests suitable for await view.dispatch(request).

post

post(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    **extra: Any,
) -> ASGIRequest

Construct a POST request with DRF-style format encoding.

put

put(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    **extra: Any,
) -> ASGIRequest

Construct a PUT request with DRF-style format encoding.

patch

patch(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    **extra: Any,
) -> ASGIRequest

Construct a PATCH request with DRF-style format encoding.

delete

delete(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    **extra: Any,
) -> ASGIRequest

Construct a DELETE request with DRF-style format encoding.

options

options(
    path: _StrOrPromise,
    data: Any = None,
    format: str | None = None,
    content_type: str | None = None,
    **extra: Any,
) -> ASGIRequest

Construct an OPTIONS request with DRF-style format encoding.

request

request(**kwargs: Any) -> ASGIRequest

Construct a generic request, marking CSRF checks per the factory setting.

force_authenticate

force_authenticate(
    request: Any, user: Any = None, token: Any = None
) -> None

Force-authenticate a request, bypassing the authenticator chain.

AsyncAPISimpleTestCase

Bases: SimpleTestCase

Async-shaped SimpleTestCase wired up with AsyncAPIClient.

AsyncAPITestCase

Bases: TestCase

Async-shaped TestCase wired up with AsyncAPIClient.

AsyncAPITransactionTestCase

Bases: TransactionTestCase

Async-shaped TransactionTestCase wired up with AsyncAPIClient.

AsyncAPILiveServerTestCase

Bases: LiveServerTestCase

Async-shaped LiveServerTestCase wired up with AsyncAPIClient.