-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Description
Betamax supports uri substitution (
betamax/src/betamax/cassette/interaction.py
Lines 99 to 107 in 2c12cee
def replace_in_uri(self, text_to_replace, placeholder): | |
if text_to_replace == '': | |
return | |
for (obj, key) in (('request', 'uri'), ('response', 'url')): | |
uri = self.data[obj][key] | |
if text_to_replace in uri: | |
self.data[obj][key] = uri.replace( | |
text_to_replace, placeholder | |
) |
from urllib.parse import urlparse, parse_qs, quote
def filter_requests(interaction, current_cassette):
token = parse_qs(urlparse(interaction.data['request']['uri']).query).get('authz')
if token is not None:
current_cassette.placeholders.append(
betamax.cassette.cassette.Placeholder(
placeholder='EOS_TOKEN', replace=quote(token[0])
)
)
betamax.Betamax.register_serializer(pretty_json.PrettyJSONSerializer)
with betamax.Betamax.configure() as config:
config.default_cassette_options['serialize_with'] = 'prettyjson'
config.before_record(callback=filter_requests)
It would be nice if betamax checked for the quoted value as well, because you don't get it at the time of filtering the requests through the interaction?
Metadata
Metadata
Assignees
Labels
No labels