]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_web: more coverage of URIPOSTHandler error cases
authorBrian Warner <warner@lothar.com>
Tue, 25 Dec 2007 05:49:35 +0000 (22:49 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 25 Dec 2007 05:49:35 +0000 (22:49 -0700)
src/allmydata/test/test_web.py
src/allmydata/webish.py

index 9d2590cb2a865b95a03dd9c0bdf9dee0fe0bc692..f6345d99a88e33216780770af19bee55fe3d75dc 100644 (file)
@@ -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("/")
index b795b071df9f8c38954ff96e885f7c5d393ad738..c1e97fc0b503ea40b805cdcdb6ee4f5db9aacfd9 100644 (file)
@@ -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):