]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
lets store the proto too
authorKevin McCarthy <me@kevinmccarthy.org>
Sat, 10 Aug 2013 23:33:10 +0000 (13:33 -1000)
committerKevin McCarthy <me@kevinmccarthy.org>
Mon, 12 Aug 2013 01:05:41 +0000 (15:05 -1000)
tests/unit/test_request.py [new file with mode: 0644]
vcr/request.py
vcr/stubs/__init__.py

diff --git a/tests/unit/test_request.py b/tests/unit/test_request.py
new file mode 100644 (file)
index 0000000..c75d377
--- /dev/null
@@ -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>'
index 461d577f0ac93e3537551c486a37fc623dd58345..d91e29faa9580436082946d32744565159e78092 100644 (file)
@@ -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 "<Request ({0}) {1}>".format(self.method, self.body)
+        return "<Request ({0}) {1}>".format(self.method, self.url)
index e102ee909a58f337bc31713395f11d1626177d5f..18af6ba79ee7bc56eb7711cdd922b1950dc52053 100644 (file)
@@ -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