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

fix tests

This commit is contained in:
Parker Hancock
2023-12-08 10:49:29 -06:00
committed by Jair Henrique
parent e8e9a4af9f
commit f5fc7aac22
14 changed files with 101 additions and 112 deletions

View File

@@ -36,8 +36,8 @@ def post(url, output="text", **kwargs):
@pytest.mark.online
def test_status(tmpdir, mockbin_request_url):
url = mockbin_request_url
def test_status(tmpdir, httpbin):
url = httpbin.url
with vcr.use_cassette(str(tmpdir.join("status.yaml"))):
response, _ = get(url)
@@ -50,8 +50,8 @@ def test_status(tmpdir, mockbin_request_url):
@pytest.mark.online
@pytest.mark.parametrize("auth", [None, aiohttp.BasicAuth("vcrpy", "test")])
def test_headers(tmpdir, auth, mockbin_request_url):
url = mockbin_request_url
def test_headers(tmpdir, auth, httpbin):
url = httpbin.url
with vcr.use_cassette(str(tmpdir.join("headers.yaml"))):
response, _ = get(url, auth=auth)
@@ -67,8 +67,8 @@ def test_headers(tmpdir, auth, mockbin_request_url):
@pytest.mark.online
def test_case_insensitive_headers(tmpdir, mockbin_request_url):
url = mockbin_request_url
def test_case_insensitive_headers(tmpdir, httpbin):
url = httpbin.url
with vcr.use_cassette(str(tmpdir.join("whatever.yaml"))):
_, _ = get(url)
@@ -81,8 +81,8 @@ def test_case_insensitive_headers(tmpdir, mockbin_request_url):
@pytest.mark.online
def test_text(tmpdir, mockbin_request_url):
url = mockbin_request_url
def test_text(tmpdir, httpbin):
url = httpbin.url
with vcr.use_cassette(str(tmpdir.join("text.yaml"))):
_, response_text = get(url)
@@ -94,8 +94,8 @@ def test_text(tmpdir, mockbin_request_url):
@pytest.mark.online
def test_json(tmpdir, mockbin_request_url):
url = mockbin_request_url
def test_json(tmpdir, httpbin):
url = httpbin.url + "/json"
headers = {"Content-Type": "application/json"}
with vcr.use_cassette(str(tmpdir.join("json.yaml"))):
@@ -108,8 +108,8 @@ def test_json(tmpdir, mockbin_request_url):
@pytest.mark.online
def test_binary(tmpdir, mockbin_request_url):
url = mockbin_request_url + "/image/png"
def test_binary(tmpdir, httpbin):
url = httpbin.url + "/image/png"
with vcr.use_cassette(str(tmpdir.join("binary.yaml"))):
_, response_binary = get(url, output="raw")
@@ -120,8 +120,8 @@ def test_binary(tmpdir, mockbin_request_url):
@pytest.mark.online
def test_stream(tmpdir, mockbin_request_url):
url = mockbin_request_url
def test_stream(tmpdir, httpbin):
url = httpbin.url
with vcr.use_cassette(str(tmpdir.join("stream.yaml"))):
_, body = get(url, output="raw") # Do not use stream here, as the stream is exhausted by vcr
@@ -134,10 +134,10 @@ def test_stream(tmpdir, mockbin_request_url):
@pytest.mark.online
@pytest.mark.parametrize("body", ["data", "json"])
def test_post(tmpdir, body, caplog, mockbin_request_url):
def test_post(tmpdir, body, caplog, httpbin):
caplog.set_level(logging.INFO)
data = {"key1": "value1", "key2": "value2"}
url = mockbin_request_url
url = httpbin.url
with vcr.use_cassette(str(tmpdir.join("post.yaml"))):
_, response_json = post(url, **{body: data})
@@ -159,14 +159,14 @@ def test_post(tmpdir, body, caplog, mockbin_request_url):
@pytest.mark.online
def test_params(tmpdir, mockbin_request_url):
url = mockbin_request_url + "?d=d"
def test_params(tmpdir, httpbin):
url = httpbin.url + "/get?d=d"
headers = {"Content-Type": "application/json"}
params = {"a": 1, "b": 2, "c": "c"}
with vcr.use_cassette(str(tmpdir.join("get.yaml"))) as cassette:
_, response_json = get(url, output="json", params=params, headers=headers)
assert response_json["queryString"] == {"a": "1", "b": "2", "c": "c", "d": "d"}
assert response_json["args"] == {"a": "1", "b": "2", "c": "c", "d": "d"}
with vcr.use_cassette(str(tmpdir.join("get.yaml"))) as cassette:
_, cassette_response_json = get(url, output="json", params=params, headers=headers)
@@ -175,8 +175,8 @@ def test_params(tmpdir, mockbin_request_url):
@pytest.mark.online
def test_params_same_url_distinct_params(tmpdir, mockbin_request_url):
url = mockbin_request_url
def test_params_same_url_distinct_params(tmpdir, httpbin):
url = httpbin.url + "/json"
headers = {"Content-Type": "application/json"}
params = {"a": 1, "b": 2, "c": "c"}
@@ -195,8 +195,8 @@ def test_params_same_url_distinct_params(tmpdir, mockbin_request_url):
@pytest.mark.online
def test_params_on_url(tmpdir, mockbin_request_url):
url = mockbin_request_url + "?a=1&b=foo"
def test_params_on_url(tmpdir, httpbin):
url = httpbin.url + "/get?a=1&b=foo"
headers = {"Content-Type": "application/json"}
with vcr.use_cassette(str(tmpdir.join("get.yaml"))) as cassette:
@@ -261,8 +261,8 @@ def test_aiohttp_test_client_json(aiohttp_client, tmpdir):
@pytest.mark.online
def test_redirect(tmpdir, mockbin):
url = mockbin + "/redirect/302/2"
def test_redirect(tmpdir, httpbin):
url = httpbin.url + "/redirect/2"
with vcr.use_cassette(str(tmpdir.join("redirect.yaml"))):
response, _ = get(url)
@@ -284,9 +284,9 @@ def test_redirect(tmpdir, mockbin):
@pytest.mark.online
def test_not_modified(tmpdir, mockbin):
def test_not_modified(tmpdir, httpbin):
"""It doesn't try to redirect on 304"""
url = mockbin + "/status/304"
url = httpbin.url + "/status/304"
with vcr.use_cassette(str(tmpdir.join("not_modified.yaml"))):
response, _ = get(url)
@@ -302,13 +302,13 @@ def test_not_modified(tmpdir, mockbin):
@pytest.mark.online
def test_double_requests(tmpdir, mockbin_request_url):
def test_double_requests(tmpdir, httpbin):
"""We should capture, record, and replay all requests and response chains,
even if there are duplicate ones.
We should replay in the order we saw them.
"""
url = mockbin_request_url
url = httpbin.url
with vcr.use_cassette(str(tmpdir.join("text.yaml"))):
_, response_text1 = get(url, output="text")
@@ -426,18 +426,18 @@ def test_cookies_redirect(httpbin_both, httpbin_ssl_context, tmpdir):
@pytest.mark.online
def test_not_allow_redirects(tmpdir, mockbin):
url = mockbin + "/redirect/308/5"
def test_not_allow_redirects(tmpdir, httpbin):
url = httpbin + "/redirect-to?url=.%2F&status_code=308"
path = str(tmpdir.join("redirects.yaml"))
with vcr.use_cassette(path):
response, _ = get(url, allow_redirects=False)
assert response.url.path == "/redirect/308/5"
assert response.url.path == "/redirect-to"
assert response.status == 308
with vcr.use_cassette(path) as cassette:
response, _ = get(url, allow_redirects=False)
assert response.url.path == "/redirect/308/5"
assert response.url.path == "/redirect-to"
assert response.status == 308
assert cassette.play_count == 1