Reference
Testing¶
hinoki.testing.ASGIClient ¶
ASGIClient(
app: Hinoki,
strict_errors: bool = False,
*,
host: str | None = None,
)
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 ¶
SyncClient(
app: Hinoki,
timeout: float = 60.0,
*,
host: str | None = None,
)
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 ¶
ManualClock(start: datetime)