Add @get_workbench test
authorSebastian Spaeth <Sebastian@SSpaeth.de>
Wed, 12 Dec 2012 13:29:49 +0000 (14:29 +0100)
committerSebastian Spaeth <Sebastian@SSpaeth.de>
Wed, 16 Jan 2013 19:19:26 +0000 (20:19 +0100)
Test the decorator function and proper cleanup after it's usage.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
mediagoblin/tests/test_workbench.py

index 46fc39e48977e3be0cb85d017bcddbfb12e94137..9da8eea0592c24711cbc34f9252d784f47264948 100644 (file)
@@ -19,6 +19,8 @@ import tempfile
 
 
 from mediagoblin import workbench
+from mediagoblin.mg_globals import setup_globals
+from mediagoblin.decorators import get_workbench
 from mediagoblin.tests.test_storage import get_tmp_filestorage
 
 
@@ -57,7 +59,7 @@ class TestWorkbench(object):
     def test_localized_file(self):
         tmpdir, this_storage = get_tmp_filestorage()
         this_workbench = self.workbench_manager.create()
-        
+
         # Write a brand new file
         filepath = ['dir1', 'dir2', 'ourfile.txt']
 
@@ -79,7 +81,7 @@ class TestWorkbench(object):
         filename = this_workbench.localized_file(this_storage, filepath)
         assert filename == os.path.join(
             this_workbench.dir, 'ourfile.txt')
-        
+
         # fake remote file storage, filename_if_copying set
         filename = this_workbench.localized_file(
             this_storage, filepath, 'thisfile')
@@ -92,3 +94,18 @@ class TestWorkbench(object):
             this_storage, filepath, 'thisfile.text', False)
         assert filename == os.path.join(
             this_workbench.dir, 'thisfile.text')
+
+    def test_workbench_decorator(self):
+        """Test @get_workbench decorator and automatic cleanup"""
+        # The decorator needs mg_globals.workbench_manager
+        setup_globals(workbench_manager=self.workbench_manager)
+
+        @get_workbench
+        def create_it(workbench=None):
+            # workbench dir exists?
+            assert os.path.isdir(workbench.dir)
+            return workbench.dir
+
+        benchdir = create_it()
+        # workbench dir has been cleaned up automatically?
+        assert not os.path.isdir(benchdir)