pre-alpha

5.14 · Reference

Testing

hinoki.testing.ASGIClient

Use as an async context manager so startup and shutdown always run.

request async

request(
    method: str,
    path: str,
    *,
    json: Any = None,
    body: bytes = b"",
    data: FormInput | None = None,
    files: FileInput | None = None,
    query: str = "",
    headers: HeaderInput | None = None,
    token: str | None = None,
) -> Response

One request, including JSON or multipart test payloads.

check_declared

check_declared(
    method: str, path: str, reply: Response
) -> None

With strict_errors=True: an error answer whose code the action did not declare (errors=...) and the framework does not produce by itself is an AssertionError. Catches business errors missing from OpenAPI.

query async

query(path: str, **options: Any) -> Response

An HTTP QUERY request (json= is its body; the query= option is still the query string).

hinoki.testing.SyncClient

The same client for tests written without async: the application runs on its own event loop in a background thread and every call blocks until the answer arrives (at most timeout seconds).

with SyncClient(create_app()) as client:
    assert client.get("/health").status == 200

Use it only inside the with block. Sync model calls (Model.get, create) work inside the application's sync handlers, not in the test body itself: seed and inspect data with an async fixture or your own connection.

hinoki.testing.ManualClock

A thread-safe, controllable UTC clock for deterministic tests.

set

set(value: datetime) -> None

Set the current instant; value must be timezone-aware.

advance

advance(*, seconds: float = 0) -> datetime

Advance by elapsed seconds and return the new UTC instant.