Skip to main content

ClientMixin

Mixin with common methods between Client and AsyncClient.

Attributes

AttributeTypeDescription
exc_infotupleStores exception information when exceptions are generated by a view, used to track and re-raise errors during request processing.
raise_request_exceptionbooleanA boolean flag that determines whether signaled exceptions should be re-raised when checking the response.
cookiesSimpleCookieA 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

NameTypeDescription
**kwargsdictArbitrary keyword arguments passed during exception handling

Returns

TypeDescription
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

NameTypeDescription
response[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)The response object to which the exception information will be attached

Returns

TypeDescription
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

TypeDescription
[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

TypeDescription
[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

NameTypeDescription
**credentialsdictAuthentication credentials such as username and password used to validate the user

Returns

TypeDescription
boolTrue if login is possible or False if the provided credentials are incorrect.

alogin()

@classmethod
def alogin(
**credentials: dict
) - > bool

See login().

Parameters

NameTypeDescription
**credentialsdictAuthentication credentials such as username and password used to validate the user

Returns

TypeDescription
boolTrue 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

NameTypeDescription
user[User](../../contrib/auth/models/user.md?sid=django_contrib_auth_models_user)The user instance to be logged in
backendstr = nullThe dotted path to the authentication backend to use for the session

Returns

TypeDescription
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

NameTypeDescription
user[User](../../contrib/auth/models/user.md?sid=django_contrib_auth_models_user)The user instance to be logged in
backendstr = nullThe dotted path to the authentication backend to use for the session

Returns

TypeDescription
null

logout()

@classmethod
def logout() - > null

Log out the user by removing the cookies and session object.

Returns

TypeDescription
null

alogout()

@classmethod
def alogout() - > null

See logout().

Returns

TypeDescription
null