1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 09:13:23 +00:00
This commit is contained in:
Kevin McCarthy
2012-07-02 10:00:18 -10:00
parent e1cd92b14d
commit bf844c6952
2 changed files with 18 additions and 21 deletions

34
test.py
View File

@@ -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()

View File

@@ -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):