HttpPlugin¶
HttpPlugin
¶
Bases: BasePlugin
HTTP interception plugin. Requires python-tripwire[http] extra.
Patches httpx sync/async transports, requests HTTPAdapter, urllib openers, and aiohttp ClientSession (if installed) at the class level. Uses reference counting so nested sandboxes work correctly.
Source code in src/tripwire/plugins/http.py
config_key
classmethod
¶
load_config
¶
Apply [tool.tripwire.http] configuration.
Recognized keys: require_response (bool): When True, assert_request() returns an HttpAssertionBuilder requiring .assert_response() to complete the assertion. Default True.
Unknown keys are silently ignored for forward-compatibility. Raises TypeError for require_response with a non-bool value.
Source code in src/tripwire/plugins/http.py
assert_request
¶
Assert an HTTP request interaction, optionally requiring a chained response assertion.
When raised is provided, the assertion is always terminal (error
interactions have no response to chain). Returns None.
When require_response is False, this method is terminal:
it asserts only the four request fields and returns None.
When require_response is True, this method returns an
HttpAssertionBuilder.
Source code in src/tripwire/plugins/http.py
mock_response
¶
mock_response(method, url, *, json=None, body=None, status=200, headers=None, params=None, required=True)
Register a mock response for the given method + URL pair.
Source code in src/tripwire/plugins/http.py
mock_error
¶
Register a mock error for the given method + URL pair.
When the interceptor matches this mock, the interaction is recorded with request fields + raised, then the exception is re-raised into the code under test.
The error config is appended to the unified mock queue alongside HttpMockConfig entries, preserving FIFO ordering for mixed success/error sequences.
Source code in src/tripwire/plugins/http.py
pass_through
¶
Register a permanent pass-through rule for the given method + URL.
Requests matching this rule are forwarded to the real backend instead of raising UnmockedInteractionError. The interaction is still recorded on the timeline and must be asserted.
The URL must match exactly (scheme, host, path). Query parameters are not considered for pass-through rule matching.
Source code in src/tripwire/plugins/http.py
check_conflicts
¶
Verify httpx sync/async transports and requests adapter have not been patched by a third party.
Source code in src/tripwire/plugins/http.py
assertable_fields
¶
Return the field names required in **expected when asserting an HTTP interaction.
Error interactions (raised in details): request fields + raised. Request-only mode: four request fields. Full mode: all seven fields.