]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
register custom persister fix
authorPetr Bulusek <bulusek.petr@gmail.com>
Wed, 9 Aug 2017 12:25:10 +0000 (14:25 +0200)
committerPetr Bulusek <bulusek.petr@gmail.com>
Wed, 9 Aug 2017 12:25:10 +0000 (14:25 +0200)
tests/integration/test_register_persister.py
vcr/config.py
vcr/persisters/filesystem.py

index 64e20b6f543c53c1ddb18679360d4a00eb5d39f5..65b9020ff4d8fe7d832f2e264b026ee4e209b95c 100644 (file)
@@ -10,10 +10,27 @@ import vcr
 from vcr.persisters.filesystem import FilesystemPersister
 
 
+class CustomFilesystemPersister(object):
+    """
+    like default FilesystemPersister but
+    adds .test extension to cassette file
+    """
+    @staticmethod
+    def load_cassette(cassette_path, serializer):
+        cassette_path += '.test'
+        return FilesystemPersister.load_cassette(cassette_path, serializer)
+
+    @staticmethod
+    def save_cassette(cassette_path, cassette_dict, serializer):
+        cassette_path += '.test'
+        FilesystemPersister.save_cassette(cassette_path, cassette_dict,
+                                          serializer)
+
+
 def test_save_cassette_with_custom_persister(tmpdir, httpbin):
     '''Ensure you can save a cassette using custom persister'''
     my_vcr = vcr.VCR()
-    my_vcr.register_persister(FilesystemPersister)
+    my_vcr.register_persister(CustomFilesystemPersister)
 
     # Check to make sure directory doesnt exist
     assert not os.path.exists(str(tmpdir.join('nonexistent')))
@@ -23,7 +40,7 @@ def test_save_cassette_with_custom_persister(tmpdir, httpbin):
         urlopen(httpbin.url).read()
 
     # Callback should have made the file and the directory
-    assert os.path.exists(str(tmpdir.join('nonexistent', 'cassette.yml')))
+    assert os.path.exists(str(tmpdir.join('nonexistent', 'cassette.yml.test')))
 
 
 def test_load_cassette_with_custom_persister(tmpdir, httpbin):
@@ -31,9 +48,9 @@ def test_load_cassette_with_custom_persister(tmpdir, httpbin):
     Ensure you can load a cassette using custom persister
     '''
     my_vcr = vcr.VCR()
-    my_vcr.register_persister(FilesystemPersister)
+    my_vcr.register_persister(CustomFilesystemPersister)
 
-    test_fixture = str(tmpdir.join('synopsis.json'))
+    test_fixture = str(tmpdir.join('synopsis.json.test'))
 
     with my_vcr.use_cassette(test_fixture, serializer='json'):
         response = urlopen(httpbin.url).read()
index 15ae459d78ee2a6934cd9be1dd84a89915563775..cfc890da42125474171f16369d684fc573fbac1c 100644 (file)
@@ -145,6 +145,7 @@ class VCR(object):
 
         merged_config = {
             'serializer': self._get_serializer(serializer_name),
+            'persister': self.persister,
             'match_on': self._get_matchers(
                 tuple(matcher_names) + tuple(additional_matchers)
             ),
index 43b52d4794149951ab6719b077a5a0ae314cd906..6e50529f7b090efd1040c0da3a302141470f77ed 100644 (file)
@@ -6,8 +6,8 @@ from ..serialize import serialize, deserialize
 
 class FilesystemPersister(object):
 
-    @classmethod
-    def load_cassette(cls, cassette_path, serializer):
+    @staticmethod
+    def load_cassette(cassette_path, serializer):
         try:
             with open(cassette_path) as f:
                 cassette_content = f.read()