Permalink
Browse files

Merge pull request #10 from sriprasanna/master

Handling multiple requests
  • Loading branch information...
2 parents 1d3fe5c + ed682cf commit 71d0392419d87770549f31973559804a05b40a73 @kevin1024 committed Feb 22, 2013
Showing with 15 additions and 4 deletions.
  1. +14 −3 test.py
  2. +1 −1 vcr/files.py
View
@@ -5,10 +5,10 @@
from vcr.cassette import Cassette
import urllib2
from urllib import urlencode
+import json
TEST_CASSETTE_FILE = 'cassettes/test_req.yaml'
-
class TestHttpRequest(unittest.TestCase):
def tearDown(self):
@@ -17,6 +17,11 @@ def tearDown(self):
except OSError:
pass
+ def strip_origin(self, body):
+ body = json.loads(body)
+ del body['origin']
+ return body
+
def test_response_code(self):
code = urllib2.urlopen('http://httpbin.org/').getcode()
with vcr.use_cassette(TEST_CASSETTE_FILE):
@@ -37,11 +42,17 @@ def test_response_headers(self):
def test_multiple_requests(self):
body1 = urllib2.urlopen('http://httpbin.org/').read()
body2 = urllib2.urlopen('http://httpbin.org/get').read()
+ body2 = self.strip_origin(body2)
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())
+ new_body2 = urllib2.urlopen('http://httpbin.org/get').read()
+ new_body2 = self.strip_origin(new_body2)
+ self.assertEqual(body2, new_body2)
+
self.assertEqual(body1, urllib2.urlopen('http://httpbin.org/').read())
- self.assertEqual(body2, urllib2.urlopen('http://httpbin.org/get').read())
+ new_body2 = urllib2.urlopen('http://httpbin.org/get').read()
+ new_body2 = self.strip_origin(new_body2)
+ self.assertEqual(body2, new_body2)
class TestHttps(unittest.TestCase):
View
@@ -16,5 +16,5 @@ def save_cassette(cassette_path, cassette):
dirname, filename = os.path.split(cassette_path)
if not os.path.exists(dirname):
os.makedirs(dirname)
- with open(cassette_path, 'wc') as cassette_file:
+ with open(cassette_path, 'a') as cassette_file:
cassette_file.write(yaml.dump(cassette.serialize()))

0 comments on commit 71d0392

Please sign in to comment.