mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Fix for Serialization errors with JSON adapter
This patch aims to fix the issue#222, where json data in request can not be serialized because of TypeError in py3
This commit is contained in:
committed by
Kevin McCarthy
parent
528c9e7b1a
commit
9daf301deb
@@ -2,7 +2,8 @@
|
||||
import pytest
|
||||
|
||||
from vcr.compat import mock
|
||||
from vcr.serialize import deserialize
|
||||
from vcr.request import Request
|
||||
from vcr.serialize import deserialize, serialize
|
||||
from vcr.serializers import yamlserializer, jsonserializer
|
||||
|
||||
|
||||
@@ -83,3 +84,50 @@ def test_deserialize_py2py3_yaml_cassette(tmpdir, req_body, expect):
|
||||
def test_serialize_constructs_UnicodeDecodeError(mock_dumps):
|
||||
with pytest.raises(UnicodeDecodeError):
|
||||
jsonserializer.serialize({})
|
||||
|
||||
|
||||
def test_serialize_empty_request():
|
||||
request = Request(
|
||||
method='POST',
|
||||
uri='http://localhost/',
|
||||
body='',
|
||||
headers={},
|
||||
)
|
||||
|
||||
serialize(
|
||||
{'requests': [request], 'responses': [{}]},
|
||||
jsonserializer
|
||||
)
|
||||
|
||||
|
||||
def test_serialize_json_request():
|
||||
request = Request(
|
||||
method='POST',
|
||||
uri='http://localhost/',
|
||||
body="{'hello': 'world'}",
|
||||
headers={},
|
||||
)
|
||||
|
||||
serialize(
|
||||
{'requests': [request], 'responses': [{}]},
|
||||
jsonserializer
|
||||
)
|
||||
|
||||
|
||||
def test_serialize_binary_request():
|
||||
msg = "Does this HTTP interaction contain binary data?"
|
||||
|
||||
request = Request(
|
||||
method='POST',
|
||||
uri='http://localhost/',
|
||||
body=b'\x8c',
|
||||
headers={},
|
||||
)
|
||||
|
||||
try:
|
||||
serialize(
|
||||
{'requests': [request], 'responses': [{}]},
|
||||
jsonserializer
|
||||
)
|
||||
except (UnicodeDecodeError, TypeError) as exc:
|
||||
assert msg in str(exc)
|
||||
|
||||
Reference in New Issue
Block a user