responses
responses copied to clipboard
Cannot match with callback
Describe the bug
When using standard responses you can use the matching behaviour but the callback API doesn't currently allow you to assert any calls to this callback
Additional context
No response
Version of responses
0.25.3
Steps to Reproduce
- Register callback 2.API currently returns None
Expected Result
API returns response we can then use with assert
Actual Result
The api returns none so we can't assert against it
Could you share an example of the code you're trying to make work?
resp = self.responses.add_callback(
responses.POST,
'http://example.com',
callback=fetch_invoice_pdf # Returns {}
)
assert resp.calls[0].request.body == {}
Currently resp will be None because add_callback returns None
I've just made a PR, but as a workaround you can do this:
self.responses.add_callback(
responses.POST,
'http://example.com',
callback=fetch_invoice_pdf # Returns {}
)
resp = self.responses._registry.registered[-1]
# or resp = responses._default_mock._registry.registered[-1]
assert resp.calls[0].request.body == {}