betamaxpy / betamax

A VCR imitation designed only for python-requests.
https://betamax.readthedocs.io/en/latest/
Other
565 stars 62 forks source link

Is it possible to write custom cassettes, without formatting, after following some syntax? #138

Closed meetmangukiya closed 7 years ago

meetmangukiya commented 7 years ago

I want to use betamax to record and use cassettes that needs to provide authorization and I wouldn't like to write the credentials in the source code.

Pardon me if this is already possible. I stumbled upon betamax while trying to find a way to test api response related functions, etc.

sigmavirus24 commented 7 years ago

Hi @meetmangukiya did you happen to see http://betamax.readthedocs.io/en/latest/configuring.html#filtering-sensitive-data ? Is that somehow insufficient for you? Is there a clear way to improve that documentation that would help you?

meetmangukiya commented 7 years ago

Hey @sigmavirus24 thanks for the link, I tried following the guide, but it seems that betamax doesn't record all the subsequent requests... see :point_down:

with recorder.use_cassette('github'):
    gh = Github.get_gh_obj(token)
    emoji_dict = gh.emojis()
    assert "smile" in emoji_dict

Github.get_gh_obj

    @staticmethod
    def get_gh_obj(token):
        """
        :returns:   A github3 github object.
        """
        return github3.login(token=token)    

So, I think it only works for requests made directly? Requests from other objects are not recorded?

sigmavirus24 commented 7 years ago

@meetmangukiya you really need to read the documentation. The problems you're having are explained very clearly there. Betamax does not globally magically monkey-patch every Requests Session you might instantiate. It only patches sessions you tell it to. As such, you've not provided the session to github3 and it creates its own (if you're using the library I think you are).