from assertions import assert_cassette_empty, assert_is_json
-
+tornado = pytest.importorskip("tornado")
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'])
def get_client(request):
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(
http.HTTPRequest(url, method='GET', **kwargs),
- raise_error=raise_error,
+ **fetch_kwargs
)
with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
# Ensure that this is empty to begin with
assert_cassette_empty(cass)
- one = yield get(
- get_client(),
- url,
- auth_username=auth[0],
- auth_password=auth[1],
- raise_error=False
- )
+ with pytest.raises(http.HTTPError) as exc_info:
+ yield get(
+ get_client(),
+ url,
+ auth_username=auth[0],
+ 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:
- two = yield get(
- get_client(),
- url,
- auth_username=auth[0],
- auth_password=auth[1],
- raise_error=False
- )
+ with pytest.raises(http.HTTPError) as exc_info:
+ two = yield get(
+ get_client(),
+ url,
+ auth_username=auth[0],
+ auth_password=auth[1],
+ )
+ two = exc_info.value.response
+ assert exc_info.value.code == 401
assert one.body == two.body
assert one.code == two.code == 401
assert 1 == cass.play_count
'''
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'))):
- response = yield get(get_client(), url, decompress_response=True)
+ response = yield get(get_client(), url, **kwargs)
assert_is_json(response.body)
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 1 == cass.play_count
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
def test_unsupported_features_raise_error_disabled(get_client, tmpdir):
'''Ensure that the exception for an AsyncHTTPClient feature not being
yield future
+@pytest.mark.skipif(
+ not supports_raise_error,
+ reason='raise_error unavailable in tornado <= 3',
+)
@pytest.mark.gen_test
def test_cannot_overwrite_cassette_raise_error_disabled(get_client, tmpdir):
'''Ensure that CannotOverwriteExistingCassetteException is not raised if
[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]
skipsdist = True
urllib317: urllib3==1.7.1
urllib319: urllib3==1.9.1
urllib3110: urllib3==1.10.2
- {py26,py27,py33,py34,pypy}-tornado: tornado
- {py26,py27,py33,py34,pypy}-tornado: pytest-tornado
- {py26,py27,py33,py34}-tornado: pycurl
+ {py26,py27,py33,py34,pypy}-tornado3: tornado>=3,<4
+ {py26,py27,py33,py34,pypy}-tornado4: tornado>=4,<5
+ {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
[flake8]