Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_recorder - matching http headers as well as URL #639

Open
stevelittlefish opened this issue May 22, 2023 · 5 comments · May be fixed by #641
Open

_recorder - matching http headers as well as URL #639

stevelittlefish opened this issue May 22, 2023 · 5 comments · May be fixed by #641
Assignees

Comments

@stevelittlefish
Copy link

For my project, I need to mock responses from an API where some of the parameters are included in a HTTP header, so for example I would make a request to http://api.com/projects with a http header set to user-id: joebloggs

Currently I am recording the responses by doing:

@_recorder.record(filepath="out.yaml")
def test_something():
    ...

and then I'm loading the yaml file like this:

@responses.activate
def test_something():
    responses.add_from_file("out.yaml")
    ...

Is it possible to set up the registry to match on this HTTP header, and also save this header in the .yaml files that it generates?

@beliaev-maksim
Copy link
Collaborator

fully legit request

I am working on the framework to record matchers as well

just to be sure, you are looking for matching request header as per https://github.com/getsentry/responses#request-headers-validation ?

@stevelittlefish
Copy link
Author

Yes I think so (although I haven't actually done it like that using this library as I have just been using the recorded files up until now).

I'm pretty sure I would want to do something like:

    responses.get(
        url="http://loginsystem.com/projects",
        match=[matchers.header_matcher({"Impersonate-User": "Mr. Bean"})],
    )

@beliaev-maksim
Copy link
Collaborator

Gotcha

Unfortunately, I cannot commit to any timeline, since it is pretty hard to accommodate all the matchers for the recorder. Need to think about some nice API that could be extended and that provides all the functionality for recording into file

@stevelittlefish
Copy link
Author

I know you can't commit to a timeline, (and I'm not trying to rush you), but would you be able to give some indication of whether it's likely to be weeks or months or longer?

I need to decide whether I am going to wait or try some other workaround / look for another solution in the meantime.

@beliaev-maksim
Copy link
Collaborator

beliaev-maksim commented May 23, 2023

in the best case by end of June
but likely to take more since we will need to iterate through the process

PS
consider applying manually responses with matchers in meantime

@beliaev-maksim beliaev-maksim linked a pull request May 28, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants