1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 09:13:23 +00:00

Merge pull request #244 from jaysonsantos/master

Avoid concatenating bytes with strings
This commit is contained in:
Kevin McCarthy
2016-04-26 08:59:07 -04:00
5 changed files with 26 additions and 10 deletions

View File

@@ -1,12 +1,12 @@
import pytest
boto = pytest.importorskip("boto")
import boto
import boto.iam
from boto.s3.connection import S3Connection
from boto.s3.key import Key
from ConfigParser import DuplicateSectionError
import vcr
import boto # NOQA
import boto.iam # NOQA
from boto.s3.connection import S3Connection # NOQA
from boto.s3.key import Key # NOQA
from ConfigParser import DuplicateSectionError # NOQA
import vcr # NOQA
def test_boto_stubs(tmpdir):

View File

@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
'''Test requests' interaction with vcr'''
import pytest
import vcr
from assertions import assert_cassette_empty, assert_is_json
@@ -95,6 +94,21 @@ def test_post(tmpdir, scheme):
assert req1 == req2
def test_post_chunked_binary(tmpdir, scheme):
'''Ensure that we can send chunked binary without breaking while trying to concatenate bytes with str.'''
data1 = iter([b'data', b'to', b'send'])
data2 = iter([b'data', b'to', b'send'])
url = scheme + '://httpbin.org/post'
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))):
req1 = requests.post(url, data1).content
print(req1)
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))):
req2 = requests.post(url, data2).content
assert req1 == req2
def test_redirects(tmpdir, scheme):
'''Ensure that we can handle redirects'''
url = scheme + '://httpbin.org/redirect-to?url=bytes/1024'

View File

@@ -3,7 +3,7 @@ from six.moves import xmlrpc_client
requests = pytest.importorskip("requests")
import vcr
import vcr # NOQA
try:
import httplib

View File

@@ -233,7 +233,8 @@ def test_cassette_use_called_without_path_uses_function_to_generate_path():
def test_path_transformer_with_function_path():
path_transformer = lambda path: os.path.join('a', path)
def path_transformer(path):
return os.path.join('a', path)
@Cassette.use(inject=True, path_transformer=path_transformer)
def function_name(cassette):

View File

@@ -191,7 +191,8 @@ class VCRConnection(object):
body of the request. So if that happens, let's just append the data
onto the most recent request in the cassette.
'''
self._vcr_request.body = (self._vcr_request.body or '') + data
self._vcr_request.body = self._vcr_request.body + data \
if self._vcr_request.body else data
def close(self):
# Note: the real connection will only close if it's open, so