]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Set request_time on Tornadoo HTTPResponses
authorAbhinav Gupta <abg@uber.com>
Tue, 18 Aug 2015 22:51:46 +0000 (15:51 -0700)
committerAbhinav Gupta <abg@uber.com>
Tue, 18 Aug 2015 22:53:35 +0000 (15:53 -0700)
tests/integration/test_tornado.py
vcr/stubs/tornado_stubs.py

index fade78f1d03847a275d5faac6a3f3f9093c242c0..b7d3c4edb0c76ca37f0835b00b801a95e2dfdade 100644 (file)
@@ -337,3 +337,19 @@ def test_existing_instances_get_patched(get_client, tmpdir):
     with vcr.use_cassette(str(tmpdir.join('data.yaml'))) as cass:
         yield get(client, 'http://httpbin.org/get')
         assert cass.play_count == 1
+
+
+@pytest.mark.gen_test
+def test_request_time_is_set(get_client, tmpdir):
+    '''Ensures that the request_time on HTTPResponses is set.'''
+
+    with vcr.use_cassette(str(tmpdir.join('data.yaml'))):
+        client = get_client()
+        response = yield get(client, 'http://httpbin.org/get')
+        assert response.request_time is not None
+
+    with vcr.use_cassette(str(tmpdir.join('data.yaml'))) as cass:
+        client = get_client()
+        response = yield get(client, 'http://httpbin.org/get')
+        assert response.request_time is not None
+        assert cass.play_count == 1
index 3b771d612bfff05362e2c3cd097e6f783a7665b6..5a4ce587c0ccdfe4ec9acb7304b79e25aea2de17 100644 (file)
@@ -36,6 +36,7 @@ def vcr_fetch_impl(cassette, real_fetch_impl):
                     "that is not yet supported by VCR.py. Please make the "
                     "request outside a VCR.py context." % repr(request)
                 ),
+                request_time=self.io_loop.time() - request.start_time,
             )
             return callback(response)
 
@@ -63,6 +64,7 @@ def vcr_fetch_impl(cassette, real_fetch_impl):
                 headers=headers,
                 buffer=BytesIO(vcr_response['body']['string']),
                 effective_url=vcr_response.get('url'),
+                request_time=self.io_loop.time() - request.start_time,
             )
             return callback(response)
         else:
@@ -78,6 +80,7 @@ def vcr_fetch_impl(cassette, real_fetch_impl):
                         "your current record mode (%r)."
                         % (vcr_request, cassette._path, cassette.record_mode)
                     ),
+                    request_time=self.io_loop.time() - request.start_time,
                 )
                 return callback(response)