1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

fixes before_record_response mutates response

When no cassette exists, it's expected that the response returned, should be
the original, unchanged response. The response recorded in the cassette should be
that which is returned by the before_record_response callback.

But on subsequent requests/responses (when a cassette exists), the responses
returned should be exactly what is in the cassette.

resolves #355
This commit is contained in:
kg
2018-05-09 20:44:28 +00:00
parent f890709a20
commit ba79174a1f
2 changed files with 52 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import collections
import copy
import sys
import inspect
import logging
@@ -222,6 +223,9 @@ class Cassette(object):
request = self._before_record_request(request)
if not request:
return
# Deepcopy is here because mutation of `response` will corrupt the
# real response.
response = copy.deepcopy(response)
response = self._before_record_response(response)
if response is None:
return