diff --git a/tests/unit/test_request.py b/tests/unit/test_request.py new file mode 100644 index 0000000..c75d377 --- /dev/null +++ b/tests/unit/test_request.py @@ -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) == '' diff --git a/vcr/request.py b/vcr/request.py index 461d577..d91e29f 100644 --- a/vcr/request.py +++ b/vcr/request.py @@ -1,16 +1,19 @@ 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) @@ -22,4 +25,4 @@ class Request(object): return hash(self) == hash(other) def __str__(self): - return "".format(self.method, self.body) + return "".format(self.method, self.url) diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index e102ee9..18af6ba 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -47,6 +47,7 @@ class VCRConnectionMixin: 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, @@ -91,6 +92,7 @@ class VCRHTTPConnection(VCRConnectionMixin, HTTPConnection): '''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) @@ -99,6 +101,7 @@ class VCRHTTPConnection(VCRConnectionMixin, HTTPConnection): 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