ClientMixin
Mixin with common methods between Client and AsyncClient.
Attributes
| Attribute | Type | Description |
|---|---|---|
| exc_info | tuple | Stores exception information when exceptions are generated by a view, used to track and re-raise errors during request processing. |
| raise_request_exception | boolean | A boolean flag that determines whether signaled exceptions should be re-raised when checking the response. |
| cookies | SimpleCookie | A cookie jar used to store and manage session identifiers and other persistent client-side data across requests. |
Methods
store_exc_info()
@classmethod
def store_exc_info(
**kwargs: dict
) - > null
Store exceptions when they are generated by a view.
Parameters
| Name | Type | Description |
|---|---|---|
| **kwargs | dict | Arbitrary keyword arguments passed during exception handling |
Returns
| Type | Description |
|---|---|
null |
check_exception()
@classmethod
def check_exception(
response: [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
) - > null
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.
Parameters
| Name | Type | Description |
|---|---|---|
| response | [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The response object to which the exception information will be attached |
Returns
| Type | Description |
|---|---|
null |
session()
@classmethod
def session() - > [SessionStore](../../contrib/sessions/backends/signed/cookies/sessionstore.md?sid=django_contrib_sessions_backends_signed_cookies_sessionstore)
Return the current session variables.
Returns
| Type | Description |
|---|---|
[SessionStore](../../contrib/sessions/backends/signed/cookies/sessionstore.md?sid=django_contrib_sessions_backends_signed_cookies_sessionstore) | The session store instance containing current session data; creates and saves a new session if one does not exist |
asession()
@classmethod
def asession() - > [SessionStore](../../contrib/sessions/backends/signed/cookies/sessionstore.md?sid=django_contrib_sessions_backends_signed_cookies_sessionstore)
Asynchronously retrieves or creates the current session variables.
Returns
| Type | Description |
|---|---|
[SessionStore](../../contrib/sessions/backends/signed/cookies/sessionstore.md?sid=django_contrib_sessions_backends_signed_cookies_sessionstore) | The session store instance containing current session data |
login()
@classmethod
def login(
**credentials: dict
) - > bool
Set the Factory to appear as if it has successfully logged into a site.
Parameters
| Name | Type | Description |
|---|---|---|
| **credentials | dict | Authentication credentials such as username and password used to validate the user |
Returns
| Type | Description |
|---|---|
bool | True if login is possible or False if the provided credentials are incorrect. |
alogin()
@classmethod
def alogin(
**credentials: dict
) - > bool
See login().
Parameters
| Name | Type | Description |
|---|---|---|
| **credentials | dict | Authentication credentials such as username and password used to validate the user |
Returns
| Type | Description |
|---|---|
bool | True if login is possible or False if the provided credentials are incorrect. |
force_login()
@classmethod
def force_login(
user: [User](../../contrib/auth/models/user.md?sid=django_contrib_auth_models_user),
backend: str = null
) - > null
Bypasses authentication to log in a specific user directly into the test client.
Parameters
| Name | Type | Description |
|---|---|---|
| user | [User](../../contrib/auth/models/user.md?sid=django_contrib_auth_models_user) | The user instance to be logged in |
| backend | str = null | The dotted path to the authentication backend to use for the session |
Returns
| Type | Description |
|---|---|
null |
aforce_login()
@classmethod
def aforce_login(
user: [User](../../contrib/auth/models/user.md?sid=django_contrib_auth_models_user),
backend: str = null
) - > null
Asynchronously bypasses authentication to log in a specific user directly into the test client.
Parameters
| Name | Type | Description |
|---|---|---|
| user | [User](../../contrib/auth/models/user.md?sid=django_contrib_auth_models_user) | The user instance to be logged in |
| backend | str = null | The dotted path to the authentication backend to use for the session |
Returns
| Type | Description |
|---|---|
null |
logout()
@classmethod
def logout() - > null
Log out the user by removing the cookies and session object.
Returns
| Type | Description |
|---|---|
null |
alogout()
@classmethod
def alogout() - > null
See logout().
Returns
| Type | Description |
|---|---|
null |