class documentation

class Client:

View In Hierarchy

This class allows you to send requests to a wrapped application.

The use_cookies parameter indicates whether cookies should be stored and sent for subsequent requests. This is True by default, but passing False will disable this behaviour.

If you want to request some subdomain of your application you may set allow_subdomain_redirects to True as if not no external redirects are allowed.

Changed in version 2.0: response_wrapper is always a subclass of TestResponse.
Changed in version 0.5: Added the use_cookies parameter.
Method __init__ Undocumented
Method __repr__ Undocumented
Method delete Call open with method set to DELETE.
Method delete​_cookie Deletes a cookie in the test client.
Method get Call open with method set to GET.
Method head Call open with method set to HEAD.
Method open Generate an environ dict from the given arguments, make a request to the application using it, and return the response.
Method options Call open with method set to OPTIONS.
Method patch Call open with method set to PATCH.
Method post Call open with method set to POST.
Method put Call open with method set to PUT.
Method resolve​_redirect Perform a new request to the location given by the redirect response to the previous request.
Method run​_wsgi​_app Runs the wrapped WSGI app with the given environment.
Method set​_cookie Sets a cookie in the client's cookie jar. The server name is required and has to match the one that is also passed to the open call.
Method trace Call open with method set to TRACE.
Instance Variable allow​_subdomain​_redirects Undocumented
Instance Variable application Undocumented
Instance Variable cookie​_jar Undocumented
Instance Variable response​_wrapper Undocumented
def __init__(self, application, response_wrapper=None, use_cookies=True, allow_subdomain_redirects=False):

Undocumented

Parameters
application:WSGIApplicationUndocumented
response​_wrapper:t.Optional[t.Type[Response]]Undocumented
use​_cookies:boolUndocumented
allow​_subdomain​_redirects:boolUndocumented
def __repr__(self):

Undocumented

Returns
strUndocumented
def delete(self, *args, **kw):
Call open with method set to DELETE.
Parameters
*args:t.AnyUndocumented
**kw:t.AnyUndocumented
Returns
TestResponseUndocumented
def delete_cookie(self, server_name, key, path='/', domain=None, secure=False, httponly=False, samesite=None):
Deletes a cookie in the test client.
Parameters
server​_name:strUndocumented
key:strUndocumented
path:strUndocumented
domain:t.Optional[str]Undocumented
secure:boolUndocumented
httponly:boolUndocumented
samesite:t.Optional[str]Undocumented
def get(self, *args, **kw):
Call open with method set to GET.
Parameters
*args:t.AnyUndocumented
**kw:t.AnyUndocumented
Returns
TestResponseUndocumented
def head(self, *args, **kw):
Call open with method set to HEAD.
Parameters
*args:t.AnyUndocumented
**kw:t.AnyUndocumented
Returns
TestResponseUndocumented
def open(self, *args, as_tuple=False, buffered=False, follow_redirects=False, **kwargs):

Generate an environ dict from the given arguments, make a request to the application using it, and return the response.

Changed in version 2.0: as_tuple is deprecated and will be removed in Werkzeug 2.1. Use TestResponse.request and request.environ instead.
Changed in version 2.0: The request input stream is closed when calling response.close(). Input streams for redirects are automatically closed.
Changed in version 0.5: If a dict is provided as file in the dict for the data parameter the content type has to be called content_type instead of mimetype. This change was made for consistency with werkzeug.FileWrapper.
Changed in version 0.5: Added the follow_redirects parameter.
Parameters
*args:t.AnyPassed to EnvironBuilder to create the environ for the request. If a single arg is passed, it can be an existing EnvironBuilder or an environ dict.
as​_tuple:boolUndocumented
buffered:boolConvert the iterator returned by the app into a list. If the iterator has a close() method, it is called automatically.
follow​_redirects:boolMake additional requests to follow HTTP redirects until a non-redirect status is returned. TestResponse.history lists the intermediate responses.
**kwargs:t.AnyUndocumented
Returns
TestResponseUndocumented
def options(self, *args, **kw):
Call open with method set to OPTIONS.
Parameters
*args:t.AnyUndocumented
**kw:t.AnyUndocumented
Returns
TestResponseUndocumented
def patch(self, *args, **kw):
Call open with method set to PATCH.
Parameters
*args:t.AnyUndocumented
**kw:t.AnyUndocumented
Returns
TestResponseUndocumented
def post(self, *args, **kw):
Call open with method set to POST.
Parameters
*args:t.AnyUndocumented
**kw:t.AnyUndocumented
Returns
TestResponseUndocumented
def put(self, *args, **kw):
Call open with method set to PUT.
Parameters
*args:t.AnyUndocumented
**kw:t.AnyUndocumented
Returns
TestResponseUndocumented
def resolve_redirect(self, response, buffered=False):
Perform a new request to the location given by the redirect response to the previous request.
Parameters
response:TestResponseUndocumented
buffered:boolUndocumented
Returns
TestResponseUndocumented
Unknown Field: meta
private
def run_wsgi_app(self, environ, buffered=False):
Runs the wrapped WSGI app with the given environment.
Parameters
environ:WSGIEnvironmentUndocumented
buffered:boolUndocumented
Returns
t.Tuple[t.Iterable[bytes], str, Headers]Undocumented
Unknown Field: meta
private
def set_cookie(self, server_name, key, value='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, samesite=None, charset='utf-8'):
Sets a cookie in the client's cookie jar. The server name is required and has to match the one that is also passed to the open call.
Parameters
server​_name:strUndocumented
key:strUndocumented
value:strUndocumented
max​_age:t.Optional[t.Union[timedelta, int]]Undocumented
expires:t.Optional[t.Union[str, datetime, int, float]]Undocumented
path:strUndocumented
domain:t.Optional[str]Undocumented
secure:boolUndocumented
httponly:boolUndocumented
samesite:t.Optional[str]Undocumented
charset:strUndocumented
def trace(self, *args, **kw):
Call open with method set to TRACE.
Parameters
*args:t.AnyUndocumented
**kw:t.AnyUndocumented
Returns
TestResponseUndocumented
allow_subdomain_redirects =

Undocumented

application =

Undocumented

cookie_jar: t.Optional[_TestCookieJar] =

Undocumented

response_wrapper =

Undocumented