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
|
return d
|
||||||
|
|
||||||
def test_PUT_NEWDIRURL_localdir_missing(self):
|
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")
|
localdir = os.path.abspath("web/PUT_NEWDIRURL_localdir_missing")
|
||||||
# we do *not* create it, to trigger an error
|
# we do *not* create it, to trigger an error
|
||||||
url = (self.public_url + "/foo/subdir/newdir?t=upload&localdir=%s"
|
url = (self.public_url + "/foo/subdir/newdir?t=upload&localdir=%s"
|
||||||
% urllib.quote(localdir))
|
% urllib.quote(localdir))
|
||||||
d = self.shouldHTTPError2("test_PUT_NEWDIRURL_localdir_missing",
|
d = self.shouldHTTPError2("test_PUT_NEWDIRURL_localdir_missing",
|
||||||
400, "Bad Request", "random",
|
400, "Bad Request",
|
||||||
|
"%s doesn't exist!" % localdir,
|
||||||
self.PUT, url, "")
|
self.PUT, url, "")
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
|
@ -472,6 +472,8 @@ class BlockingFileError(Exception):
|
||||||
the way"""
|
the way"""
|
||||||
class NoReplacementError(Exception):
|
class NoReplacementError(Exception):
|
||||||
"""There was already a child by that name, and you asked me to not replace it"""
|
"""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"
|
LOCALHOST = "127.0.0.1"
|
||||||
|
|
||||||
|
@ -931,18 +933,19 @@ class PUTHandler(rend.Page):
|
||||||
d.addCallback(self._mkdir, name)
|
d.addCallback(self._mkdir, name)
|
||||||
else:
|
else:
|
||||||
d.addCallback(self._upload_file, req.content, name)
|
d.addCallback(self._upload_file, req.content, name)
|
||||||
def _check_blocking(f):
|
|
||||||
f.trap(BlockingFileError)
|
def _transform_error(f):
|
||||||
req.setResponseCode(http.BAD_REQUEST)
|
errors = {BlockingFileError: http.BAD_REQUEST,
|
||||||
req.setHeader("content-type", "text/plain")
|
NoReplacementError: http.CONFLICT,
|
||||||
return str(f.value)
|
NoLocalDirectoryError: http.BAD_REQUEST,
|
||||||
d.addErrback(_check_blocking)
|
}
|
||||||
def _check_replacement(f):
|
for k,v in errors.items():
|
||||||
f.trap(NoReplacementError)
|
if f.check(k):
|
||||||
req.setResponseCode(http.CONFLICT)
|
req.setResponseCode(v)
|
||||||
req.setHeader("content-type", "text/plain")
|
req.setHeader("content-type", "text/plain")
|
||||||
return str(f.value)
|
return str(f.value)
|
||||||
d.addErrback(_check_replacement)
|
return f
|
||||||
|
d.addErrback(_transform_error)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _get_or_create_directories(self, node, path):
|
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
|
msg = "No files to upload! %s is empty" % localdir
|
||||||
if not os.path.exists(localdir):
|
if not os.path.exists(localdir):
|
||||||
msg = "%s doesn't exist!" % localdir
|
msg = "%s doesn't exist!" % localdir
|
||||||
|
raise NoLocalDirectoryError(msg)
|
||||||
for root, dirs, files in os.walk(localdir):
|
for root, dirs, files in os.walk(localdir):
|
||||||
if root == localdir:
|
if root == localdir:
|
||||||
path = ()
|
path = ()
|
||||||
|
|
Loading…
Reference in New Issue