aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2011-06-11 19:18:51 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2011-06-11 19:18:51 -0500
commitf43ecb0fc459c0ee64f3a40b98ed6bbf8564c107 (patch)
tree12db5c2131caaaf2e7b7f9401292b37fe3bdb6bf
parentf2b96ff0a4efab989ff5558de44b33da21b1bf00 (diff)
downloadmediagoblin-f43ecb0fc459c0ee64f3a40b98ed6bbf8564c107.tar.lz
mediagoblin-f43ecb0fc459c0ee64f3a40b98ed6bbf8564c107.tar.xz
mediagoblin-f43ecb0fc459c0ee64f3a40b98ed6bbf8564c107.zip
test WorkbenchManager.possibly_localize_file()
-rw-r--r--mediagoblin/tests/test_workbench.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/mediagoblin/tests/test_workbench.py b/mediagoblin/tests/test_workbench.py
index 83e90c3d..fd71a6eb 100644
--- a/mediagoblin/tests/test_workbench.py
+++ b/mediagoblin/tests/test_workbench.py
@@ -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')