Test provider
Provider verification for multipart/form-data contract with matching rules.
This test demonstrates provider verification for contracts with multipart requests and matching rules. It uses FastAPI to create a simple server that can process multipart uploads containing JSON metadata and a JPEG image. The test verifies that the provider complies with the contract generated by the consumer tests, ensuring that it can handle variations in the data while maintaining compatibility.
Attributes¶
app = FastAPI()
module-attribute
¶
FastAPI application to handle multipart/form-data uploads.
uploads: dict[str, dict[str, Any]] = {}
module-attribute
¶
In-memory store for uploaded files and metadata.
Classes¶
UploadMetadata
pydantic-model
¶
UploadResponse
pydantic-model
¶
Functions¶
app_server() -> str
¶
Start FastAPI server for provider verification.
Source code in examples/catalog/multipart_matching_rules/test_provider.py
test_provider_multipart(app_server: str) -> None
¶
Verify the provider against the multipart upload contract.
In general, there are no special considerations for verifying providers with multipart requests. The Pact verifier will read the contract file generated by the consumer tests and ensure that the provider can handle requests that conform to the specified matching rules.
As with any provider verification, the test needs to ensure that provider states are set up correctly. This example does not include any provider states to ensure simplicity.
Source code in examples/catalog/multipart_matching_rules/test_provider.py
upload_file(metadata: Annotated[str, Form()], image: Annotated[UploadFile, Form()]) -> UploadResponse
async
¶
Handle multipart upload with JSON metadata and image.
This endpoint processes a multipart/form-data request containing a JSON metadata part and an image file part. It validates the metadata structure and the image content type, then stores the upload in memory.