Test provider
Provider verification for binary payloads with matching rules.
This test runs a small FastAPI provider which
stores opaque binary blobs, and verifies it against the contract generated by
test_consumer.py.
The interesting part of provider verification for binary payloads is that the
contract does not contain an exact byte sequence: the contentType matching
rule only requires the payload to be of the declared type. The provider state
handler below therefore seeds the store with a payload which differs from the
example bytes in the contract, and verification still passes.
The provider must still return the correct Content-Type; the matching rule
constrains the content type of the payload, so returning application/json or
omitting the header will cause a mismatch.
Attributes¶
BLOBS: dict[str, bytes] = {}
module-attribute
¶
PROVIDER_BLOB = bytes([0, 66, 19, 55, 255, 127, 1])
module-attribute
¶
RECEIVED_SIZES: list[int] = []
module-attribute
¶
SERVED_SIZES: list[int] = []
module-attribute
¶
app = FastAPI()
module-attribute
¶
FastAPI application serving a binary blob store.
Classes¶
Functions:¶
app_server() -> str
¶
Run the FastAPI server for provider verification.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The base URL of the running FastAPI server. |
Source code in examples/catalog/binary_payloads/test_provider.py
download_blob(blob_id: str) -> Response
async
¶
Return a stored binary payload.
| PARAMETER | DESCRIPTION |
|---|---|
blob_id
|
The ID of the blob to return.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
The raw payload, served as |
| RAISES | DESCRIPTION |
|---|---|
HTTPException
|
If no blob exists with the given ID. |
Source code in examples/catalog/binary_payloads/test_provider.py
seed_blob(action: Literal['setup', 'teardown'], parameters: dict[str, Any]) -> None
¶
Populate the blob store before an interaction which needs a stored blob.
| PARAMETER | DESCRIPTION |
|---|---|
action
|
Either
TYPE:
|
parameters
|
State parameters from the consumer contract. Must contain the
|
Source code in examples/catalog/binary_payloads/test_provider.py
test_provider(app_server: str) -> None
¶
Verify the provider against the binary payload contract.
The verifier replays the interactions from the contract generated by the consumer tests. Binary request bodies are compared using the matching rules from the contract, and binary response bodies are verified the same way, so the provider may return any payload of the declared content type.
The "a binary blob exists" provider state seeds the store with
PROVIDER_BLOB, whose bytes differ from the example in the contract.
Verification passes because the contract only requires
application/octet-stream.
Source code in examples/catalog/binary_payloads/test_provider.py
upload_blob(request: Request) -> dict[str, str | int]
async
¶
Store an uploaded binary payload and return its metadata.
| PARAMETER | DESCRIPTION |
|---|---|
request
|
The incoming request. Its raw body is read without any parsing, as the payload is opaque binary data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str | int]
|
The ID of the stored blob and the size of the payload in bytes. |