]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Default path_transformer=None. Fixes #199
authorAron Griffis <aron@arongriffis.com>
Fri, 28 Aug 2015 11:25:03 +0000 (07:25 -0400)
committerAron Griffis <aron@arongriffis.com>
Fri, 28 Aug 2015 11:25:03 +0000 (07:25 -0400)
tests/unit/test_cassettes.py
tests/unit/test_vcr.py
vcr/cassette.py
vcr/config.py
vcr/util.py

index e1e9fb9144fa60c6fce353968f1f771e98ca0dba..413b154d5f2b6206a2c7080b2f2deec3e5058b3c 100644 (file)
@@ -245,6 +245,13 @@ def test_path_transformer_with_context_manager():
         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 generator(function):
         return os.path.join(os.path.dirname(inspect.getfile(function)),
index cbdcde44ad65f49d7485abbc152c519fb73f2fbd..6cbf21b6f737972cb36bbca6f96180040e71cf30 100644 (file)
@@ -98,6 +98,28 @@ def test_vcr_before_record_response_iterable():
             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
 def random_fixture():
     return 1
index bc7410ff684677cf08bbd3e64155fb68befa45fb..6dc6c402502cd1fef2a9222e94977d1a0f3a369e 100644 (file)
@@ -75,7 +75,7 @@ class CassetteContextDecorator(object):
             lambda key, _: key in self._non_cassette_arguments,
             self._args_getter()
         )
-        if 'path_transformer' in other_kwargs:
+        if other_kwargs.get('path_transformer'):
             transformer = other_kwargs['path_transformer']
             cassette_kwargs['path'] = transformer(cassette_kwargs['path'])
         self.__finish = self._patch_generator(self.cls.load(**cassette_kwargs))
index e2389dbe281597ec55a8d218928752d0d9ba5a36..99e4cf7c49610218128701785f180c603216bd14 100644 (file)
@@ -23,7 +23,7 @@ class VCR(object):
             return path
         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=(),
                  record_mode="once", ignore_localhost=False, filter_headers=(),
                  before_record_response=None, filter_post_data_parameters=(),
@@ -108,7 +108,7 @@ class VCR(object):
         matcher_names = kwargs.get('match_on', self.match_on)
         path_transformer = kwargs.get(
             'path_transformer',
-            self.path_transformer or self.ensure_suffix('.yaml')
+            self.path_transformer
         )
         func_path_generator = kwargs.get(
             'func_path_generator',
index 8c5bd9472aa911d69475bab50343247ab5b4c9bf..b36ff7576349bb938025c420757cb7ad5d3a08d2 100644 (file)
@@ -81,8 +81,9 @@ def partition_dict(predicate, dictionary):
 def compose(*functions):
     def composed(incoming):
         res = incoming
-        for function in functions[::-1]:
-            res = function(res)
+        for function in reversed(functions):
+            if function:
+                res = function(res)
         return res
     return composed