mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-10 09:35:34 +00:00
Merge pull request #186 from ByteInternet/capture-effective-url
Capture effective url in Tornado
This commit is contained in:
@@ -56,6 +56,17 @@ def test_response_headers(scheme, tmpdir):
|
|||||||
resp, _ = httplib2.Http().request(url)
|
resp, _ = httplib2.Http().request(url)
|
||||||
assert set(headers) == set(resp.items())
|
assert set(headers) == set(resp.items())
|
||||||
|
|
||||||
|
def test_effective_url(scheme, tmpdir):
|
||||||
|
'''Ensure that the effective_url is captured'''
|
||||||
|
url = scheme + '://httpbin.org/redirect-to?url=/html'
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
|
||||||
|
resp, _ = httplib2.Http().request(url)
|
||||||
|
effective_url = resp['content-location']
|
||||||
|
assert effective_url == scheme + '://httpbin.org/html'
|
||||||
|
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
|
||||||
|
resp, _ = httplib2.Http().request(url)
|
||||||
|
assert effective_url == resp['content-location']
|
||||||
|
|
||||||
def test_multiple_requests(scheme, tmpdir):
|
def test_multiple_requests(scheme, tmpdir):
|
||||||
'''Ensure that we can cache multiple requests'''
|
'''Ensure that we can cache multiple requests'''
|
||||||
|
|||||||
@@ -44,6 +44,15 @@ def test_body(tmpdir, scheme):
|
|||||||
with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
|
with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
|
||||||
assert content == requests.get(url).content
|
assert content == requests.get(url).content
|
||||||
|
|
||||||
|
def test_effective_url(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 = requests.get(url).url
|
||||||
|
assert effective_url == scheme + '://httpbin.org/html'
|
||||||
|
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('url.yaml'))):
|
||||||
|
assert effective_url == requests.get(url).url
|
||||||
|
|
||||||
def test_auth(tmpdir, scheme):
|
def test_auth(tmpdir, scheme):
|
||||||
'''Ensure that we can handle basic auth'''
|
'''Ensure that we can handle basic auth'''
|
||||||
|
|||||||
@@ -81,6 +81,17 @@ def test_body(get_client, tmpdir, scheme):
|
|||||||
assert content == (yield get(get_client(), url)).body
|
assert content == (yield get(get_client(), url)).body
|
||||||
assert 1 == cass.play_count
|
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
|
||||||
|
assert effective_url == scheme + '://httpbin.org/html'
|
||||||
|
|
||||||
|
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
|
@pytest.mark.gen_test
|
||||||
def test_auth(get_client, tmpdir, scheme):
|
def test_auth(get_client, tmpdir, scheme):
|
||||||
|
|||||||
@@ -49,6 +49,15 @@ def test_response_headers(scheme, tmpdir):
|
|||||||
open2 = urlopen(url).info().items()
|
open2 = urlopen(url).info().items()
|
||||||
assert sorted(open1) == sorted(open2)
|
assert sorted(open1) == sorted(open2)
|
||||||
|
|
||||||
|
def test_effective_url(scheme, tmpdir):
|
||||||
|
'''Ensure that the effective_url is captured'''
|
||||||
|
url = scheme + '://httpbin.org/redirect-to?url=/html'
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
|
||||||
|
effective_url = urlopen(url).geturl()
|
||||||
|
assert effective_url == scheme + '://httpbin.org/html'
|
||||||
|
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
|
||||||
|
assert effective_url == urlopen(url).geturl()
|
||||||
|
|
||||||
def test_multiple_requests(scheme, tmpdir):
|
def test_multiple_requests(scheme, tmpdir):
|
||||||
'''Ensure that we can cache multiple requests'''
|
'''Ensure that we can cache multiple requests'''
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ def vcr_fetch_impl(cassette, real_fetch_impl):
|
|||||||
reason=vcr_response['status']['message'],
|
reason=vcr_response['status']['message'],
|
||||||
headers=headers,
|
headers=headers,
|
||||||
buffer=BytesIO(vcr_response['body']['string']),
|
buffer=BytesIO(vcr_response['body']['string']),
|
||||||
|
effective_url=vcr_response.get('url'),
|
||||||
)
|
)
|
||||||
return callback(response)
|
return callback(response)
|
||||||
else:
|
else:
|
||||||
@@ -93,6 +94,7 @@ def vcr_fetch_impl(cassette, real_fetch_impl):
|
|||||||
},
|
},
|
||||||
'headers': headers,
|
'headers': headers,
|
||||||
'body': {'string': response.body},
|
'body': {'string': response.body},
|
||||||
|
'url': response.effective_url,
|
||||||
}
|
}
|
||||||
cassette.append(vcr_request, vcr_response)
|
cassette.append(vcr_request, vcr_response)
|
||||||
return callback(response)
|
return callback(response)
|
||||||
|
|||||||
Reference in New Issue
Block a user