1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

Do not redirect on 304 for aiohttp

This commit is contained in:
Jean-Sebastien Roy
2020-01-13 13:55:41 -05:00
parent accffa8ea2
commit 6e040030b8
2 changed files with 20 additions and 0 deletions

View File

@@ -273,6 +273,23 @@ def test_redirect(aiohttp_client, tmpdir):
assert cassette_response.request_info.real_url == response.request_info.real_url
def test_not_modified(aiohttp_client, tmpdir):
"""It doesn't try to redirect on 304"""
url = "https://httpbin.org/status/304"
with vcr.use_cassette(str(tmpdir.join("not_modified.yaml"))):
response, _ = get(url)
with vcr.use_cassette(str(tmpdir.join("not_modified.yaml"))) as cassette:
cassette_response, _ = get(url)
assert cassette_response.status == 304
assert response.status == 304
assert len(cassette_response.history) == len(response.history)
assert len(cassette) == 1
assert cassette.play_count == 1
def test_double_requests(tmpdir):
"""We should capture, record, and replay all requests and response chains,
even if there are duplicate ones.

View File

@@ -92,6 +92,9 @@ def play_responses(cassette, vcr_request):
# If we're following redirects, continue playing until we reach
# our final destination.
while 300 <= response.status <= 399:
if "location" not in response.headers:
break
next_url = URL(response.url).with_path(response.headers["location"])
# Make a stub VCR request that we can then use to look up the recorded