Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disallowing writes only when fully matched request is in cassette #659

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions vcr/cassette.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ def _responses(self, request):
the request.
"""
request = self._before_record_request(request)
if request is None:
return
for index, (stored_request, response) in enumerate(self.data):
if requests_match(request, stored_request, self._match_on):
yield index, response
Expand Down
2 changes: 1 addition & 1 deletion vcr/stubs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def getresponse(self, _=False, **kwargs):
response = self.cassette.play_response(self._vcr_request)
return VCRHTTPResponse(response)
else:
if self.cassette.write_protected and self.cassette.filter_request(self._vcr_request):
if self.cassette.write_protected and self._vcr_request in self.cassette:
raise CannotOverwriteExistingCassetteException(
cassette=self.cassette, failed_request=self._vcr_request
)
Expand Down
2 changes: 1 addition & 1 deletion vcr/stubs/aiohttp_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ async def new_request(self, method, url, **kwargs):
self._cookie_jar.update_cookies(response.cookies, response.url)
return response

if cassette.write_protected and cassette.filter_request(vcr_request):
if cassette.write_protected and vcr_request in cassette:
raise CannotOverwriteExistingCassetteException(cassette=cassette, failed_request=vcr_request)

log.info("%s not in cassette, sending to real server", vcr_request)
Expand Down
2 changes: 1 addition & 1 deletion vcr/stubs/httpx_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _shared_vcr_send(cassette, real_send, *args, **kwargs):
if cassette.can_play_response_for(vcr_request):
return vcr_request, _play_responses(cassette, real_request, vcr_request, args[0], kwargs)

if cassette.write_protected and cassette.filter_request(vcr_request):
if cassette.write_protected and vcr_request in cassette:
raise CannotOverwriteExistingCassetteException(cassette=cassette, failed_request=vcr_request)

_logger.info("%s not in cassette, sending to real server", vcr_request)
Expand Down
2 changes: 1 addition & 1 deletion vcr/stubs/tornado_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def new_fetch_impl(self, request, callback):
)
return callback(response)
else:
if cassette.write_protected and cassette.filter_request(vcr_request):
if cassette.write_protected and vcr_request in cassette:
response = HTTPResponse(
request,
599,
Expand Down