Created
November 15, 2022 09:08
-
-
Save pmilosev/9e398d8567bb1f03a817ae249d52e1ae to your computer and use it in GitHub Desktop.
Python tests - update VCR recording - example updates recorded Jira version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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