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=False, **defaults)

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)

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=None, token=None)

Forcibly authenticate outgoing requests with the given user or token.

logout

logout()

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

request async

request(**kwargs)

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

get async

get(path, data=None, follow=False, secure=False, **extra)

Send a GET request.

post async

post(
    path,
    data=None,
    format=None,
    content_type=None,
    follow=False,
    secure=False,
    **extra,
)

Send a POST request with DRF-style format encoding.

put async

put(
    path,
    data=None,
    format=None,
    content_type=None,
    follow=False,
    secure=False,
    **extra,
)

Send a PUT request with DRF-style format encoding.

patch async

patch(
    path,
    data=None,
    format=None,
    content_type=None,
    follow=False,
    secure=False,
    **extra,
)

Send a PATCH request with DRF-style format encoding.

delete async

delete(
    path,
    data=None,
    format=None,
    content_type=None,
    follow=False,
    secure=False,
    **extra,
)

Send a DELETE request with DRF-style format encoding.

options async

options(
    path,
    data=None,
    format=None,
    content_type=None,
    follow=False,
    secure=False,
    **extra,
)

Send an OPTIONS request with DRF-style format encoding.

head async

head(path, data=None, follow=False, secure=False, **extra)

Send a HEAD request.

AsyncAPIRequestFactory

AsyncAPIRequestFactory(
    enforce_csrf_checks=False, **defaults
)

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, data=None, format=None, content_type=None, **extra
)

Construct a POST request with DRF-style format encoding.

put

put(
    path, data=None, format=None, content_type=None, **extra
)

Construct a PUT request with DRF-style format encoding.

patch

patch(
    path, data=None, format=None, content_type=None, **extra
)

Construct a PATCH request with DRF-style format encoding.

delete

delete(
    path, data=None, format=None, content_type=None, **extra
)

Construct a DELETE request with DRF-style format encoding.

options

options(
    path, data=None, format=None, content_type=None, **extra
)

Construct an OPTIONS request with DRF-style format encoding.

request

request(**kwargs)

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

force_authenticate

force_authenticate(request, user=None, token=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.