]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_web/test_system: improve test coverage
authorBrian Warner <warner@lothar.com>
Tue, 20 May 2008 06:28:52 +0000 (23:28 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 20 May 2008 06:28:52 +0000 (23:28 -0700)
src/allmydata/test/test_system.py
src/allmydata/test/test_web.py

index 0d7d587344cf024dafab1198c4fa598e91218c3b..50662db36d98a4564b23ce0f7818b6845282e0a2 100644 (file)
@@ -137,6 +137,7 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, testutil.StallMixin,
                 # client[0] runs a webserver and a helper, no key_generator
                 open(os.path.join(basedir, "webport"), "w").write("tcp:0:interface=127.0.0.1")
                 open(os.path.join(basedir, "run_helper"), "w").write("yes\n")
+                open(os.path.join(basedir, "sizelimit"), "w").write("10GB\n")
             if i == 3:
                 # client[3] runs a webserver and uses a helper, uses key_generator
                 open(os.path.join(basedir, "webport"), "w").write("tcp:0:interface=127.0.0.1")
index a76f71515b917397427f98df36b7acacc264c650..b97fdf29ea9dfb9ca72c3b89d54169884ac54653 100644 (file)
@@ -473,6 +473,29 @@ class Web(WebMixin, unittest.TestCase):
         d.addCallback(self.failUnlessIsBarDotTxt)
         return d
 
+    def test_PUT_FILEURL_named_bad(self):
+        base = "/file/%s" % urllib.quote(self._bar_txt_uri)
+        d = self.shouldFail2(error.Error, "test_PUT_FILEURL_named_bad",
+                             "400 Bad Request",
+                             "/file can only be used with GET or HEAD",
+                             self.PUT, base + "/@@name=/blah.txt", "")
+        return d
+
+    def test_GET_DIRURL_named_bad(self):
+        base = "/file/%s" % urllib.quote(self._foo_uri)
+        d = self.shouldFail2(error.Error, "test_PUT_DIRURL_named_bad",
+                             "400 Bad Request",
+                             "is not a file-cap",
+                             self.GET, base + "/@@name=/blah.txt")
+        return d
+
+    def test_GET_slash_file_bad(self):
+        d = self.shouldFail2(error.Error, "test_GET_slash_file_bad",
+                             "404 Not Found",
+                             "/file must be followed by a file-cap and a name",
+                             self.GET, "/file")
+        return d
+
     def test_GET_unhandled_URI_named(self):
         contents, n, newuri = self.makefile(12)
         verifier_cap = n.get_verifier().to_string()
@@ -484,6 +507,17 @@ class Web(WebMixin, unittest.TestCase):
                              self.GET, base)
         return d
 
+    def test_GET_unhandled_URI(self):
+        contents, n, newuri = self.makefile(12)
+        verifier_cap = n.get_verifier().to_string()
+        base = "/uri/%s" % urllib.quote(verifier_cap)
+        # client.create_node_from_uri() can't handle verify-caps
+        d = self.shouldFail2(error.Error, "test_GET_unhandled_URI",
+                             "400 Bad Request",
+                             "is not a valid file- or directory- cap",
+                             self.GET, base)
+        return d
+
     def test_GET_FILEURL_save(self):
         d = self.GET(self.public_url + "/foo/bar.txt?filename=bar.txt&save=true")
         # TODO: look at the headers, expect a Content-Disposition: attachment
@@ -899,6 +933,33 @@ class Web(WebMixin, unittest.TestCase):
         d.addBoth(self.shouldRedirect, "/")
         return d
 
+    def shouldRedirect2(self, which, checker, callable, *args, **kwargs):
+        d = defer.maybeDeferred(callable, *args, **kwargs)
+        def done(res):
+            if isinstance(res, failure.Failure):
+                res.trap(error.PageRedirect)
+                statuscode = res.value.status
+                target = res.value.location
+                return checker(statuscode, target)
+            self.fail("%s: callable was supposed to redirect, not return '%s'"
+                      % (which, res))
+        d.addBoth(done)
+        return d
+
+    def test_POST_upload_no_link_whendone_results(self):
+        def check(statuscode, target):
+            self.failUnlessEqual(statuscode, str(http.FOUND))
+            self.failUnless(target.startswith(self.webish_url), target)
+            return client.getPage(target, method="GET")
+        d = self.shouldRedirect2("test_POST_upload_no_link_whendone_results",
+                                 check,
+                                 self.POST, "/uri", t="upload",
+                                 when_done="/uri/%(uri)s",
+                                 file=("new.txt", self.NEWFILE_CONTENTS))
+        d.addCallback(lambda res:
+                      self.failUnlessEqual(res, self.NEWFILE_CONTENTS))
+        return d
+
     def test_POST_upload_no_link_mutable(self):
         d = self.POST("/uri", t="upload", mutable="true",
                       file=("new.txt", self.NEWFILE_CONTENTS))
@@ -1463,6 +1524,12 @@ class Web(WebMixin, unittest.TestCase):
 
         return d
 
+    def test_GET_URI_form_bad(self):
+        d = self.shouldFail2(error.Error, "test_GET_URI_form_bad",
+                             "400 Bad Request", "GET /uri requires uri=",
+                             self.GET, "/uri")
+        return d
+
     def test_GET_rename_form(self):
         d = self.GET(self.public_url + "/foo?t=rename-form&name=bar.txt",
                      followRedirect=True) # XXX [ ] todo: figure out why '.../foo' doesn't work