mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
properly handle tunnel connect uri generation broken in #389
This commit is contained in:
@@ -3,9 +3,13 @@ import pytest
|
|||||||
from vcr.request import Request, HeadersDict
|
from vcr.request import Request, HeadersDict
|
||||||
|
|
||||||
|
|
||||||
def test_str():
|
@pytest.mark.parametrize("method, uri, expected_str", [
|
||||||
req = Request('GET', 'http://www.google.com/', '', {})
|
('GET', 'http://www.google.com/', '<Request (GET) http://www.google.com/>'),
|
||||||
str(req) == '<Request (GET) http://www.google.com/>'
|
('OPTIONS', '*', '<Request (OPTIONS) *>'),
|
||||||
|
('CONNECT', 'host.some.where:1234', '<Request (CONNECT) host.some.where:1234>')
|
||||||
|
])
|
||||||
|
def test_str(method, uri, expected_str):
|
||||||
|
assert str(Request(method, uri, '', {})) == expected_str
|
||||||
|
|
||||||
|
|
||||||
def test_headers():
|
def test_headers():
|
||||||
@@ -29,18 +33,21 @@ def test_add_header_deprecated():
|
|||||||
('https://go.com/', 443),
|
('https://go.com/', 443),
|
||||||
('https://go.com:443/', 443),
|
('https://go.com:443/', 443),
|
||||||
('https://go.com:3000/', 3000),
|
('https://go.com:3000/', 3000),
|
||||||
|
('*', None)
|
||||||
])
|
])
|
||||||
def test_port(uri, expected_port):
|
def test_port(uri, expected_port):
|
||||||
req = Request('GET', uri, '', {})
|
req = Request('GET', uri, '', {})
|
||||||
assert req.port == expected_port
|
assert req.port == expected_port
|
||||||
|
|
||||||
|
|
||||||
def test_uri():
|
@pytest.mark.parametrize("method, uri", [
|
||||||
req = Request('GET', 'http://go.com/', '', {})
|
('GET', 'http://go.com/'),
|
||||||
assert req.uri == 'http://go.com/'
|
('GET', 'http://go.com:80/'),
|
||||||
|
('CONNECT', 'localhost:1234'),
|
||||||
req = Request('GET', 'http://go.com:80/', '', {})
|
('OPTIONS', '*')
|
||||||
assert req.uri == 'http://go.com:80/'
|
])
|
||||||
|
def test_uri(method, uri):
|
||||||
|
assert Request(method, uri, '', {}).uri == uri
|
||||||
|
|
||||||
|
|
||||||
def test_HeadersDict():
|
def test_HeadersDict():
|
||||||
|
|||||||
@@ -58,7 +58,10 @@ class Request(object):
|
|||||||
parse_uri = urlparse(self.uri)
|
parse_uri = urlparse(self.uri)
|
||||||
port = parse_uri.port
|
port = parse_uri.port
|
||||||
if port is None:
|
if port is None:
|
||||||
port = {'https': 443, 'http': 80}[parse_uri.scheme]
|
try:
|
||||||
|
port = {'https': 443, 'http': 80}[parse_uri.scheme]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
return port
|
return port
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
Reference in New Issue
Block a user