Classes
TestClient
10
▼
TestClient
10
▼
Methods
get
3
Response
▼
Send a GET request.
async
get
3
Response
▼
async def get(self, path: str, *, headers: dict[str, str] | None = None, query: dict[str, str] | None = None) -> Response
Parameters
| Name | Type | Description |
|---|---|---|
path |
— |
|
headers |
— |
Default:None
|
query |
— |
Default:None
|
Returns
Response
post
5
Response
▼
Send a POST request.
async
post
5
Response
▼
async def post(self, path: str, *, headers: dict[str, str] | None = None, body: bytes | None = None, data: dict[str, str] | None = None, json: dict[str, object] | None = None) -> Response
Parameters
| Name | Type | Description |
|---|---|---|
path |
— |
Request path. |
headers |
— |
Optional extra headers. Default:None
|
body |
— |
Raw body bytes. Default:None
|
data |
— |
Form data dict (URL-encoded). Default:None
|
json |
— |
JSON body dict. Default:None
|
Returns
Response
put
3
Response
▼
Send a PUT request.
async
put
3
Response
▼
async def put(self, path: str, *, headers: dict[str, str] | None = None, body: bytes | None = None) -> Response
Parameters
| Name | Type | Description |
|---|---|---|
path |
— |
|
headers |
— |
Default:None
|
body |
— |
Default:None
|
Returns
Response
delete
2
Response
▼
Send a DELETE request.
async
delete
2
Response
▼
async def delete(self, path: str, *, headers: dict[str, str] | None = None) -> Response
Parameters
| Name | Type | Description |
|---|---|---|
path |
— |
|
headers |
— |
Default:None
|
Returns
Response
fragment
7
Response
▼
Send a fragment request (sets HX-Request header).
async
fragment
7
Response
▼
async def fragment(self, path: str, *, method: str = 'GET', target: str | None = None, trigger: str | None = None, history_restore: bool = False, headers: dict[str, str] | None = None, body: bytes | None = None) -> Response
Parameters
| Name | Type | Description |
|---|---|---|
path |
— |
The URL path to request. |
method |
— |
HTTP method (default GET). Default:'GET'
|
target |
— |
Sets the None
|
trigger |
— |
Sets the None
|
history_restore |
— |
If True, sets False
|
headers |
— |
Additional headers to include. Default:None
|
body |
— |
Request body bytes (for POST/PUT). Default:None
|
Returns
Response
sse
5
SSETestResult
▼
Connect to an SSE endpoint and collect events.
The connection stays open until…
async
sse
5
SSETestResult
▼
async def sse(self, path: str, *, headers: dict[str, str] | None = None, max_events: int = 10, disconnect_after: float | None = None, timeout: float | None = None) -> SSETestResult
Connect to an SSE endpoint and collect events.
The connection stays open until one of:
max_eventsdata events have been collected, ordisconnect_after(ortimeout) seconds have elapsed, or- the server closes the stream (generator exhausted).
timeout is an alias for disconnect_after.
Returns anSSETestResultwith parsed events and metadata.
Usage::
result = await client.sse("/notifications", max_events=3)
assert len(result.events) == 3
assert result.events[0].data == "hello"
Parameters
| Name | Type | Description |
|---|---|---|
path |
— |
|
headers |
— |
Default:None
|
max_events |
— |
Default:10
|
disconnect_after |
— |
Default:None
|
timeout |
— |
Default:None
|
Returns
SSETestResult
request
4
Response
▼
Send an arbitrary request through the ASGI app.
async
request
4
Response
▼
async def request(self, method: str, path: str, *, headers: dict[str, str] | None = None, body: bytes | None = None) -> Response
Parameters
| Name | Type | Description |
|---|---|---|
method |
— |
|
path |
— |
|
headers |
— |
Default:None
|
body |
— |
Default:None
|
Returns
Response
Internal Methods 3 ▼
__init__
1
▼
__init__
1
▼
def __init__(self, app: App) -> None
Parameters
| Name | Type | Description |
|---|---|---|
app |
— |
__aenter__
0
TestClient
▼
async
__aenter__
0
TestClient
▼
async def __aenter__(self) -> TestClient
Returns
TestClient
__aexit__
1
▼
async
__aexit__
1
▼
async def __aexit__(self, *args: object) -> None
Parameters
| Name | Type | Description |
|---|---|---|
*args |
— |