test WorkbenchManager.possibly_localize_file()
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 12 Jun 2011 00:18:51 +0000 (19:18 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 12 Jun 2011 00:18:51 +0000 (19:18 -0500)
mediagoblin/tests/test_workbench.py

index 83e90c3dcc5bb1c1062cdf42cc894ebcaad9382d..fd71a6eb6c5ac246a246a6ff8bda46bd898b99bd 100644 (file)
@@ -20,6 +20,7 @@ import tempfile
 from nose.tools import assert_raises
 
 from mediagoblin.process_media import workbench
+from mediagoblin.tests.test_storage import get_tmp_filestorage
 
 
 class TestWorkbench(object):
@@ -52,3 +53,45 @@ class TestWorkbench(object):
             workbench.WorkbenchOutsideScope,
             self.workbench_manager.destroy_workbench,
             dont_kill_this)
+
+    def test_possibly_localize_file(self):
+        tmpdir, this_storage = get_tmp_filestorage()
+        this_workbench = self.workbench_manager.create_workbench()
+        
+        # Write a brand new file
+        filepath = ['dir1', 'dir2', 'ourfile.txt']
+
+        with this_storage.get_file(filepath, 'w') as our_file:
+            our_file.write('Our file')
+
+        # with a local file storage
+        filename, copied = self.workbench_manager.possibly_localize_file(
+            this_workbench, this_storage, filepath)
+        assert copied is False
+        assert filename == os.path.join(
+            tmpdir, 'dir1/dir2/ourfile.txt')
+
+        # with a fake remote file storage
+        tmpdir, this_storage = get_tmp_filestorage(fake_remote=True)
+
+        # ... write a brand new file, again ;)
+        with this_storage.get_file(filepath, 'w') as our_file:
+            our_file.write('Our file')
+
+        filename, copied = self.workbench_manager.possibly_localize_file(
+            this_workbench, this_storage, filepath)
+        assert filename == os.path.join(
+            this_workbench, 'ourfile.txt')
+        
+        # fake remote file storage, filename_if_copying set
+        filename, copied = self.workbench_manager.possibly_localize_file(
+            this_workbench, this_storage, filepath, 'thisfile')
+        assert filename == os.path.join(
+            this_workbench, 'thisfile.txt')
+
+        # fake remote file storage, filename_if_copying set,
+        # keep_extension_if_copying set to false
+        filename, copied = self.workbench_manager.possibly_localize_file(
+            this_workbench, this_storage, filepath, 'thisfile.text', False)
+        assert filename == os.path.join(
+            this_workbench, 'thisfile.text')