mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53: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):
|
||||
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user