webish: test error cases more thoroughly by looking inside the response text

This commit is contained in:
Brian Warner 2007-07-16 12:01:19 -07:00
parent 3f294d5597
commit 56dcb814a8
2 changed files with 12 additions and 6 deletions

View File

@ -387,7 +387,8 @@ class Web(unittest.TestCase):
d = self.PUT("/vdrive/global/foo/blockingfile/new.txt",
self.NEWFILE_CONTENTS)
d.addBoth(self.shouldFail, error.Error, "PUT_NEWFILEURL_blocked",
"403 Forbidden")
"400 Bad Request",
"cannot create directory because there is a file in the way")
return d
def test_DELETE_FILEURL(self): # YES
@ -444,7 +445,8 @@ class Web(unittest.TestCase):
d = self.GET("/vdrive/global/foo/bar.txt?t=download&localfile=%s"
% localfile)
d.addBoth(self.shouldFail, error.Error, "localfile non-local",
"403 Forbidden")
"403 Forbidden",
"localfile= or localdir= requires a local connection")
def _check(res):
self.failIf(os.path.exists(localfile))
d.addCallback(_check)
@ -460,7 +462,8 @@ class Web(unittest.TestCase):
d = self.GET("/vdrive/global/foo/bar.txt?t=download&localfile=%s"
% localfile)
d.addBoth(self.shouldFail, error.Error, "localfile non-absolute",
"403 Forbidden")
"403 Forbidden",
"localfile= or localdir= requires an absolute path")
def _check(res):
self.failIf(os.path.exists(localfile))
d.addCallback(_check)

View File

@ -626,15 +626,18 @@ class PUTHandler(rend.Page):
d.addCallback(self._upload_file, req.content, name)
def _check_blocking(f):
f.trap(BlockingFileError)
req.setResponseCode(http.FORBIDDEN)
req.setResponseCode(http.BAD_REQUEST)
req.setHeader("content-type", "text/plain")
return str(f)
return str(f.value)
d.addErrback(_check_blocking)
return d
def _get_or_create_directories(self, node, path):
if not IDirectoryNode.providedBy(node):
raise BlockingFileError
# unfortunately it is too late to provide the name of the
# blocking directory in the error message.
raise BlockingFileError("cannot create directory because there "
"is a file in the way")
if not path:
return defer.succeed(node)
d = node.get(path[0])