Merge "Prevent JSON decode errors in the pre-record hook"
This commit is contained in:
commit
1bf7f3ffe0
@ -48,11 +48,13 @@ def pre_record_hook(interaction, cassette):
|
||||
- set token expiration time to an inifinite time.
|
||||
"""
|
||||
request_body = interaction.data['request']['body']
|
||||
parsed_content = json.loads(request_body['string'])
|
||||
mask_fixture_values(parsed_content, None)
|
||||
request_body['string'] = json.dumps(parsed_content)
|
||||
if request_body.get('string'):
|
||||
parsed_content = json.loads(request_body['string'])
|
||||
mask_fixture_values(parsed_content, None)
|
||||
request_body['string'] = json.dumps(parsed_content)
|
||||
|
||||
response_body = interaction.data['response']['body']
|
||||
parsed_content = json.loads(response_body['string'])
|
||||
mask_fixture_values(parsed_content, None)
|
||||
response_body['string'] = json.dumps(parsed_content)
|
||||
if response_body.get('string'):
|
||||
parsed_content = json.loads(response_body['string'])
|
||||
mask_fixture_values(parsed_content, None)
|
||||
response_body['string'] = json.dumps(parsed_content)
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
import betamax
|
||||
import json
|
||||
import mock
|
||||
from requests import models
|
||||
import testtools
|
||||
|
||||
@ -174,3 +175,24 @@ class TestBetamaxHooks(testtools.TestCase):
|
||||
u'dummy')
|
||||
self.assertEqual(
|
||||
request_content['auth']['tenantName'], u'dummy')
|
||||
|
||||
@mock.patch('keystoneauth1.fixture.hooks.mask_fixture_values')
|
||||
def test_pre_record_hook_empty_body(self, mask_fixture_values):
|
||||
interaction = mock.Mock()
|
||||
interaction.data = {
|
||||
'request': {
|
||||
'body': {
|
||||
'encoding': 'utf-8',
|
||||
'string': '',
|
||||
},
|
||||
},
|
||||
'response': {
|
||||
'body': {
|
||||
'encoding': 'utf-8',
|
||||
'string': '',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
hooks.pre_record_hook(interaction, mock.Mock())
|
||||
self.assertFalse(mask_fixture_values.called)
|
||||
|
Loading…
x
Reference in New Issue
Block a user