From 7d68f0577a54b44ecc642e88983b4801e0bdac90 Mon Sep 17 00:00:00 2001 From: Maarten van Schaik Date: Fri, 14 Aug 2015 12:08:57 +0200 Subject: [PATCH] Capture effective URL in tornado --- tests/integration/test_tornado.py | 10 ++++++++++ vcr/stubs/tornado_stubs.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/tests/integration/test_tornado.py b/tests/integration/test_tornado.py index 6f88d67..57ada3f 100644 --- a/tests/integration/test_tornado.py +++ b/tests/integration/test_tornado.py @@ -81,6 +81,16 @@ def test_body(get_client, tmpdir, scheme): assert content == (yield get(get_client(), url)).body assert 1 == cass.play_count +@pytest.mark.gen_test +def test_effective_url(get_client, scheme, tmpdir): + '''Ensure that the effective_url is captured''' + url = scheme + '://httpbin.org/redirect-to?url=/html' + with vcr.use_cassette(str(tmpdir.join('url.yaml'))): + effective_url = (yield get(get_client(), url)).effective_url + + with vcr.use_cassette(str(tmpdir.join('url.yaml'))) as cass: + assert effective_url == (yield get(get_client(), url)).effective_url + assert 1 == cass.play_count @pytest.mark.gen_test def test_auth(get_client, tmpdir, scheme): diff --git a/vcr/stubs/tornado_stubs.py b/vcr/stubs/tornado_stubs.py index e5d93c5..3b771d6 100644 --- a/vcr/stubs/tornado_stubs.py +++ b/vcr/stubs/tornado_stubs.py @@ -62,6 +62,7 @@ def vcr_fetch_impl(cassette, real_fetch_impl): reason=vcr_response['status']['message'], headers=headers, buffer=BytesIO(vcr_response['body']['string']), + effective_url=vcr_response.get('url'), ) return callback(response) else: @@ -93,6 +94,7 @@ def vcr_fetch_impl(cassette, real_fetch_impl): }, 'headers': headers, 'body': {'string': response.body}, + 'url': response.effective_url, } cassette.append(vcr_request, vcr_response) return callback(response)