From cd722780620dfcd6d3cec813ff45c30ce7892342 Mon Sep 17 00:00:00 2001 From: Jair Henrique Date: Tue, 2 Nov 2021 16:15:04 -0300 Subject: [PATCH] Fix urllib redirect tests --- tests/integration/test_urllib2.py | 7 ++++--- tests/integration/test_urllib3.py | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/integration/test_urllib2.py b/tests/integration/test_urllib2.py index 2582e0c..dd74bd5 100644 --- a/tests/integration/test_urllib2.py +++ b/tests/integration/test_urllib2.py @@ -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() diff --git a/tests/integration/test_urllib3.py b/tests/integration/test_urllib3.py index 110c05a..01de5a8 100644 --- a/tests/integration/test_urllib3.py +++ b/tests/integration/test_urllib3.py @@ -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,8 +105,9 @@ 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 + + assert len(cass) == 2 + assert cass.play_count == 2 def test_cross_scheme(tmpdir, httpbin, httpbin_secure, verify_pool_mgr):