From 4ba1af37a678414b159a511d899a3859a34b94f9 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 24 Dec 2007 22:49:35 -0700 Subject: [PATCH] test_web: more coverage of URIPOSTHandler error cases --- src/allmydata/test/test_web.py | 35 ++++++++++++++++++++++++++++++++++ src/allmydata/webish.py | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 9d2590cb..f6345d99 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -212,6 +212,23 @@ class WebMixin(object): self.fail("%s was supposed to raise %s, not get '%s'" % (which, expected_failure, res)) + def shouldFail2(self, expected_failure, which, substring, + callable, *args, **kwargs): + assert substring is None or isinstance(substring, str) + d = defer.maybeDeferred(callable, *args, **kwargs) + def done(res): + if isinstance(res, Failure): + res.trap(expected_failure) + if substring: + self.failUnless(substring in str(res), + "substring '%s' not in '%s'" + % (substring, str(res))) + else: + self.fail("%s was supposed to raise %s, not get '%s'" % + (which, expected_failure, res)) + d.addBoth(done) + return d + def should404(self, res, which): if isinstance(res, failure.Failure): res.trap(error.Error) @@ -238,6 +255,17 @@ class WebMixin(object): self.fail("%s was supposed to Error(%s), not get '%s'" % (which, code, res)) + def shouldHTTPError2(self, which, + code=None, substring=None, response_substring=None, + callable=None, *args, **kwargs): + assert substring is None or isinstance(substring, str) + assert callable + d = defer.maybeDeferred(callable, *args, **kwargs) + d.addBoth(self.shouldHTTPError, which, + code, substring, response_substring) + return d + + class Web(WebMixin, unittest.TestCase): def test_create(self): pass @@ -1118,6 +1146,13 @@ class Web(WebMixin, unittest.TestCase): d.addCallback(_check_target) return d + def test_POST_noparent_bad(self): + d = self.shouldHTTPError2("POST /uri?t=bogus", 400, "Bad Request", + "/uri accepts only PUT, PUT?t=mkdir, " + "POST?t=upload, and POST?t=mkdir", + self.POST, "/uri?t=bogus") + return d + def test_welcome_page_mkdir_button(self): # Fetch the welcome page. d = self.GET("/") diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index b795b071..c1e97fc0 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -1270,7 +1270,8 @@ class URIPOSTHandler(rend.Page): req.setResponseCode(http.BAD_REQUEST) req.setHeader("content-type", "text/plain") - return "/uri accepts only PUT, PUT?t=mkdir, POST?t=upload" # XXX check this -- what about POST?t=mkdir? + err = "/uri accepts only PUT, PUT?t=mkdir, POST?t=upload, and POST?t=mkdir" + return err class Root(rend.Page): -- 2.45.2