]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Fixes #123. When attempting to replay the same request twice using record_mode="new_e...
authorNithin Reddy <nithin.reddy@invitae.com>
Fri, 21 Nov 2014 03:07:21 +0000 (19:07 -0800)
committerNithin Reddy <nithin.reddy@invitae.com>
Fri, 21 Nov 2014 03:07:21 +0000 (19:07 -0800)
tests/integration/test_record_mode.py
vcr/cassette.py

index 0e007b36be32a53955517ea7fc270132f13b57f7..f658adfe58512ea88734167a4274464133897b56 100644 (file)
@@ -72,6 +72,21 @@ def test_new_episodes_record_mode(tmpdir):
         assert len(cass.responses) == 2
 
 
+def test_new_episodes_record_mode_two_times(tmpdir):
+    testfile = str(tmpdir.join('recordmode.yml'))
+    with vcr.use_cassette(testfile, record_mode="new_episodes"):
+        # cassette file doesn't exist, so create.
+        response1 = urlopen('http://httpbin.org/').read()
+
+    with vcr.use_cassette(testfile, record_mode="new_episodes") as cass:
+        # make the same request again
+        response = urlopen('http://httpbin.org/').read()
+
+        # in the "new_episodes" record mode, we can add the same request
+        # to the cassette without repercussions
+        response = urlopen('http://httpbin.org/').read()
+
+
 def test_all_record_mode(tmpdir):
     testfile = str(tmpdir.join('recordmode.yml'))
 
index 099253f71132ab07a863e559ec4b58ffd286cd99..7a8a4ddcabd181361a3bc552d1308000e2f37d8f 100644 (file)
@@ -219,6 +219,7 @@ class Cassette(object):
 
     def __contains__(self, request):
         """Return whether or not a request has been stored"""
-        for response in self._responses(request):
-            return True
+        for index, response in self._responses(request):
+            if self.play_counts[index] == 0:
+                return True
         return False