class documentation

class Client: (source)

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. .. versionchanged:: 2.1 Removed deprecated behavior of treating the response as a tuple. All data is available as properties on the returned response object. .. versionchanged:: 2.0 ``response_wrapper`` is always a subclass of :class:``TestResponse``. .. versionchanged:: 0.5 Added the ``use_cookies`` parameter.

Method __init__ Undocumented
Method __repr__ Undocumented
Method delete Call :meth:`open` with ``method`` set to ``DELETE``.
Method delete_cookie Deletes a cookie in the test client.
Method get Call :meth:`open` with ``method`` set to ``GET``.
Method head Call :meth:`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 :meth:`open` with ``method`` set to ``OPTIONS``.
Method patch Call :meth:`open` with ``method`` set to ``PATCH``.
Method post Call :meth:`open` with ``method`` set to ``POST``.
Method put Call :meth:`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 :meth:`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: WSGIApplication, response_wrapper: t.Optional[t.Type[Response]] = None, use_cookies: bool = True, allow_subdomain_redirects: bool = False): (source)

Undocumented

def __repr__(self) -> str: (source)

Undocumented

def delete(self, *args: t.Any, **kw: t.Any) -> TestResponse: (source)

Call :meth:`open` with ``method`` set to ``DELETE``.

def delete_cookie(self, server_name: str, key: str, path: str = '/', domain: t.Optional[str] = None, secure: bool = False, httponly: bool = False, samesite: t.Optional[str] = None): (source)

Deletes a cookie in the test client.

def get(self, *args: t.Any, **kw: t.Any) -> TestResponse: (source)

Call :meth:`open` with ``method`` set to ``GET``.

def head(self, *args: t.Any, **kw: t.Any) -> TestResponse: (source)

Call :meth:`open` with ``method`` set to ``HEAD``.

def open(self, *args: t.Any, buffered: bool = False, follow_redirects: bool = False, **kwargs: t.Any) -> TestResponse: (source)

Generate an environ dict from the given arguments, make a request to the application using it, and return the response. :param args: Passed to :class:`EnvironBuilder` to create the environ for the request. If a single arg is passed, it can be an existing :class:`EnvironBuilder` or an environ dict. :param buffered: Convert the iterator returned by the app into a list. If the iterator has a ``close()`` method, it is called automatically. :param follow_redirects: Make additional requests to follow HTTP redirects until a non-redirect status is returned. :attr:`TestResponse.history` lists the intermediate responses. .. versionchanged:: 2.1 Removed the ``as_tuple`` parameter. .. versionchanged:: 2.0 ``as_tuple`` is deprecated and will be removed in Werkzeug 2.1. Use :attr:`TestResponse.request` and ``request.environ`` instead. .. versionchanged:: 2.0 The request input stream is closed when calling ``response.close()``. Input streams for redirects are automatically closed. .. versionchanged:: 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 :class:`werkzeug.FileWrapper`. .. versionchanged:: 0.5 Added the ``follow_redirects`` parameter.

def options(self, *args: t.Any, **kw: t.Any) -> TestResponse: (source)

Call :meth:`open` with ``method`` set to ``OPTIONS``.

def patch(self, *args: t.Any, **kw: t.Any) -> TestResponse: (source)

Call :meth:`open` with ``method`` set to ``PATCH``.

def post(self, *args: t.Any, **kw: t.Any) -> TestResponse: (source)

Call :meth:`open` with ``method`` set to ``POST``.

def put(self, *args: t.Any, **kw: t.Any) -> TestResponse: (source)

Call :meth:`open` with ``method`` set to ``PUT``.

def resolve_redirect(self, response: TestResponse, buffered: bool = False) -> TestResponse: (source)

Perform a new request to the location given by the redirect response to the previous request. :meta private:

def run_wsgi_app(self, environ: WSGIEnvironment, buffered: bool = False) -> t.Tuple[t.Iterable[bytes], str, Headers]: (source)

Runs the wrapped WSGI app with the given environment. :meta private:

def set_cookie(self, server_name: str, key: str, value: str = '', max_age: t.Optional[t.Union[timedelta, int]] = None, expires: t.Optional[t.Union[str, datetime, int, float]] = None, path: str = '/', domain: t.Optional[str] = None, secure: bool = False, httponly: bool = False, samesite: t.Optional[str] = None, charset: str = 'utf-8'): (source)

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.

def trace(self, *args: t.Any, **kw: t.Any) -> TestResponse: (source)

Call :meth:`open` with ``method`` set to ``TRACE``.

allow_subdomain_redirects = (source)

Undocumented

application = (source)

Undocumented

Undocumented

response_wrapper = (source)

Undocumented