1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 01:25:34 +00:00

Merge pull request #279 from kevin1024/fix_nonetype_encode_exception

Fix nonetype encode exception
This commit is contained in:
Kevin McCarthy
2016-10-02 12:09:55 -10:00
committed by GitHub
2 changed files with 8 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ import pytest
from vcr.compat import mock from vcr.compat import mock
from vcr.request import Request from vcr.request import Request
from vcr.serialize import deserialize, serialize from vcr.serialize import deserialize, serialize
from vcr.serializers import yamlserializer, jsonserializer from vcr.serializers import yamlserializer, jsonserializer, compat
def test_deserialize_old_yaml_cassette(): def test_deserialize_old_yaml_cassette():
@@ -131,3 +131,9 @@ def test_serialize_binary_request():
) )
except (UnicodeDecodeError, TypeError) as exc: except (UnicodeDecodeError, TypeError) as exc:
assert msg in str(exc) assert msg in str(exc)
def test_deserialize_no_body_string():
data = {'body': {'string': None}}
output = compat.convert_to_bytes(data)
assert data == output

View File

@@ -24,7 +24,7 @@ def convert_body_to_bytes(resp):
http://pyyaml.org/wiki/PyYAMLDocumentation#Python3support http://pyyaml.org/wiki/PyYAMLDocumentation#Python3support
""" """
try: try:
if not isinstance(resp['body']['string'], six.binary_type): if resp['body']['string'] is not None and not isinstance(resp['body']['string'], six.binary_type):
resp['body']['string'] = resp['body']['string'].encode('utf-8') resp['body']['string'] = resp['body']['string'].encode('utf-8')
except (KeyError, TypeError, UnicodeEncodeError): except (KeyError, TypeError, UnicodeEncodeError):
# The thing we were converting either wasn't a dictionary or didn't # The thing we were converting either wasn't a dictionary or didn't