# quart.testing package

## Submodules

- quart.testing.app module
  - `LifespanError`
  - `TestApp`
    - `TestApp.test_client()`
    - `TestApp.startup()`
    - `TestApp.shutdown()`
- quart.testing.client module
  - `QuartClient`
    - `QuartClient.http_connection_class`
    - `QuartClient.websocket_connection_class`
    - `QuartClient.open()`
    - `QuartClient.request()`
    - `QuartClient.websocket()`
    - `QuartClient.delete()`
    - `QuartClient.get()`
    - `QuartClient.head()`
    - `QuartClient.options()`
    - `QuartClient.patch()`
    - `QuartClient.post()`
    - `QuartClient.put()`
    - `QuartClient.trace()`
    - `QuartClient.set_cookie()`
    - `QuartClient.delete_cookie()`
    - `QuartClient.session_transaction()`
- quart.testing.connections module
  - `HTTPDisconnectError`
  - `WebsocketDisconnectError`
  - `WebsocketResponseError`
  - `TestHTTPConnection`
    - `TestHTTPConnection.send()`
    - `TestHTTPConnection.send_complete()`
    - `TestHTTPConnection.receive()`
    - `TestHTTPConnection.disconnect()`
    - `TestHTTPConnection.as_response()`
  - `TestWebsocketConnection`
    - `TestWebsocketConnection.receive()`
    - `TestWebsocketConnection.send()`
    - `TestWebsocketConnection.receive_json()`
    - `TestWebsocketConnection.send_json()`
    - `TestWebsocketConnection.close()`
    - `TestWebsocketConnection.disconnect()`
- quart.testing.utils module
  - `make_test_headers_path_and_query_string()`
  - `make_test_body_with_headers()`
  - `make_test_scope()`
  - `no_op_push()`

## Module contents

quart.testing.make_test_body_with_headers(*, data=None, form=None, files=None, json=sentinel, app=None)

  Make the body bytes with associated headers.

  Parameters:

    - data (AnyStr | None) – Raw data to send in the request body.

    - form (dict | None) – Key value paired data to send form encoded in the request body.

    - files (dict[str, FileStorage] | None) – Key FileStorage paired data to send as file encoded in the request body.

    - json (Any) – Data to send json encoded in the request body.

    - app (Quart | None)

  Return type:

    tuple[bytes, Headers]

quart.testing.make_test_headers_path_and_query_string(app, path, headers=None, query_string=None, auth=None, subdomain=None)

  Make the headers and path with defaults for testing.

  Parameters:

    - app (Quart) – The application to test against.

    - path (str) – 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 (dict | Headers | None) – Initial headers to send.

    - query_string (dict | None) – To send as a dictionary, alternatively the query_string can be determined from the path.

    - auth (Authorization | tuple[str, str] | None)

    - subdomain (str | None)

  Return type:

    tuple[Headers, str, bytes]

quart.testing.make_test_scope(type_, path, method, headers, query_string, scheme, root_path, http_version, scope_base, *, _preserve_context=False)
  Parameters:

    - 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)

  Return type:

    HTTPScope | WebsocketScope | LifespanScope

async quart.testing.no_op_push(path, headers)

  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.

  Parameters:

    - path (str)

    - headers (Headers)

  Return type:

    None

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

  Bases: `object`

  Parameters:

    - app (Quart)

    - use_cookies (bool)

  async delete(*args, **kwargs)

    Make a DELETE request.

    See `open()` for argument details.

    Parameters:

      - args (Any)

      - kwargs (Any)

    Return type:

      Response

  delete_cookie(server_name, key, path='/', domain=None)

    Delete a cookie (set to expire immediately).

    Parameters:

      - server_name (str)

      - key (str)

      - path (str)

      - domain (str | None)

    Return type:

      None

  async get(*args, **kwargs)

    Make a GET request.

    See `open()` for argument details.

    Parameters:

      - args (Any)

      - kwargs (Any)

    Return type:

      Response

  async head(*args, **kwargs)

    Make a HEAD request.

    See `open()` for argument details.

    Parameters:

      - args (Any)

      - kwargs (Any)

    Return type:

      Response

  http_connection_class

    alias of `TestHTTPConnection`

  async open(path, *, method='GET', headers=None, data=None, form=None, files=None, query_string=None, json=sentinel, scheme='http', follow_redirects=False, root_path='', http_version='1.1', scope_base=None, auth=None, subdomain=None)
    Parameters:

      - path (str)

      - method (str)

      - headers (dict | Headers | None)

      - data (AnyStr | None)

      - form (dict | None)

      - files (dict[str, FileStorage] | None)

      - query_string (dict | None)

      - json (Any)

      - scheme (str)

      - follow_redirects (bool)

      - root_path (str)

      - http_version (str)

      - scope_base (dict | None)

      - auth (Authorization | tuple[str, str] | None)

      - subdomain (str | None)

    Return type:

      Response

  async options(*args, **kwargs)

    Make a OPTIONS request.

    See `open()` for argument details.

    Parameters:

      - args (Any)

      - kwargs (Any)

    Return type:

      Response

  async patch(*args, **kwargs)

    Make a PATCH request.

    See `open()` for argument details.

    Parameters:

      - args (Any)

      - kwargs (Any)

    Return type:

      Response

  async post(*args, **kwargs)

    Make a POST request.

    See `open()` for argument details.

    Parameters:

      - args (Any)

      - kwargs (Any)

    Return type:

      Response

  async put(*args, **kwargs)

    Make a PUT request.

    See `open()` for argument details.

    Parameters:

      - args (Any)

      - kwargs (Any)

    Return type:

      Response

  request(path, *, method='GET', headers=None, query_string=None, scheme='http', root_path='', http_version='1.1', scope_base=None, auth=None, subdomain=None)
    Parameters:

      - path (str)

      - method (str)

      - headers (dict | Headers | None)

      - query_string (dict | None)

      - scheme (str)

      - root_path (str)

      - http_version (str)

      - scope_base (dict | None)

      - auth (Authorization | tuple[str, str] | None)

      - subdomain (str | None)

    Return type:

      TestHTTPConnectionProtocol

  session_transaction(path='/', *, method='GET', headers=None, query_string=None, scheme='http', data=None, form=None, json=sentinel, root_path='', http_version='1.1', auth=None)
    Parameters:

      - path (str)

      - method (str)

      - headers (dict | Headers | None)

      - query_string (dict | None)

      - scheme (str)

      - data (AnyStr | None)

      - form (dict | None)

      - json (Any)

      - root_path (str)

      - http_version (str)

      - auth (Authorization | tuple[str, str] | None)

    Return type:

      AsyncGenerator[SessionMixin, None]

  set_cookie(server_name, key, value='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, samesite=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.

    Parameters:

      - server_name (str)

      - key (str)

      - value (str)

      - max_age (int | timedelta | None)

      - expires (int | float | datetime | None)

      - path (str)

      - domain (str | None)

      - secure (bool)

      - httponly (bool)

      - samesite (str)

    Return type:

      None

  async trace(*args, **kwargs)

    Make a TRACE request.

    See `open()` for argument details.

    Parameters:

      - args (Any)

      - kwargs (Any)

    Return type:

      Response

  websocket(path, *, headers=None, query_string=None, scheme='ws', subprotocols=None, root_path='', http_version='1.1', scope_base=None, auth=None, subdomain=None)
    Parameters:

      - path (str)

      - headers (dict | Headers | None)

      - query_string (dict | None)

      - scheme (str)

      - subprotocols (list[str] | None)

      - root_path (str)

      - http_version (str)

      - scope_base (dict | None)

      - auth (Authorization | tuple[str, str] | None)

      - subdomain (str | None)

    Return type:

      TestWebsocketConnectionProtocol

  websocket_connection_class

    alias of `TestWebsocketConnection`

class quart.testing.QuartCliRunner(app, **kwargs)

  Bases: `CliRunner`

  Parameters:

    - app (Quart)

    - kwargs (Any)

  invoke(cli=None, args=None, **kwargs)

    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 (Any) – the command to invoke

      - args (Any) – 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.

      - kwargs (Any)

    Return type:

      Any

    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.TestApp(app, startup_timeout=DEFAULT_TIMEOUT, shutdown_timeout=DEFAULT_TIMEOUT)

  Bases: `object`

  Parameters:

    - app (Quart)

    - startup_timeout (int)

    - shutdown_timeout (int)

  async shutdown()
    Return type:

      None

  async startup()
    Return type:

      None

  test_client()
    Return type:

      TestClientProtocol

exception quart.testing.WebsocketResponseError(response)

  Bases: `Exception`

  Parameters:

    response (Response)

  Return type:

    None