tests.custom_flask_client
Description
Classes
|
- class tests.custom_flask_client.CustomFlaskClient(*args: Any, **kwargs: Any)
- static after_request(response: flask.wrappers.Response)
- application: Flask
- static before_request(*args, **kwargs)
- delete(*args, **kwargs)
Like open but method is enforced to DELETE.
- delete_cookie(server_name: str, key: str, path: str = '/', domain: Optional[str] = None, secure: bool = False, httponly: bool = False, samesite: Optional[str] = None) None
Deletes a cookie in the test client.
- get(*args, **kwargs)
Like open but method is enforced to GET.
- make_request(method: str, *args, **kwargs)
- open(*args: Any, as_tuple: bool = False, buffered: bool = False, follow_redirects: bool = False, **kwargs: Any) Response
Generate an environ dict from the given arguments, make a request to the application using it, and return the response.
- Parameters
args – Passed to
EnvironBuilder
to create the environ for the request. If a single arg is passed, it can be an existingEnvironBuilder
or an environ dict.buffered – Convert the iterator returned by the app into a list. If the iterator has a
close()
method, it is called automatically.follow_redirects – Make additional requests to follow HTTP redirects until a non-redirect status is returned.
TestResponse.history
lists the intermediate responses.
Changed in version 2.0:
as_tuple
is deprecated and will be removed in Werkzeug 2.1. UseTestResponse.request
andrequest.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 calledcontent_type
instead ofmimetype
. This change was made for consistency withwerkzeug.FileWrapper
.Changed in version 0.5: Added the
follow_redirects
parameter.
- post(*args, **kwargs)
Like open but method is enforced to POST.
- preserve_context = False
- put(*args, **kwargs)
Like open but method is enforced to PUT.
- resolve_redirect(response: werkzeug.test.TestResponse, buffered: bool = False) werkzeug.test.TestResponse
Perform a new request to the location given by the redirect response to the previous request.
- run_wsgi_app(environ: WSGIEnvironment, buffered: bool = False) Tuple[Iterable[bytes], str, werkzeug.datastructures.Headers]
Runs the wrapped WSGI app with the given environment.
- session_transaction(*args: Any, **kwargs: Any) Generator[flask.sessions.SessionMixin, None, None]
When used in combination with a
with
statement this opens a session transaction. This can be used to modify the session that the test client uses. Once thewith
block is left the session is stored back.with client.session_transaction() as session: session['value'] = 42
Internally this is implemented by going through a temporary test request context and since session handling could depend on request variables this function accepts the same arguments as
test_request_context()
which are directly passed through.
- set_cookie(server_name: str, key: str, value: str = '', max_age: Optional[Union[datetime.timedelta, int]] = None, expires: Optional[Union[str, datetime.datetime, int, float]] = None, path: str = '/', domain: Optional[str] = None, secure: bool = False, httponly: bool = False, samesite: Optional[str] = None, charset: str = 'utf-8') None
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.