Responses¶
See the Responses & serializers guide for usage.
asyncly.srvmocker.responses.base.BaseMockResponse
¶
Bases: ABC
asyncly.srvmocker.responses.json.JsonResponse
¶
Bases: BaseMockResponse
A mock response that serializes body to JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
Any
|
Any JSON-serializable object. |
required |
status
|
int
|
HTTP status code to return. |
OK
|
headers
|
Mapping[str, str] | None
|
Extra response headers; |
None
|
Source code in asyncly/srvmocker/responses/json.py
asyncly.srvmocker.responses.raw.RawResponse
¶
Bases: BaseMockResponse
Return arbitrary bytes with arbitrary headers — useful for testing client behavior on malformed data, unexpected content-types, or empty bodies.
Source code in asyncly/srvmocker/responses/raw.py
asyncly.srvmocker.responses.content.ContentResponse
dataclass
¶
ContentResponse(
body: Any = None,
status: int = OK,
headers: Mapping[str, str] | None = None,
serializer: Serializer | None = None,
)
Bases: BaseMockResponse
General mock response: a body plus an explicit serializer.
The format-specific responses (JsonResponse, MsgpackResponse, ...) are
thin wrappers over this. Provide a Serializer to control the wire format
and Content-Type.
Attributes:
| Name | Type | Description |
|---|---|---|
body |
Any
|
The object to serialize (or raw value if no serializer). |
status |
int
|
HTTP status code to return. |
headers |
Mapping[str, str] | None
|
Extra response headers. |
serializer |
Serializer | None
|
Serializer pairing a |
asyncly.srvmocker.responses.sequence.SequenceResponse
¶
SequenceResponse(
responses: Iterable[BaseMockResponse],
on_exhausted: OnExhausted = "raise",
)
Bases: BaseMockResponse
Return a different response on each call, in order.
on_exhausted controls behavior after the last response is consumed:
"raise"(default) -- raise :class:SequenceExhaustedon the next call. Inside an aiohttp request handler this surfaces to clients as a 500."cycle"-- start over from the first response and loop indefinitely."last"-- keep returning the last response forever.
Constructing with an empty iterable raises ValueError eagerly.
Source code in asyncly/srvmocker/responses/sequence.py
asyncly.srvmocker.responses.timeout.LatencyResponse
dataclass
¶
LatencyResponse(
wrapped: BaseMockResponse, latency: TimeoutType
)
Bases: BaseMockResponse
Delay another response by a fixed latency — for testing timeouts.
Attributes:
| Name | Type | Description |
|---|---|---|
wrapped |
BaseMockResponse
|
The response to return after the delay. |
latency |
TimeoutType
|
Delay in seconds before responding. |
asyncly.srvmocker.responses.msgpack.MsgpackResponse
¶
Bases: BaseMockResponse
A mock response that serializes body to msgpack (needs msgspec).
Source code in asyncly/srvmocker/responses/msgpack.py
asyncly.srvmocker.responses.toml.TomlResponse
¶
Bases: BaseMockResponse
A mock response that serializes body to TOML.
Source code in asyncly/srvmocker/responses/toml.py
asyncly.srvmocker.responses.yaml.YamlResponse
¶
Bases: BaseMockResponse
A mock response that serializes body to YAML.