mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 09:13:23 +00:00
lets store the proto too
This commit is contained in:
9
tests/unit/test_request.py
Normal file
9
tests/unit/test_request.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from vcr.request import Request
|
||||||
|
|
||||||
|
def test_url():
|
||||||
|
req = Request('http','www.google.com',80,'GET','/','',{})
|
||||||
|
assert req.url == 'http://www.google.com/'
|
||||||
|
|
||||||
|
def test_str():
|
||||||
|
req = Request('http','www.google.com',80,'GET','/','',{})
|
||||||
|
str(req) == '<Request (GET) http://www.google.com>'
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
class Request(object):
|
class Request(object):
|
||||||
|
|
||||||
def __init__(self, host, port, method, path, body, headers):
|
def __init__(self, protocol, host, port, method, path, body, headers):
|
||||||
|
self.protocol = protocol
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
self.method = method
|
self.method = method
|
||||||
self.path = path
|
self.path = path
|
||||||
self.body = body
|
self.body = body
|
||||||
|
# make haders a frozenset so it will be hashable
|
||||||
self.headers = frozenset(headers.items())
|
self.headers = frozenset(headers.items())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
return self.host + self.path
|
print self.protocol, self.host, self.path
|
||||||
|
return "{0}://{1}{2}".format(self.protocol, self.host, self.path)
|
||||||
|
|
||||||
def __key(self):
|
def __key(self):
|
||||||
return (self.host, self.port, self.method, self.path, self.body, self.headers)
|
return (self.host, self.port, self.method, self.path, self.body, self.headers)
|
||||||
@@ -22,4 +25,4 @@ class Request(object):
|
|||||||
return hash(self) == hash(other)
|
return hash(self) == hash(other)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "<Request ({0}) {1}>".format(self.method, self.body)
|
return "<Request ({0}) {1}>".format(self.method, self.url)
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class VCRConnectionMixin:
|
|||||||
def request(self, method, url, body=None, headers=None):
|
def request(self, method, url, body=None, headers=None):
|
||||||
'''Persist the request metadata in self._vcr'''
|
'''Persist the request metadata in self._vcr'''
|
||||||
self._request = Request(
|
self._request = Request(
|
||||||
|
protocol = self._protocol,
|
||||||
host = self.host,
|
host = self.host,
|
||||||
port = self.port,
|
port = self.port,
|
||||||
method = method,
|
method = method,
|
||||||
@@ -91,6 +92,7 @@ class VCRHTTPConnection(VCRConnectionMixin, HTTPConnection):
|
|||||||
'''A Mocked class for HTTP requests'''
|
'''A Mocked class for HTTP requests'''
|
||||||
# Can't use super since this is an old-style class
|
# Can't use super since this is an old-style class
|
||||||
_baseclass = HTTPConnection
|
_baseclass = HTTPConnection
|
||||||
|
_protocol = 'http'
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
HTTPConnection.__init__(self, *args, **kwargs)
|
HTTPConnection.__init__(self, *args, **kwargs)
|
||||||
@@ -99,6 +101,7 @@ class VCRHTTPConnection(VCRConnectionMixin, HTTPConnection):
|
|||||||
class VCRHTTPSConnection(VCRConnectionMixin, HTTPSConnection):
|
class VCRHTTPSConnection(VCRConnectionMixin, HTTPSConnection):
|
||||||
'''A Mocked class for HTTPS requests'''
|
'''A Mocked class for HTTPS requests'''
|
||||||
_baseclass = HTTPSConnection
|
_baseclass = HTTPSConnection
|
||||||
|
_protocol = 'https'
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
'''I overrode the init and copied a lot of the code from the parent
|
'''I overrode the init and copied a lot of the code from the parent
|
||||||
|
|||||||
Reference in New Issue
Block a user