quart.testing module

class quart.testing.QuartClient(app: Quart, use_cookies: bool = True)

Bases: object

A Client bound to an app for testing.

This should be used to make requests and receive responses from the app for testing purposes. This is best used via test_client method.

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.

async open(path: str, *, method: str = 'GET', headers: Union[dict, quart.datastructures.CIMultiDict, None] = None, data: Optional[AnyStr] = None, form: Optional[dict] = 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') → quart.wrappers.response.Response

Open a request to the app associated with this client.

Parameters
  • 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.

  • method – The method to make the request with, defaults to ‘GET’.

  • headers – Headers to include in the request.

  • data – Raw data to send in the request body.

  • form – Data to send form encoded in the request body.

  • query_string – To send as a dictionary, alternatively the query_string can be determined from the path.

  • json – Data to send json encoded in the request body.

  • scheme – The scheme to use in the request, default http.

  • follow_redirects – Whether or not a redirect response should be followed, defaults to False.

Returns

The response from the app handling the request.

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.

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: Union[dict, quart.datastructures.CIMultiDict, None] = None, query_string: Optional[dict] = None, scheme: str = 'http', subprotocols: Optional[List[str]] = None, root_path: str = '', http_version: str = '1.1') → AsyncGenerator[quart.testing._TestingWebsocket, None]
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, json: Any = <object object>, app: Optional[Quart] = None) → Tuple[bytes, quart.datastructures.CIMultiDict]

Make the body bytes with associated headers.

Parameters
  • data – Raw data to send in the request body.

  • form – Data to send form 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: Union[dict, quart.datastructures.CIMultiDict, None] = None, query_string: Optional[dict] = None) → Tuple[quart.datastructures.CIMultiDict, 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.

async quart.testing.no_op_push(path: str, headers: quart.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.