mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 09:13:23 +00:00
Default path_transformer=None. Fixes #199
This commit is contained in:
@@ -245,6 +245,13 @@ def test_path_transformer_with_context_manager():
|
|||||||
assert cassette._path == 'a'
|
assert cassette._path == 'a'
|
||||||
|
|
||||||
|
|
||||||
|
def test_path_transformer_None():
|
||||||
|
with Cassette.use(
|
||||||
|
path='a', path_transformer=None,
|
||||||
|
) as cassette:
|
||||||
|
assert cassette._path == 'a'
|
||||||
|
|
||||||
|
|
||||||
def test_func_path_generator():
|
def test_func_path_generator():
|
||||||
def generator(function):
|
def generator(function):
|
||||||
return os.path.join(os.path.dirname(inspect.getfile(function)),
|
return os.path.join(os.path.dirname(inspect.getfile(function)),
|
||||||
|
|||||||
@@ -98,6 +98,28 @@ def test_vcr_before_record_response_iterable():
|
|||||||
assert mock_filter.call_count == 1
|
assert mock_filter.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_vcr_path_transformer():
|
||||||
|
# Regression test for #199
|
||||||
|
|
||||||
|
# Prevent actually saving the cassette
|
||||||
|
with mock.patch('vcr.cassette.save_cassette'):
|
||||||
|
|
||||||
|
# Baseline: path should be unchanged
|
||||||
|
vcr = VCR()
|
||||||
|
with vcr.use_cassette('test') as cassette:
|
||||||
|
assert cassette._path == 'test'
|
||||||
|
|
||||||
|
# Regression test: path_transformer=None should do the same.
|
||||||
|
vcr = VCR(path_transformer=None)
|
||||||
|
with vcr.use_cassette('test') as cassette:
|
||||||
|
assert cassette._path == 'test'
|
||||||
|
|
||||||
|
# and it should still work with cassette_library_dir
|
||||||
|
vcr = VCR(cassette_library_dir='/foo')
|
||||||
|
with vcr.use_cassette('test') as cassette:
|
||||||
|
assert cassette._path == '/foo/test'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def random_fixture():
|
def random_fixture():
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class CassetteContextDecorator(object):
|
|||||||
lambda key, _: key in self._non_cassette_arguments,
|
lambda key, _: key in self._non_cassette_arguments,
|
||||||
self._args_getter()
|
self._args_getter()
|
||||||
)
|
)
|
||||||
if 'path_transformer' in other_kwargs:
|
if other_kwargs.get('path_transformer'):
|
||||||
transformer = other_kwargs['path_transformer']
|
transformer = other_kwargs['path_transformer']
|
||||||
cassette_kwargs['path'] = transformer(cassette_kwargs['path'])
|
cassette_kwargs['path'] = transformer(cassette_kwargs['path'])
|
||||||
self.__finish = self._patch_generator(self.cls.load(**cassette_kwargs))
|
self.__finish = self._patch_generator(self.cls.load(**cassette_kwargs))
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class VCR(object):
|
|||||||
return path
|
return path
|
||||||
return ensure
|
return ensure
|
||||||
|
|
||||||
def __init__(self, path_transformer=lambda x: x, before_record_request=None,
|
def __init__(self, path_transformer=None, before_record_request=None,
|
||||||
custom_patches=(), filter_query_parameters=(), ignore_hosts=(),
|
custom_patches=(), filter_query_parameters=(), ignore_hosts=(),
|
||||||
record_mode="once", ignore_localhost=False, filter_headers=(),
|
record_mode="once", ignore_localhost=False, filter_headers=(),
|
||||||
before_record_response=None, filter_post_data_parameters=(),
|
before_record_response=None, filter_post_data_parameters=(),
|
||||||
@@ -108,7 +108,7 @@ class VCR(object):
|
|||||||
matcher_names = kwargs.get('match_on', self.match_on)
|
matcher_names = kwargs.get('match_on', self.match_on)
|
||||||
path_transformer = kwargs.get(
|
path_transformer = kwargs.get(
|
||||||
'path_transformer',
|
'path_transformer',
|
||||||
self.path_transformer or self.ensure_suffix('.yaml')
|
self.path_transformer
|
||||||
)
|
)
|
||||||
func_path_generator = kwargs.get(
|
func_path_generator = kwargs.get(
|
||||||
'func_path_generator',
|
'func_path_generator',
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ def partition_dict(predicate, dictionary):
|
|||||||
def compose(*functions):
|
def compose(*functions):
|
||||||
def composed(incoming):
|
def composed(incoming):
|
||||||
res = incoming
|
res = incoming
|
||||||
for function in functions[::-1]:
|
for function in reversed(functions):
|
||||||
|
if function:
|
||||||
res = function(res)
|
res = function(res)
|
||||||
return res
|
return res
|
||||||
return composed
|
return composed
|
||||||
|
|||||||
Reference in New Issue
Block a user