1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 01:25:34 +00:00

check that cassette contains things before returning

This commit is contained in:
Kevin McCarthy
2013-08-06 18:34:56 -10:00
parent 37504c8982
commit 166facd0d0
3 changed files with 18 additions and 18 deletions

View File

@@ -65,22 +65,22 @@ class VCRConnectionMixin:
'''Retrieve a the response'''
# Check to see if the cassette has a response for this request. If so,
# then return it
response = self.cassette.response(self._request)
if response:
if self._request in self.cassette:
response = self.cassette.response(self._request)
# Alert the cassette to the fact that we've served another
# response for the provided requests
self.cassette.mark_played()
return VCRHTTPResponse(response)
# Otherwise, we made an actual request, and should return the response
# we got from the actual connection
response = HTTPConnection.getresponse(self)
response = {
'status': {'code': response.status, 'message': response.reason},
'headers': dict(response.getheaders()),
'body': {'string': response.read()},
}
self.cassette.append(self._request, response)
else:
# Otherwise, we made an actual request, and should return the response
# we got from the actual connection
response = HTTPConnection.getresponse(self)
response = {
'status': {'code': response.status, 'message': response.reason},
'headers': dict(response.getheaders()),
'body': {'string': response.read()},
}
self.cassette.append(self._request, response)
return VCRHTTPResponse(response)