mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-10 09:35:34 +00:00
meh I guess HTTPS works
This commit is contained in:
@@ -42,9 +42,8 @@ Ruby's VCR are not compatible with VCR.py. The API is similar but VCR.py
|
|||||||
doesn't have nearly as many features.
|
doesn't have nearly as many features.
|
||||||
|
|
||||||
##Known Issues
|
##Known Issues
|
||||||
* Only works with the first HTTP request made in each use_cassette block. That's because I haven't gotten around to implementing multiple requests yet.
|
* Only works with the first HTTP request made in each use_cassette block. That's because I haven't gotten around to implementing multiple requests yet. This means anything that does a 301 / 302 won't work.
|
||||||
* Probably only works with urllib2. Hey, doesn't `requests` use urllib2? Maybe that works too then.
|
* Probably only works with urllib2. Hey, doesn't `requests` use urllib2? Maybe that works too then.
|
||||||
* No HTTPS support (yet)
|
|
||||||
|
|
||||||
##Similar libraries in Python
|
##Similar libraries in Python
|
||||||
Neither of these really implement the API I want, but I have cribbed some code
|
Neither of these really implement the API I want, but I have cribbed some code
|
||||||
|
|||||||
32
test.py
32
test.py
@@ -8,7 +8,7 @@ TEST_CASSETTE_FILE = 'test/test_req.yaml'
|
|||||||
|
|
||||||
class TestHttpRequest(unittest.TestCase):
|
class TestHttpRequest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
os.remove(TEST_CASSETTE_FILE)
|
os.remove(TEST_CASSETTE_FILE)
|
||||||
except OSError:
|
except OSError:
|
||||||
@@ -22,15 +22,41 @@ class TestHttpRequest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_response_body(self):
|
def test_response_body(self):
|
||||||
body = urllib2.urlopen('http://www.iana.org/domains/example/').read()
|
body = urllib2.urlopen('http://www.iana.org/domains/example/').read()
|
||||||
with vcr.use_cassette('test/synopsis.yaml'):
|
with vcr.use_cassette(TEST_CASSETTE_FILE):
|
||||||
self.assertEqual(body, urllib2.urlopen('http://www.iana.org/domains/example/').read())
|
self.assertEqual(body, urllib2.urlopen('http://www.iana.org/domains/example/').read())
|
||||||
self.assertEqual(body, urllib2.urlopen('http://www.iana.org/domains/example/').read())
|
self.assertEqual(body, urllib2.urlopen('http://www.iana.org/domains/example/').read())
|
||||||
|
|
||||||
def test_response_headers(self):
|
def test_response_headers(self):
|
||||||
with vcr.use_cassette('test/synopsis.yaml'):
|
with vcr.use_cassette(TEST_CASSETTE_FILE):
|
||||||
headers = urllib2.urlopen('http://www.iana.org/domains/example/').info().items()
|
headers = urllib2.urlopen('http://www.iana.org/domains/example/').info().items()
|
||||||
self.assertEqual(headers, urllib2.urlopen('http://www.iana.org/domains/example/').info().items())
|
self.assertEqual(headers, urllib2.urlopen('http://www.iana.org/domains/example/').info().items())
|
||||||
|
|
||||||
|
|
||||||
|
class TestHttps(unittest.TestCase):
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
try:
|
||||||
|
os.remove(TEST_CASSETTE_FILE)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_response_code(self):
|
||||||
|
code = urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').getcode()
|
||||||
|
with vcr.use_cassette(TEST_CASSETTE_FILE):
|
||||||
|
self.assertEqual(code, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').getcode())
|
||||||
|
self.assertEqual(code, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').getcode())
|
||||||
|
|
||||||
|
def test_response_body(self):
|
||||||
|
body = urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').read()
|
||||||
|
with vcr.use_cassette(TEST_CASSETTE_FILE):
|
||||||
|
self.assertEqual(body, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').read())
|
||||||
|
self.assertEqual(body, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').read())
|
||||||
|
|
||||||
|
def test_response_headers(self):
|
||||||
|
with vcr.use_cassette(TEST_CASSETTE_FILE):
|
||||||
|
headers = urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').info().items()
|
||||||
|
self.assertEqual(headers, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').info().items())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user