API Reference¶
Package for serving WireMock stubs with Python HTTP mocking libraries.
- wiremock_mock.add_wiremock_to_responses(*, mock_obj: RequestsMock, stubs: Mapping[str, object], base_url: str) None¶
Add mock routes from WireMock stubs to a responses mock.
Request matching and response fields are the same as for
add_wiremock_to_respx(), except that customstatusMessagevalues are not supported by responses.- Parameters:
mock_obj – The responses RequestsMock to add routes to.
stubs – WireMock stubs dict with
mappingsarray (e.g. fromjson.loads(path.read_text())).base_url – Base URL for all routes.
- wiremock_mock.add_wiremock_to_respx(*, mock_obj: MockRouter | Router, stubs: Mapping[str, object], base_url: str) None¶
Add mock routes from WireMock stubs to a respx mock/router.
Supports request matching by: - method -
urlPath(exact) orurlPathPattern(regex) -queryParameterswithequalTo-bodyPatterns(equalToJson,contains,equalTo)equalToJsonsupports theignoreArrayOrderandignoreExtraElementsoptions. MultiplebodyPatternson a single stub must all match, letting two requests to the same method and URL return different responses based on their bodies.Response supports
status,statusMessage,headers,jsonBody,bodyandbase64Bodyfrom each stub.- Parameters:
mock_obj – The respx MockRouter or Router to add routes to.
stubs – WireMock stubs dict with
mappingsarray (e.g. fromjson.loads(path.read_text())).base_url – Base URL for all routes. Must match
respx.mock().
- wiremock_mock.create_httpx2_transport(*, stubs: Mapping[str, object], base_url: str) MockTransport¶
Create a native HTTPX2 transport loaded with WireMock stubs.
Supports the same request matching and response fields as
add_wiremock_to_respx(). Requests that do not match a mapping raisehttpx2.ConnectErrorrather than reaching the network.- Parameters:
stubs – WireMock stubs dict with
mappingsarray (e.g. fromjson.loads(path.read_text())).base_url – Base URL for all routes.
- Returns:
A mock transport for
httpx2.Clientorhttpx2.AsyncClient.