webish: upload+localdir=missing should give an error
authorBrian Warner <warner@allmydata.com>
Mon, 28 Jan 2008 21:48:06 +0000 (14:48 -0700)
committerBrian Warner <warner@allmydata.com>
Mon, 28 Jan 2008 21:48:06 +0000 (14:48 -0700)
src/allmydata/test/test_web.py
src/allmydata/webish.py

index 36f5e19ec797730302a0e5bb119eb0656b98a2f1..69d9bb5b606ee14f73bc0eb9fb6e7f627fbaedde 100644 (file)
@@ -959,14 +959,13 @@ class Web(WebMixin, unittest.TestCase):
         return d
 
     def test_PUT_NEWDIRURL_localdir_missing(self):
-        raise unittest.SkipTest("fix PUTHandler._upload_localdir to return "
-                                "an error instead of silently passing")
         localdir = os.path.abspath("web/PUT_NEWDIRURL_localdir_missing")
         # we do *not* create it, to trigger an error
         url = (self.public_url + "/foo/subdir/newdir?t=upload&localdir=%s"
                % urllib.quote(localdir))
         d = self.shouldHTTPError2("test_PUT_NEWDIRURL_localdir_missing",
-                                  400, "Bad Request", "random",
+                                  400, "Bad Request",
+                                  "%s doesn't exist!" % localdir,
                                   self.PUT, url, "")
         return d
 
index 755ae548fde9691decfd61c5d2a9526669362184..d7e9863006dc52971087a5fc07c8550759caae9c 100644 (file)
@@ -472,6 +472,8 @@ class BlockingFileError(Exception):
     the way"""
 class NoReplacementError(Exception):
     """There was already a child by that name, and you asked me to not replace it"""
+class NoLocalDirectoryError(Exception):
+    """The localdir= directory didn't exist"""
 
 LOCALHOST = "127.0.0.1"
 
@@ -931,18 +933,19 @@ class PUTHandler(rend.Page):
             d.addCallback(self._mkdir, name)
         else:
             d.addCallback(self._upload_file, req.content, name)
-        def _check_blocking(f):
-            f.trap(BlockingFileError)
-            req.setResponseCode(http.BAD_REQUEST)
-            req.setHeader("content-type", "text/plain")
-            return str(f.value)
-        d.addErrback(_check_blocking)
-        def _check_replacement(f):
-            f.trap(NoReplacementError)
-            req.setResponseCode(http.CONFLICT)
-            req.setHeader("content-type", "text/plain")
-            return str(f.value)
-        d.addErrback(_check_replacement)
+
+        def _transform_error(f):
+            errors = {BlockingFileError: http.BAD_REQUEST,
+                      NoReplacementError: http.CONFLICT,
+                      NoLocalDirectoryError: http.BAD_REQUEST,
+                      }
+            for k,v in errors.items():
+                if f.check(k):
+                    req.setResponseCode(v)
+                    req.setHeader("content-type", "text/plain")
+                    return str(f.value)
+            return f
+        d.addErrback(_transform_error)
         return d
 
     def _get_or_create_directories(self, node, path):
@@ -1011,6 +1014,7 @@ class PUTHandler(rend.Page):
         msg = "No files to upload! %s is empty" % localdir
         if not os.path.exists(localdir):
             msg = "%s doesn't exist!" % localdir
+            raise NoLocalDirectoryError(msg)
         for root, dirs, files in os.walk(localdir):
             if root == localdir:
                 path = ()