1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 17:15:35 +00:00

Nicer error for can't overwrite existing cassette

Raise CannotOverwriteExistingCassetteException rather than Exception.
Include cassette filename and record mode in error message.
This commit is contained in:
Marc Abramowitz
2013-12-19 13:55:19 -08:00
committed by Kevin McCarthy
parent a6806f2f99
commit 41f5fce895

View File

@@ -6,6 +6,10 @@ from cStringIO import StringIO
from vcr.request import Request from vcr.request import Request
class CannotOverwriteExistingCassetteException(Exception):
pass
def parse_headers(header_list): def parse_headers(header_list):
headers = "".join(header_list) + "\r\n" headers = "".join(header_list) + "\r\n"
msg = HTTPMessage(StringIO(headers)) msg = HTTPMessage(StringIO(headers))
@@ -172,9 +176,10 @@ class VCRConnectionMixin:
return VCRHTTPResponse(response) return VCRHTTPResponse(response)
else: else:
if self.cassette.write_protected: if self.cassette.write_protected:
raise Exception( raise CannotOverwriteExistingCassetteException(
"Can't overwrite existing cassette in \ "Can't overwrite existing cassette (%r) in "
your current record mode." "your current record mode (%r)."
% (self.cassette._path, self.cassette.record_mode)
) )
# Otherwise, we should send the request, then get the response # Otherwise, we should send the request, then get the response