betamaxpy / betamax

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

Allow per cassette placeholder overrides with merging of defaults #97

Closed ekohl closed 8 years ago

ekohl commented 8 years ago

When you pass in placeholders per cassette, you lose all default placeholders (https://github.com/sigmavirus24/betamax/blob/4126cf86b778ef3c5fe31386040e62f7ee9c1641/betamax/cassette/cassette.py#L42-L45). I'd like to pass in additional overrides for generated content, but this shouldn't be global.

sigmavirus24 commented 8 years ago

That seems reasonable and along the lines of what VCR does.

We'll probably want to be a little careful with how we do this. We'll probably want to make placeholders not a list of dictionaries but instead something a bit more conductive to merging. We might want to do something like:

import collections

Placeholder = collections.namedtuple('Placeholder', ['replace', 'replace_with'])

And then store them as something like

{'<AUTHORIZATION>': Placeholder(replace='password', replace_with='<AUTHORIZATION>'), ...}
ekohl commented 8 years ago

Would you still accept a dict as a parameter and then convert it internally to the namedtuple? That would yield an easier API for me as a user.

sigmavirus24 commented 8 years ago

Would you still accept a dict as a parameter and then convert it internally to the namedtuple? That would yield an easier API for me as a user.

Absolutely

ekohl commented 8 years ago

I'm looking at writing a PR for this, but why would you use a namedtuple for this over a simple dict? The dict key is the value for replace_with.