quart.testing package

Module contents

class quart.testing.QuartCliRunner(app: Quart, **kwargs: Any)

Bases: click.testing.CliRunner

invoke(cli: Optional[Any] = None, args: Optional[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)quart.wrappers.response.Response

Make a DELETE request.

See open() for argument details.

Delete a cookie (set to expire immediately).

async get(*args: Any, **kwargs: Any)quart.wrappers.response.Response

Make a GET request.

See open() for argument details.

async head(*args: Any, **kwargs: Any)quart.wrappers.response.Response

Make a HEAD request.

See open() for argument details.

http_connection_class

alias of quart.testing.connections.TestHTTPConnection

async open(path: str, *, method: str = 'GET', headers: Optional[Union[dict, werkzeug.datastructures.Headers]] = None, data: Optional[AnyStr] = None, form: Optional[dict] = None, files: Optional[Dict[str, quart.datastructures.FileStorage]] = None, query_string: Optional[dict] = None, json: Any = <object object>, scheme: str = 'http', follow_redirects: bool = False, root_path: str = '', http_version: str = '1.1', scope_base: Optional[dict] = None)quart.wrappers.response.Response
async options(*args: Any, **kwargs: Any)quart.wrappers.response.Response

Make a OPTIONS request.

See open() for argument details.

async patch(*args: Any, **kwargs: Any)quart.wrappers.response.Response

Make a PATCH request.

See open() for argument details.

async post(*args: Any, **kwargs: Any)quart.wrappers.response.Response

Make a POST request.

See open() for argument details.

async put(*args: Any, **kwargs: Any)quart.wrappers.response.Response

Make a PUT request.

See open() for argument details.

request(path: str, *, method: str = 'GET', headers: Optional[Union[dict, werkzeug.datastructures.Headers]] = None, query_string: Optional[dict] = None, scheme: str = 'http', root_path: str = '', http_version: str = '1.1', scope_base: Optional[dict] = None)quart.typing.TestHTTPConnectionProtocol
session_transaction(path: str = '/', *, method: str = 'GET', headers: Optional[Union[dict, werkzeug.datastructures.Headers]] = None, query_string: Optional[dict] = None, scheme: str = 'http', data: Optional[AnyStr] = None, form: Optional[dict] = None, json: Any = <object object>, root_path: str = '', http_version: str = '1.1')AsyncGenerator[quart.sessions.SessionMixin, 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)quart.wrappers.response.Response

Make a TRACE request.

See open() for argument details.

websocket(path: str, *, headers: Optional[Union[dict, werkzeug.datastructures.Headers]] = None, query_string: Optional[dict] = None, scheme: str = 'ws', subprotocols: Optional[List[str]] = None, root_path: str = '', http_version: str = '1.1', scope_base: Optional[dict] = None)quart.typing.TestWebsocketConnectionProtocol
websocket_connection_class

alias of quart.testing.connections.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()quart.typing.TestClientProtocol
exception quart.testing.WebsocketResponse(response: quart.wrappers.response.Response)

Bases: Exception

quart.testing.make_test_body_with_headers(*, data: Optional[AnyStr] = None, form: Optional[dict] = None, files: Optional[Dict[str, FileStorage]] = None, json: Any = <object object>, app: Optional['Quart'] = 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: Optional[Union[dict, Headers]] = None, query_string: Optional[dict] = 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: werkzeug.datastructures.Headers, query_string: bytes, scheme: str, root_path: str, http_version: str, scope_base: Optional[dict], *, _preserve_context: bool = False)Union[hypercorn.typing.HTTPScope, hypercorn.typing.WebsocketScope, hypercorn.typing.LifespanScope]
async quart.testing.no_op_push(path: str, headers: werkzeug.datastructures.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.