--- /dev/null
+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>'
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.port = port
self.method = method
self.path = path
self.body = body
+ # make haders a frozenset so it will be hashable
self.headers = frozenset(headers.items())
@property
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):
return (self.host, self.port, self.method, self.path, self.body, self.headers)
return hash(self) == hash(other)
def __str__(self):
- return "<Request ({0}) {1}>".format(self.method, self.body)
+ return "<Request ({0}) {1}>".format(self.method, self.url)
def request(self, method, url, body=None, headers=None):
'''Persist the request metadata in self._vcr'''
self._request = Request(
+ protocol = self._protocol,
host = self.host,
port = self.port,
method = method,
'''A Mocked class for HTTP requests'''
# Can't use super since this is an old-style class
_baseclass = HTTPConnection
+ _protocol = 'http'
def __init__(self, *args, **kwargs):
HTTPConnection.__init__(self, *args, **kwargs)
class VCRHTTPSConnection(VCRConnectionMixin, HTTPSConnection):
'''A Mocked class for HTTPS requests'''
_baseclass = HTTPSConnection
+ _protocol = 'https'
def __init__(self, *args, **kwargs):
'''I overrode the init and copied a lot of the code from the parent