quart.testing package#
Submodules#
- quart.testing.app module
- quart.testing.client module
QuartClient
QuartClient.delete()
QuartClient.delete_cookie()
QuartClient.get()
QuartClient.head()
QuartClient.http_connection_class
QuartClient.open()
QuartClient.options()
QuartClient.patch()
QuartClient.post()
QuartClient.put()
QuartClient.request()
QuartClient.session_transaction()
QuartClient.set_cookie()
QuartClient.trace()
QuartClient.websocket()
QuartClient.websocket_connection_class
- quart.testing.connections module
- quart.testing.utils module
Module contents#
- class quart.testing.QuartCliRunner(app: Quart, **kwargs: Any)#
Bases:
CliRunner
- invoke(cli: Any = None, args: Any = None, **kwargs: Any) Any #
Invokes a command in an isolated environment. The arguments are forwarded directly to the command line script, the extra keyword arguments are passed to the
main()
function of the command.This returns a
Result
object.- Parameters:
cli – the command to invoke
args – the arguments to invoke. It may be given as an iterable or a string. When given as string it will be interpreted as a Unix shell command. More details at
shlex.split()
.input – the input data for sys.stdin.
env – the environment overrides.
catch_exceptions – Whether to catch any other exceptions than
SystemExit
.extra – the keyword arguments to pass to
main()
.color – whether the output should contain color codes. The application can still override this explicitly.
Changed in version 8.0: The result object has the
return_value
attribute with the value returned from the invoked command.Changed in version 4.0: Added the
color
parameter.Changed in version 3.0: Added the
catch_exceptions
parameter.Changed in version 3.0: The result object has the
exc_info
attribute with the traceback if available.
- class quart.testing.QuartClient(app: Quart, use_cookies: bool = True)#
Bases:
object
- async delete(*args: Any, **kwargs: Any) Response #
Make a DELETE request.
See
open()
for argument details.
- delete_cookie(server_name: str, key: str, path: str = '/', domain: str | None = None) None #
Delete a cookie (set to expire immediately).
- async get(*args: Any, **kwargs: Any) Response #
Make a GET request.
See
open()
for argument details.
- async head(*args: Any, **kwargs: Any) Response #
Make a HEAD request.
See
open()
for argument details.
- http_connection_class#
alias of
TestHTTPConnection
- async open(path: str, *, method: str = 'GET', headers: dict | ~werkzeug.datastructures.headers.Headers | None = None, data: AnyStr | None = None, form: dict | None = None, files: dict[str, ~quart.datastructures.FileStorage] | None = None, query_string: dict | None = None, json: ~typing.Any = <object object>, scheme: str = 'http', follow_redirects: bool = False, root_path: str = '', http_version: str = '1.1', scope_base: dict | None = None, auth: ~werkzeug.datastructures.auth.Authorization | tuple[str, str] | None = None, subdomain: str | None = None) Response #
- async options(*args: Any, **kwargs: Any) Response #
Make a OPTIONS request.
See
open()
for argument details.
- async patch(*args: Any, **kwargs: Any) Response #
Make a PATCH request.
See
open()
for argument details.
- async post(*args: Any, **kwargs: Any) Response #
Make a POST request.
See
open()
for argument details.
- async put(*args: Any, **kwargs: Any) Response #
Make a PUT request.
See
open()
for argument details.
- request(path: str, *, method: str = 'GET', headers: dict | Headers | None = None, query_string: dict | None = None, scheme: str = 'http', root_path: str = '', http_version: str = '1.1', scope_base: dict | None = None, auth: Authorization | tuple[str, str] | None = None, subdomain: str | None = None) TestHTTPConnectionProtocol #
- session_transaction(path: str = '/', *, method: str = 'GET', headers: dict | ~werkzeug.datastructures.headers.Headers | None = None, query_string: dict | None = None, scheme: str = 'http', data: AnyStr | None = None, form: dict | None = None, json: ~typing.Any = <object object>, root_path: str = '', http_version: str = '1.1', auth: ~werkzeug.datastructures.auth.Authorization | tuple[str, str] | None = None) AsyncGenerator[SessionMixin, None] #
- set_cookie(server_name: str, key: str, value: str = '', max_age: int | timedelta | None = None, expires: int | float | datetime | None = None, path: str = '/', domain: str | None = None, secure: bool = False, httponly: bool = False, samesite: str = None) None #
Set a cookie in the cookie jar.
The arguments are the standard cookie morsels and this is a wrapper around the stdlib SimpleCookie code.
- async trace(*args: Any, **kwargs: Any) Response #
Make a TRACE request.
See
open()
for argument details.
- websocket(path: str, *, headers: dict | Headers | None = None, query_string: dict | None = None, scheme: str = 'ws', subprotocols: list[str] | None = None, root_path: str = '', http_version: str = '1.1', scope_base: dict | None = None, auth: Authorization | tuple[str, str] | None = None, subdomain: str | None = None) TestWebsocketConnectionProtocol #
- websocket_connection_class#
alias of
TestWebsocketConnection
- class quart.testing.TestApp(app: Quart, startup_timeout: int = 6, shutdown_timeout: int = 6)#
Bases:
object
- async shutdown() None #
- async startup() None #
- test_client() TestClientProtocol #
- quart.testing.make_test_body_with_headers(*, data: AnyStr | None = None, form: dict | None = None, files: dict[str, FileStorage] | None = None, json: Any = <object object>, app: Quart | None = None) tuple[bytes, Headers] #
Make the body bytes with associated headers.
- Parameters:
data – Raw data to send in the request body.
form – Key value paired data to send form encoded in the request body.
files – Key FileStorage paired data to send as file encoded in the request body.
json – Data to send json encoded in the request body.
- quart.testing.make_test_headers_path_and_query_string(app: Quart, path: str, headers: dict | Headers | None = None, query_string: dict | None = None, auth: Authorization | tuple[str, str] | None = None, subdomain: str | None = None) tuple[Headers, str, bytes] #
Make the headers and path with defaults for testing.
- Parameters:
app – The application to test against.
path – The path to request. If the query_string argument is not defined this argument will be partitioned on a ‘?’ with the following part being considered the query_string.
headers – Initial headers to send.
query_string – To send as a dictionary, alternatively the query_string can be determined from the path.
- quart.testing.make_test_scope(type_: str, path: str, method: str, headers: Headers, query_string: bytes, scheme: str, root_path: str, http_version: str, scope_base: dict | None, *, _preserve_context: bool = False) HTTPScope | WebsocketScope | LifespanScope #
- async quart.testing.no_op_push(path: str, headers: Headers) None #
A push promise sender that does nothing.
This is best used when creating Request instances for testing outside of the QuartClient. The Request instance must know what to do with push promises, and this gives it the option of doing nothing.