Skip to content

Instantly share code, notes, and snippets.

@pmilosev
Created November 15, 2022 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmilosev/9e398d8567bb1f03a817ae249d52e1ae to your computer and use it in GitHub Desktop.
Save pmilosev/9e398d8567bb1f03a817ae249d52e1ae to your computer and use it in GitHub Desktop.
Python tests - update VCR recording - example updates recorded Jira version
import sys
import vcr
import json
import ruamel.yaml
for argi in range(1, len(sys.argv)):
fin = open(sys.argv[argi], 'r')
fon = open(sys.argv[argi]+'.updated', 'w')
doc, ind, bsi = ruamel.yaml.util.load_yaml_guess_indent(fin)
for i in range (len(doc['interactions'])):
interaction = doc['interactions'][i]
print(interaction['request']['uri'])
if interaction['request']['uri'] != 'https://defectdojo.atlassian.net/rest/api/2/serverInfo':
print(' skipping ...')
continue
r = vcr.filters.decode_response(interaction['response'])
b = r['body']['string']
if type(b) != type(' '):
b = b.decode()
j = json.loads(b)
j['version'] = '8.4.0'
j['versionNumbers'] = [8, 4, 0]
b = json.dumps(j)
r['body']['string'] = b
interaction['response'] = r
doc['interactions'][i] = interaction
yaml = ruamel.yaml.YAML()
yaml.indent(mapping=ind, sequence=ind, offset=bsi)
yaml.dump(doc, fon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment