Skip to content

Commit

Permalink
Merge pull request #154 from betamaxpy/bug/153
Browse files Browse the repository at this point in the history
Fix bug with new_episodes always trying to record
  • Loading branch information
sigmavirus24 committed Apr 6, 2018
2 parents 6dd3d84 + 26ff45b commit cf26610
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/betamax/cassette/cassette.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ def find_match(self, request):
:returns: :class:`~betamax.cassette.Interaction`
"""
# if we are recording, do not filter by match
if self.is_recording() and self.record_mode != 'all':
return None
if self.is_recording():
if ((self.record_mode == 'new_episodes' and
all(i.used is True for i in self.interactions)) or
self.record_mode in ('once', 'none')):
return None

opts = self.match_options
# Curry those matchers
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_cassette.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,28 @@ def test_find_match(self):
assert i is not None
assert self.interaction is i

def test_find_match_new_episodes_with_existing_unused_interactions(self):
"""See bug 153 in GitHub for details.
https://github.com/betamaxpy/betamax/issues/153
"""
self.cassette.match_options = set(['method', 'uri'])
self.cassette.record_mode = 'new_episodes'
i = self.cassette.find_match(self.response.request)
assert i is not None
assert self.interaction is i

def test_find_match_new_episodes_with_no_unused_interactions(self):
"""See bug 153 in GitHub for details.
https://github.com/betamaxpy/betamax/issues/153
"""
self.cassette.match_options = set(['method', 'uri'])
self.cassette.record_mode = 'new_episodes'
self.interaction.used = True
i = self.cassette.find_match(self.response.request)
assert i is None

def test_find_match__missing_matcher(self):
self.cassette.match_options = set(['uri', 'method', 'invalid'])
self.cassette.record_mode = 'none'
Expand Down

0 comments on commit cf26610

Please sign in to comment.