]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
+ @bhartin - now vcr can handle multiple requests
authorSri Prasanna <k.sriprasanna@gmail.com>
Thu, 21 Feb 2013 10:04:55 +0000 (13:04 +0300)
committerSri Prasanna <k.sriprasanna@gmail.com>
Thu, 21 Feb 2013 10:04:55 +0000 (13:04 +0300)
test.py
vcr/files.py

diff --git a/test.py b/test.py
index a04efb414ffa0c94e47369dcd861d74d047b2529..10417eccb26e402a1fca0de06fb991432ac4dbf7 100644 (file)
--- a/test.py
+++ b/test.py
@@ -5,10 +5,10 @@ import vcr
 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 @@ class TestHttpRequest(unittest.TestCase):
         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 @@ class TestHttpRequest(unittest.TestCase):
     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):
index 79047d7fba7698ce873fce1411a0eb4c9c2d536b..86b6d18d43fea2473bc388ac967ca3fde4aa19a5 100644 (file)
@@ -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()))