mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
@@ -19,7 +19,8 @@ env:
|
|||||||
- TOX_SUFFIX="urllib317"
|
- TOX_SUFFIX="urllib317"
|
||||||
- TOX_SUFFIX="urllib319"
|
- TOX_SUFFIX="urllib319"
|
||||||
- TOX_SUFFIX="urllib3110"
|
- TOX_SUFFIX="urllib3110"
|
||||||
- TOX_SUFFIX="tornado"
|
- TOX_SUFFIX="tornado3"
|
||||||
|
- TOX_SUFFIX="tornado4"
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- env: TOX_SUFFIX="boto"
|
- env: TOX_SUFFIX="boto"
|
||||||
|
|||||||
@@ -9,9 +9,13 @@ from vcr.errors import CannotOverwriteExistingCassetteException
|
|||||||
|
|
||||||
from assertions import assert_cassette_empty, assert_is_json
|
from assertions import assert_cassette_empty, assert_is_json
|
||||||
|
|
||||||
|
tornado = pytest.importorskip("tornado")
|
||||||
http = pytest.importorskip("tornado.httpclient")
|
http = pytest.importorskip("tornado.httpclient")
|
||||||
|
|
||||||
|
# whether the current version of Tornado supports the raise_error argument for
|
||||||
|
# fetch().
|
||||||
|
supports_raise_error = tornado.version_info >= (4,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=['simple', 'curl', 'default'])
|
@pytest.fixture(params=['simple', 'curl', 'default'])
|
||||||
def get_client(request):
|
def get_client(request):
|
||||||
@@ -26,10 +30,13 @@ def get_client(request):
|
|||||||
|
|
||||||
|
|
||||||
def get(client, url, **kwargs):
|
def get(client, url, **kwargs):
|
||||||
raise_error = kwargs.pop('raise_error', True)
|
fetch_kwargs = {}
|
||||||
|
if supports_raise_error:
|
||||||
|
fetch_kwargs['raise_error'] = kwargs.pop('raise_error', True)
|
||||||
|
|
||||||
return client.fetch(
|
return client.fetch(
|
||||||
http.HTTPRequest(url, method='GET', **kwargs),
|
http.HTTPRequest(url, method='GET', **kwargs),
|
||||||
raise_error=raise_error,
|
**fetch_kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -122,22 +129,26 @@ def test_auth_failed(get_client, tmpdir, scheme):
|
|||||||
with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
|
||||||
# Ensure that this is empty to begin with
|
# Ensure that this is empty to begin with
|
||||||
assert_cassette_empty(cass)
|
assert_cassette_empty(cass)
|
||||||
one = yield get(
|
with pytest.raises(http.HTTPError) as exc_info:
|
||||||
get_client(),
|
yield get(
|
||||||
url,
|
get_client(),
|
||||||
auth_username=auth[0],
|
url,
|
||||||
auth_password=auth[1],
|
auth_username=auth[0],
|
||||||
raise_error=False
|
auth_password=auth[1],
|
||||||
)
|
)
|
||||||
|
one = exc_info.value.response
|
||||||
|
assert exc_info.value.code == 401
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
|
||||||
two = yield get(
|
with pytest.raises(http.HTTPError) as exc_info:
|
||||||
get_client(),
|
two = yield get(
|
||||||
url,
|
get_client(),
|
||||||
auth_username=auth[0],
|
url,
|
||||||
auth_password=auth[1],
|
auth_username=auth[0],
|
||||||
raise_error=False
|
auth_password=auth[1],
|
||||||
)
|
)
|
||||||
|
two = exc_info.value.response
|
||||||
|
assert exc_info.value.code == 401
|
||||||
assert one.body == two.body
|
assert one.body == two.body
|
||||||
assert one.code == two.code == 401
|
assert one.code == two.code == 401
|
||||||
assert 1 == cass.play_count
|
assert 1 == cass.play_count
|
||||||
@@ -197,12 +208,19 @@ def test_gzip(get_client, tmpdir, scheme):
|
|||||||
'''
|
'''
|
||||||
url = scheme + '://httpbin.org/gzip'
|
url = scheme + '://httpbin.org/gzip'
|
||||||
|
|
||||||
|
# use_gzip was renamed to decompress_response in 4.0
|
||||||
|
kwargs = {}
|
||||||
|
if tornado.version_info < (4,):
|
||||||
|
kwargs['use_gzip'] = True
|
||||||
|
else:
|
||||||
|
kwargs['decompress_response'] = True
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))):
|
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))):
|
||||||
response = yield get(get_client(), url, decompress_response=True)
|
response = yield get(get_client(), url, **kwargs)
|
||||||
assert_is_json(response.body)
|
assert_is_json(response.body)
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))) as cass:
|
||||||
response = yield get(get_client(), url, decompress_response=True)
|
response = yield get(get_client(), url, **kwargs)
|
||||||
assert_is_json(response.body)
|
assert_is_json(response.body)
|
||||||
assert 1 == cass.play_count
|
assert 1 == cass.play_count
|
||||||
|
|
||||||
@@ -238,6 +256,10 @@ def test_unsupported_features_raises_in_future(get_client, tmpdir):
|
|||||||
assert "not yet supported by VCR" in str(excinfo)
|
assert "not yet supported by VCR" in str(excinfo)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
not supports_raise_error,
|
||||||
|
reason='raise_error unavailable in tornado <= 3',
|
||||||
|
)
|
||||||
@pytest.mark.gen_test
|
@pytest.mark.gen_test
|
||||||
def test_unsupported_features_raise_error_disabled(get_client, tmpdir):
|
def test_unsupported_features_raise_error_disabled(get_client, tmpdir):
|
||||||
'''Ensure that the exception for an AsyncHTTPClient feature not being
|
'''Ensure that the exception for an AsyncHTTPClient feature not being
|
||||||
@@ -272,6 +294,10 @@ def test_cannot_overwrite_cassette_raises_in_future(get_client, tmpdir):
|
|||||||
yield future
|
yield future
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
not supports_raise_error,
|
||||||
|
reason='raise_error unavailable in tornado <= 3',
|
||||||
|
)
|
||||||
@pytest.mark.gen_test
|
@pytest.mark.gen_test
|
||||||
def test_cannot_overwrite_cassette_raise_error_disabled(get_client, tmpdir):
|
def test_cannot_overwrite_cassette_raise_error_disabled(get_client, tmpdir):
|
||||||
'''Ensure that CannotOverwriteExistingCassetteException is not raised if
|
'''Ensure that CannotOverwriteExistingCassetteException is not raised if
|
||||||
|
|||||||
11
tox.ini
11
tox.ini
@@ -1,5 +1,5 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = {py26,py27,py33,py34,pypy}-{flakes,requests27,requests26,requests25,requests24,requests23,requests22,requests1,httplib2,urllib317,urllib319,urllib3110,tornado,boto}
|
envlist = {py26,py27,py33,py34,pypy}-{flakes,requests27,requests26,requests25,requests24,requests23,requests22,requests1,httplib2,urllib317,urllib319,urllib3110,tornado3,tornado4,boto}
|
||||||
|
|
||||||
[testenv:flakes]
|
[testenv:flakes]
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
@@ -28,9 +28,12 @@ deps =
|
|||||||
urllib317: urllib3==1.7.1
|
urllib317: urllib3==1.7.1
|
||||||
urllib319: urllib3==1.9.1
|
urllib319: urllib3==1.9.1
|
||||||
urllib3110: urllib3==1.10.2
|
urllib3110: urllib3==1.10.2
|
||||||
{py26,py27,py33,py34,pypy}-tornado: tornado
|
{py26,py27,py33,py34,pypy}-tornado3: tornado>=3,<4
|
||||||
{py26,py27,py33,py34,pypy}-tornado: pytest-tornado
|
{py26,py27,py33,py34,pypy}-tornado4: tornado>=4,<5
|
||||||
{py26,py27,py33,py34}-tornado: pycurl
|
{py26,py27,py33,py34,pypy}-tornado3: pytest-tornado
|
||||||
|
{py26,py27,py33,py34,pypy}-tornado4: pytest-tornado
|
||||||
|
{py26,py27,py33,py34}-tornado3: pycurl
|
||||||
|
{py26,py27,py33,py34}-tornado4: pycurl
|
||||||
boto: boto
|
boto: boto
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def vcr_fetch_impl(cassette, real_fetch_impl):
|
|||||||
# yet supported.
|
# yet supported.
|
||||||
|
|
||||||
unsupported_call = (
|
unsupported_call = (
|
||||||
request.body_producer is not None or
|
getattr(request, 'body_producer', None) is not None or
|
||||||
request.header_callback is not None or
|
request.header_callback is not None or
|
||||||
request.streaming_callback is not None
|
request.streaming_callback is not None
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user