From 7cc513e1d2e28975f6a464fc65e5ce2a86a48703 Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Tue, 19 Jan 2016 14:19:03 +0100 Subject: [PATCH 1/3] Avoid concatenating bytes with strings --- vcr/stubs/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index b372658..a703ff4 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -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 From 7fdfce65ee044c58df5cf4cce8d2c7f81d055915 Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Wed, 20 Jan 2016 12:17:28 +0100 Subject: [PATCH 2/3] Add test to make sure we can post chunked binary data --- tests/integration/test_requests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/integration/test_requests.py b/tests/integration/test_requests.py index 58ce543..cc8360a 100644 --- a/tests/integration/test_requests.py +++ b/tests/integration/test_requests.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- '''Test requests' interaction with vcr''' +from io import BytesIO import pytest import vcr @@ -95,6 +96,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 string.''' + 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' From 632af2e41a4b833d38e1ba84bb7aead35a123d7a Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Wed, 20 Jan 2016 12:28:46 +0100 Subject: [PATCH 3/3] Fix/ignore some flake errors --- tests/integration/test_boto.py | 12 ++++++------ tests/integration/test_requests.py | 4 +--- tests/integration/test_wild.py | 2 +- tests/unit/test_cassettes.py | 3 ++- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/integration/test_boto.py b/tests/integration/test_boto.py index 84132d7..6a396cc 100644 --- a/tests/integration/test_boto.py +++ b/tests/integration/test_boto.py @@ -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): diff --git a/tests/integration/test_requests.py b/tests/integration/test_requests.py index cc8360a..117e92e 100644 --- a/tests/integration/test_requests.py +++ b/tests/integration/test_requests.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- '''Test requests' interaction with vcr''' -from io import BytesIO - import pytest import vcr from assertions import assert_cassette_empty, assert_is_json @@ -97,7 +95,7 @@ def test_post(tmpdir, scheme): def test_post_chunked_binary(tmpdir, scheme): - '''Ensure that we can send chunked binary without breaking while trying to concatenate bytes with string.''' + '''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' diff --git a/tests/integration/test_wild.py b/tests/integration/test_wild.py index 47edc08..e8feeb5 100644 --- a/tests/integration/test_wild.py +++ b/tests/integration/test_wild.py @@ -3,7 +3,7 @@ from six.moves import xmlrpc_client requests = pytest.importorskip("requests") -import vcr +import vcr # NOQA try: import httplib diff --git a/tests/unit/test_cassettes.py b/tests/unit/test_cassettes.py index fc7fac0..ef9e808 100644 --- a/tests/unit/test_cassettes.py +++ b/tests/unit/test_cassettes.py @@ -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):