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

Merge pull request #165 from abhinav/master

[Tornado] Fix unsupported features exception not being raised.
This commit is contained in:
Ivan 'Goat' Malison
2015-07-03 16:04:49 -07:00
2 changed files with 76 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import json
import pytest
import vcr
from vcr.errors import CannotOverwriteExistingCassetteException
from assertions import assert_cassette_empty, assert_is_json
@@ -203,3 +204,74 @@ def test_https_with_cert_validation_disabled(get_client, tmpdir):
with vcr.use_cassette(cass_path) as cass:
yield get(get_client(), 'https://httpbin.org', validate_cert=False)
assert 1 == cass.play_count
@pytest.mark.gen_test
def test_unsupported_features_raises_in_future(get_client, tmpdir):
'''Ensure that the exception for an AsyncHTTPClient feature not being
supported is raised inside the future.'''
def callback(chunk):
assert False, "Did not expect to be called."
with vcr.use_cassette(str(tmpdir.join('invalid.yaml'))):
future = get(
get_client(), 'http://httpbin.org', streaming_callback=callback
)
with pytest.raises(Exception) as excinfo:
yield future
assert "not yet supported by VCR" in str(excinfo)
@pytest.mark.gen_test
def test_unsupported_features_raise_error_disabled(get_client, tmpdir):
'''Ensure that the exception for an AsyncHTTPClient feature not being
supported is not raised if raise_error=False.'''
def callback(chunk):
assert False, "Did not expect to be called."
with vcr.use_cassette(str(tmpdir.join('invalid.yaml'))):
response = yield get(
get_client(),
'http://httpbin.org',
streaming_callback=callback,
raise_error=False,
)
assert "not yet supported by VCR" in str(response.error)
@pytest.mark.gen_test
def test_cannot_overwrite_cassette_raises_in_future(get_client, tmpdir):
'''Ensure that CannotOverwriteExistingCassetteException is raised inside
the future.'''
with vcr.use_cassette(str(tmpdir.join('overwrite.yaml'))):
yield get(get_client(), 'http://httpbin.org/get')
with vcr.use_cassette(str(tmpdir.join('overwrite.yaml'))):
future = get(get_client(), 'http://httpbin.org/headers')
with pytest.raises(CannotOverwriteExistingCassetteException):
yield future
@pytest.mark.gen_test
def test_cannot_overwrite_cassette_raise_error_disabled(get_client, tmpdir):
'''Ensure that CannotOverwriteExistingCassetteException is not raised if
raise_error=False in the fetch() call.'''
with vcr.use_cassette(str(tmpdir.join('overwrite.yaml'))):
yield get(
get_client(), 'http://httpbin.org/get', raise_error=False
)
with vcr.use_cassette(str(tmpdir.join('overwrite.yaml'))):
response = yield get(
get_client(), 'http://httpbin.org/headers', raise_error=False
)
assert isinstance(response.error, CannotOverwriteExistingCassetteException)

View File

@@ -65,6 +65,7 @@ class _VCRAsyncClient(object):
"request outside a VCR.py context." % repr(request)
),
)
return callback(response)
vcr_request = Request(
request.method,
@@ -90,7 +91,7 @@ class _VCRAsyncClient(object):
headers=headers,
buffer=BytesIO(vcr_response['body']['string']),
)
callback(response)
return callback(response)
else:
if self.cassette.write_protected and self.cassette.filter_request(
vcr_request
@@ -106,7 +107,7 @@ class _VCRAsyncClient(object):
self.cassette.record_mode)
),
)
callback(response)
return callback(response)
def new_callback(response):
headers = [
@@ -123,7 +124,7 @@ class _VCRAsyncClient(object):
'body': {'string': response.body},
}
self.cassette.append(vcr_request, vcr_response)
callback(response)
return callback(response)
from vcr.patch import force_reset
with force_reset():