Class Client
A class that can act as a client for testing purposes.
Declaration
source linkDocumentation
It allows the user to compose GET and POST requests, and
obtain the response that the server gave to those requests.
The server Response objects are annotated with the details
of the contexts and templates that were rendered during the
process of serving the request.
Client objects are stateful - they will retain cookie (and
thus session) details for the lifetime of the Client instance.
This is not intended as a replacement for Twill/Selenium or
the like - it is here to allow testing against the
contexts and templates produced by a view, rather than the
HTML rendered to the end-user.
Methods
▶ def __init__(self, enforce_csrf_checks=False, raise_request_exception=True, **defaults) override ▶ def delete(self, path, data='', content_type='application/octet-stream', follow=False, ...) override Send a DELETE request to the server.
▶ def get(self, path, data=None, follow=False, secure=False, **extra) override Request a response from the server using GET.
▶ def head(self, path, data=None, follow=False, secure=False, **extra) override Request a response from the server using HEAD.
▶ def options(self, path, data='', content_type='application/octet-stream', follow=False, ...) override Request a response from the server using OPTIONS.
▶ def patch(self, path, data='', content_type='application/octet-stream', follow=False, ...) override Send a resource to the server using PATCH.
▶ def post(self, path, data=None, content_type=MULTIPART_CONTENT, follow=False, ...) override Request a response from the server using POST.
def post(
self,
path,
data=None,
content_type=MULTIPART_CONTENT,
follow=False,
secure=False,
**extra,
)
This method overrides django.test.client.RequestFactory.post.
▶ def put(self, path, data='', content_type='application/octet-stream', follow=False, ...) override Send a resource to the server using PUT.
▶ def request(self, **request) override The master request method. Compose the environment dictionary and pass
This method overrides django.test.client.RequestFactory.request.
to the handler, return the result of the handler. Assume defaults for
the query environment, which can be overridden using the arguments to
the request.
▶ def trace(self, path, data='', follow=False, secure=False, **extra) override Send a TRACE request to the server.