class Client(ClientMixin, RequestFactory): (source)
A class that can act as a client for testing purposes. 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.
Method | __init__ |
Undocumented |
Method | delete |
Send a DELETE request to the server. |
Method | get |
Request a response from the server using GET. |
Method | head |
Request a response from the server using HEAD. |
Method | options |
Request a response from the server using OPTIONS. |
Method | patch |
Send a resource to the server using PATCH. |
Method | post |
Request a response from the server using POST. |
Method | put |
Send a resource to the server using PUT. |
Method | request |
Make a generic request. Compose the environment dictionary and pass 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. |
Method | trace |
Send a TRACE request to the server. |
Instance Variable | exc |
Undocumented |
Instance Variable | extra |
Undocumented |
Instance Variable | handler |
Undocumented |
Instance Variable | raise |
Undocumented |
Method | _handle |
Follow any redirects by requesting responses from the server using GET. |
Inherited from ClientMixin
:
Method | check |
Look for a signaled exception, clear the current context exception data, re-raise the signaled exception, and clear the signaled exception from the local cache. |
Method | force |
Undocumented |
Method | login |
Set the Factory to appear as if it has successfully logged into a site. |
Method | logout |
Log out the user by removing the cookies and session object. |
Method | store |
Store exceptions when they are generated by a view. |
Instance Variable | cookies |
Undocumented |
Property | session |
Return the current session variables. |
Method | _login |
Undocumented |
Method | _parse |
Undocumented |
Inherited from RequestFactory
(via ClientMixin
):
Method | generic |
Construct an arbitrary HTTP request. |
Instance Variable | defaults |
Undocumented |
Instance Variable | errors |
Undocumented |
Instance Variable | json |
Undocumented |
Method | _base |
The base environment for a request. |
Method | _encode |
Undocumented |
Method | _encode |
Return encoded JSON if data is a dict, list, or tuple and content_type is application/json. |
Method | _get |
Undocumented |
django.test.client.RequestFactory.delete
Send a DELETE request to the server.
Request a response from the server using OPTIONS.
django.test.client.RequestFactory.patch
Send a resource to the server using PATCH.
django.test.client.RequestFactory.post
Request a response from the server using POST.
django.test.client.RequestFactory.put
Send a resource to the server using PUT.
Make a generic request. Compose the environment dictionary and pass 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.