1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

Fix urllib redirect tests

This commit is contained in:
Jair Henrique
2021-11-02 16:15:04 -03:00
parent 3c7b791783
commit cd72278062
2 changed files with 10 additions and 7 deletions

View File

@@ -56,12 +56,13 @@ def test_response_headers(httpbin_both, tmpdir):
assert sorted(open1) == sorted(open2)
def test_effective_url(httpbin_both, tmpdir):
def test_effective_url(tmpdir):
"""Ensure that the effective_url is captured"""
url = httpbin_both.url + "/redirect-to?url=/html"
url = "http://mockbin.org/redirect/301"
with vcr.use_cassette(str(tmpdir.join("headers.yaml"))):
effective_url = urlopen_with_cafile(url).geturl()
assert effective_url == httpbin_both.url + "/html"
assert effective_url == "http://mockbin.org/redirect/301/0"
with vcr.use_cassette(str(tmpdir.join("headers.yaml"))):
assert effective_url == urlopen_with_cafile(url).geturl()

View File

@@ -94,9 +94,10 @@ def test_post(tmpdir, httpbin_both, verify_pool_mgr):
assert req1 == req2
def test_redirects(tmpdir, httpbin_both, verify_pool_mgr):
def test_redirects(tmpdir, verify_pool_mgr):
"""Ensure that we can handle redirects"""
url = httpbin_both.url + "/redirect-to?url=bytes/1024"
url = "http://mockbin.org/redirect/301"
with vcr.use_cassette(str(tmpdir.join("verify_pool_mgr.yaml"))):
content = verify_pool_mgr.request("GET", url).data
@@ -104,6 +105,7 @@ def test_redirects(tmpdir, httpbin_both, verify_pool_mgr):
assert content == verify_pool_mgr.request("GET", url).data
# Ensure that we've now cached *two* responses. One for the redirect
# and one for the final fetch
assert len(cass) == 2
assert cass.play_count == 2