]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
[Tornado] Fix unsupported features exception not being raised.
authorAbhinav Gupta <mail@abhinavg.net>
Fri, 3 Jul 2015 19:32:07 +0000 (12:32 -0700)
committerAbhinav Gupta <mail@abhinavg.net>
Fri, 3 Jul 2015 19:34:57 +0000 (12:34 -0700)
Add tests for that exception being raisd correctly and for
CannotOverwriteCassetteException.

tests/integration/test_tornado.py
vcr/stubs/tornado_stubs.py

index 68659245cc0b99eaa50c1ae55f34f692534eb74a..123007704a495db84605a0d07f8ed426938b7ea5 100644 (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)
index c6f1befe29f2a76c30e673e794247513cbcbf119..7a16cd88c958371840d141ae54cdb5b2a605e491 100644 (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():