mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 09:13:23 +00:00
cleanup
This commit is contained in:
34
test.py
34
test.py
@@ -39,9 +39,9 @@ class TestHttpRequest(unittest.TestCase):
|
||||
body2 = urllib2.urlopen('http://httpbin.org/get').read()
|
||||
with vcr.use_cassette(TEST_CASSETTE_FILE):
|
||||
self.assertEqual(body1, urllib2.urlopen('http://httpbin.org/').read())
|
||||
self.assertEqual(body2, urllib2.urlopen('http://httpbin.org/get').read())
|
||||
self.assertEqual(body2, urllib2.urlopen('http://httpbin.org/get').read())
|
||||
self.assertEqual(body1, urllib2.urlopen('http://httpbin.org/').read())
|
||||
self.assertEqual(body2, urllib2.urlopen('http://httpbin.org/get').read())
|
||||
self.assertEqual(body2, urllib2.urlopen('http://httpbin.org/get').read())
|
||||
|
||||
|
||||
class TestHttps(unittest.TestCase):
|
||||
@@ -70,35 +70,33 @@ class TestHttps(unittest.TestCase):
|
||||
self.assertEqual(headers, urllib2.urlopen('https://httpbin.org/').info().items())
|
||||
|
||||
def test_get_data(self):
|
||||
TEST_DATA = urlencode({'some':1,'data':'here'})
|
||||
TEST_DATA = urlencode({'some': 1, 'data': 'here'})
|
||||
with vcr.use_cassette(TEST_CASSETTE_FILE):
|
||||
body = urllib2.urlopen('https://httpbin.org/get?' + TEST_DATA).read()
|
||||
self.assertEqual(body, urllib2.urlopen('https://httpbin.org/get?' + TEST_DATA).read())
|
||||
|
||||
def test_post_data(self):
|
||||
TEST_DATA = urlencode({'some':1,'data':'here'})
|
||||
TEST_DATA = urlencode({'some': 1, 'data': 'here'})
|
||||
with vcr.use_cassette(TEST_CASSETTE_FILE):
|
||||
body = urllib2.urlopen('https://httpbin.org/post',TEST_DATA).read()
|
||||
self.assertEqual(body, urllib2.urlopen('https://httpbin.org/post',TEST_DATA).read())
|
||||
body = urllib2.urlopen('https://httpbin.org/post', TEST_DATA).read()
|
||||
self.assertEqual(body, urllib2.urlopen('https://httpbin.org/post', TEST_DATA).read())
|
||||
|
||||
def test_post_unicode(self):
|
||||
TEST_DATA = urlencode({'snowman':u'☃'.encode('utf-8')})
|
||||
TEST_DATA = urlencode({'snowman': u'☃'.encode('utf-8')})
|
||||
with vcr.use_cassette(TEST_CASSETTE_FILE):
|
||||
body = urllib2.urlopen('https://httpbin.org/post',TEST_DATA).read()
|
||||
self.assertEqual(body, urllib2.urlopen('https://httpbin.org/post',TEST_DATA).read())
|
||||
body = urllib2.urlopen('https://httpbin.org/post', TEST_DATA).read()
|
||||
self.assertEqual(body, urllib2.urlopen('https://httpbin.org/post', TEST_DATA).read())
|
||||
|
||||
|
||||
class TestCassette(unittest.TestCase):
|
||||
def test_serialize_cassette(self):
|
||||
c1 = Cassette()
|
||||
c1.requests = ['a','b','c']
|
||||
c1.responses = ['d','e','f']
|
||||
ser = c1.serialize()
|
||||
c2 = Cassette(ser)
|
||||
self.assertEqual(c1.requests,c2.requests)
|
||||
self.assertEqual(c1.responses,c2.responses)
|
||||
|
||||
|
||||
|
||||
c1.requests = ['a', 'b', 'c']
|
||||
c1.responses = ['d', 'e', 'f']
|
||||
ser = c1.serialize()
|
||||
c2 = Cassette(ser)
|
||||
self.assertEqual(c1.requests, c2.requests)
|
||||
self.assertEqual(c1.responses, c2.responses)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import socket
|
||||
from httplib import HTTPConnection, HTTPSConnection, HTTPMessage
|
||||
from cStringIO import StringIO
|
||||
from .files import save_cassette, load_cassette
|
||||
@@ -83,8 +82,8 @@ class VCRHTTPSConnection(HTTPSConnection):
|
||||
one.
|
||||
"""
|
||||
HTTPConnection.__init__(self, *args, **kwargs)
|
||||
self.key_file = kwargs.pop('key_file',None)
|
||||
self.cert_file = kwargs.pop('cert_file',None)
|
||||
self.key_file = kwargs.pop('key_file', None)
|
||||
self.cert_file = kwargs.pop('cert_file', None)
|
||||
self._cassette = Cassette()
|
||||
|
||||
def _load_old_response(self):
|
||||
|
||||
Reference in New Issue
Block a user