getsentry / responses

A utility for mocking out the Python Requests library.
Apache License 2.0
4.14k stars 354 forks source link

Store the initial request somewhere #633

Closed sshishov closed 1 year ago

sshishov commented 1 year ago

Hi dear developers, I would like to ask how we can access the initial request was made for the caught response?

In the beginning I was thinking that we can access it thought .request somehow...

rsp = responses.add(method=responses.POST, url='https://example.com/, body='my body content)
...
assert 'some data' in rsp.request.text

The question is... how we can assert that the request was done with some specific parameters. I know that there are matchers there but it does not look great to inject some matchers, especially for content inside the responses mock.

I would like to assert them separately...

beliaev-maksim commented 1 year ago

Overall, we attach the initial request to a response

sshishov commented 1 year ago

Hi @beliaev-maksim ,

Could you please show me how I can access it? Please note that the flow is the following:

Now inside the test I have only API-1 response which is completely different from one which I want to assert. I want to assert that through the flow the API-2 was called with specific body...

Thanks you for the help!

beliaev-maksim commented 1 year ago

In such case the best would be to use matchers

But you can explore the CallList object which stores calls history