diff --git a/README.md b/README.md index 73079ad..e985132 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,8 @@ the API. The fields are as follows: * `responses`: A list of the responses made. * `play_count`: The number of times this cassette has had a response played back + * `all_played`: A boolean indicates whether all the responses have been + played back * `responses_of(request)`: Access the responses that match a given request The `Request` object has the following properties: diff --git a/tests/integration/test_record_mode.py b/tests/integration/test_record_mode.py index c47baad..0e007b3 100644 --- a/tests/integration/test_record_mode.py +++ b/tests/integration/test_record_mode.py @@ -54,6 +54,9 @@ def test_new_episodes_record_mode(tmpdir): # make the same request again response = urlopen('http://httpbin.org/').read() + # all responses have been played + assert cass.all_played + # in the "new_episodes" record mode, we can add more requests to # a cassette without repurcussions. response = urlopen('http://httpbin.org/get').read() @@ -61,6 +64,9 @@ def test_new_episodes_record_mode(tmpdir): # one of the responses has been played assert cass.play_count == 1 + # not all responses have been played + assert not cass.all_played + with vcr.use_cassette(testfile, record_mode="new_episodes") as cass: # the cassette should now have 2 responses assert len(cass.responses) == 2 diff --git a/tests/unit/test_cassettes.py b/tests/unit/test_cassettes.py index 4c4818f..b612072 100644 --- a/tests/unit/test_cassettes.py +++ b/tests/unit/test_cassettes.py @@ -58,10 +58,25 @@ def test_cassette_get_missing_response(): with pytest.raises(UnhandledHTTPRequestError): a.responses_of('foo') + @mock.patch('vcr.cassette.requests_match', _mock_requests_match) def test_cassette_cant_read_same_request_twice(): a = Cassette('test') - a.append('foo','bar') + a.append('foo', 'bar') a.play_response('foo') with pytest.raises(UnhandledHTTPRequestError): a.play_response('foo') + + +def test_cassette_not_all_played(): + a = Cassette('test') + a.append('foo', 'bar') + assert not a.all_played + + +@mock.patch('vcr.cassette.requests_match', _mock_requests_match) +def test_cassette_all_played(): + a = Cassette('test') + a.append('foo', 'bar') + a.play_response('foo') + assert a.all_played diff --git a/vcr/cassette.py b/vcr/cassette.py index aa9f5a9..c58a6bd 100644 --- a/vcr/cassette.py +++ b/vcr/cassette.py @@ -60,6 +60,13 @@ class Cassette(ContextDecorator): def play_count(self): return sum(self.play_counts.values()) + @property + def all_played(self): + """ + Returns True if all responses have been played, False otherwise. + """ + return self.play_count == len(self) + @property def requests(self): return [request for (request, response) in self.data]