mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
update tests
- Use mockbin for redirections. - Mock synchronous requests too.
This commit is contained in:
committed by
Kevin McCarthy
parent
5afa8f703a
commit
8529c46f00
@@ -1,43 +0,0 @@
|
||||
interactions:
|
||||
- request:
|
||||
body: null
|
||||
headers:
|
||||
accept:
|
||||
- '*/*'
|
||||
accept-encoding:
|
||||
- gzip, deflate, br
|
||||
connection:
|
||||
- keep-alive
|
||||
host:
|
||||
- httpbin.org
|
||||
user-agent:
|
||||
- python-httpx/0.12.1
|
||||
method: GET
|
||||
uri: https://localhost:8080/headers
|
||||
response:
|
||||
body:
|
||||
string: "{\n \"headers\": {\n \"Accept\": \"*/*\", \n \"Accept-Encoding\"\
|
||||
: \"gzip, deflate, br\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\"\
|
||||
: \"python-httpx/0.12.1\", \n \"X-Amzn-Trace-Id\": \"Root=1-5ea778ca-c402f3ae901e78b3435b0a0c\"\
|
||||
\n }\n}\n"
|
||||
headers:
|
||||
Access-Control-Allow-Credentials:
|
||||
- 'true'
|
||||
Access-Control-Allow-Origin:
|
||||
- '*'
|
||||
Connection:
|
||||
- keep-alive
|
||||
Content-Length:
|
||||
- '226'
|
||||
Content-Type:
|
||||
- application/json
|
||||
Date:
|
||||
- Tue, 28 Apr 2020 00:28:58 GMT
|
||||
Server:
|
||||
- gunicorn/19.9.0
|
||||
Via:
|
||||
- my_own_proxy
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
version: 1
|
||||
@@ -53,7 +53,7 @@ def yml(tmpdir, request):
|
||||
|
||||
|
||||
def test_status(tmpdir, scheme, do_request):
|
||||
url = scheme + "://httpbin.org"
|
||||
url = scheme + "://mockbin.org/request"
|
||||
with vcr.use_cassette(str(tmpdir.join("status.yaml"))):
|
||||
response = do_request()("GET", url)
|
||||
|
||||
@@ -64,7 +64,7 @@ def test_status(tmpdir, scheme, do_request):
|
||||
|
||||
|
||||
def test_case_insensitive_headers(tmpdir, scheme, do_request):
|
||||
url = scheme + "://httpbin.org"
|
||||
url = scheme + "://mockbin.org/request"
|
||||
with vcr.use_cassette(str(tmpdir.join("whatever.yaml"))):
|
||||
do_request()("GET", url)
|
||||
|
||||
@@ -120,7 +120,7 @@ def test_params_same_url_distinct_params(tmpdir, scheme, do_request):
|
||||
|
||||
|
||||
def test_redirect(tmpdir, do_request, yml):
|
||||
url = "https://httpbin.org/redirect/2"
|
||||
url = "https://mockbin.org/redirect/303/2"
|
||||
|
||||
response = do_request()("GET", url)
|
||||
with vcr.use_cassette(yml):
|
||||
@@ -169,10 +169,7 @@ def test_simple_fetching(tmpdir, do_request, yml, url):
|
||||
def test_behind_proxy(do_request):
|
||||
# This is recorded because otherwise we should have a live proxy somewhere.
|
||||
yml = (
|
||||
os.path.dirname(os.path.realpath(__file__))
|
||||
+ "/cassettes/"
|
||||
+ do_request.__name__
|
||||
+ "test_httpx_test_test_behind_proxy.yml"
|
||||
os.path.dirname(os.path.realpath(__file__)) + "/cassettes/" + "test_httpx_test_test_behind_proxy.yml"
|
||||
)
|
||||
url = "https://httpbin.org/headers"
|
||||
proxy = "http://localhost:8080"
|
||||
@@ -225,16 +222,16 @@ def test_cookies(tmpdir, scheme, do_request):
|
||||
|
||||
|
||||
def test_relative_redirects(tmpdir, scheme, do_request):
|
||||
url = scheme + "://httpbin.org"
|
||||
url = scheme + "://mockbin.com/redirect/301?to=/redirect/301?to=/request"
|
||||
testfile = str(tmpdir.join("relative_redirects.yml"))
|
||||
with vcr.use_cassette(testfile):
|
||||
response = do_request()("GET", url + "/redirect-to?url=/redirect-to?url=/get")
|
||||
assert len(response.history) == 2
|
||||
assert response.json()["url"].endswith("get")
|
||||
response = do_request()("GET", url)
|
||||
assert len(response.history) == 2, response
|
||||
assert response.json()["url"].endswith("request")
|
||||
|
||||
with vcr.use_cassette(testfile) as cassette:
|
||||
response = do_request()("GET", url + "/redirect-to?url=/redirect-to?url=/get")
|
||||
response = do_request()("GET", url)
|
||||
assert len(response.history) == 2
|
||||
assert response.json()["url"].endswith("get")
|
||||
assert response.json()["url"].endswith("request")
|
||||
|
||||
assert cassette.play_count == 3
|
||||
|
||||
Reference in New Issue
Block a user