responses icon indicating copy to clipboard operation
responses copied to clipboard

Cannot match with callback

Open jcampbell05 opened this issue 1 year ago • 2 comments

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

  1. 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

jcampbell05 avatar Jul 08 '24 13:07 jcampbell05

Could you share an example of the code you're trying to make work?

markstory avatar Jul 08 '24 20:07 markstory

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

jcampbell05 avatar Jul 09 '24 17:07 jcampbell05

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 == {}

kleptog avatar Jul 22 '25 13:07 kleptog