vcr: scrub ONE xmlrpc auth from recordings

master
Justin Riley 2016-08-03 11:38:10 -04:00
parent 17acd42c7d
commit 2c32c03ab4
1 changed files with 17 additions and 0 deletions

View File

@ -1,7 +1,23 @@
import os
import StringIO
import xml.etree.ElementTree as ET
from vcr import VCR
def scrub_auth(request):
xml = StringIO.StringIO(request.body)
tree = ET.parse(xml)
root = tree.getroot()
auth_param = tree.findall('./params/param/value/string')[0]
auth_param.text = 'someuser:sometoken'
scrubbed = StringIO.StringIO()
tree.write(scrubbed)
scrubbed.seek(0)
request.body = scrubbed.read()
return request
vcr = VCR(
serializer='yaml',
cassette_library_dir=os.path.join(
@ -10,4 +26,5 @@ vcr = VCR(
record_mode='once',
decode_compressed_response=True,
path_transformer=VCR.ensure_suffix('.yaml'),
before_record=scrub_auth,
)