webish: upload+localdir=missing should give an error
This commit is contained in:
parent
3b41c939f8
commit
4c5518faef
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
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)
|
||||
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)
|
||||
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 = ()
|
||||
|
|
Loading…
Reference in New Issue