class Client: (source)
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 |
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 |
Perform a new request to the location given by the redirect response to the previous request. |
Method | run |
Runs the wrapped WSGI app with the given environment. |
Method | set |
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 |
Undocumented |
Instance Variable | application |
Undocumented |
Instance Variable | cookie |
Undocumented |
Instance Variable | response |
Undocumented |
WSGIApplication
, response_wrapper: t.Optional[ t.Type[ Response]]
= None, use_cookies: bool
= True, allow_subdomain_redirects: bool
= False):
(source)
¶
Undocumented
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.
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.
TestResponse
, buffered: bool
= False) -> TestResponse
:
(source)
¶
Perform a new request to the location given by the redirect response to the previous request. :meta private:
WSGIEnvironment
, buffered: bool
= False) -> t.Tuple[ t.Iterable[ bytes], str, Headers]
:
(source)
¶
Runs the wrapped WSGI app with the given environment. :meta private:
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.