From: Brian Warner Date: Tue, 20 May 2008 06:28:52 +0000 (-0700) Subject: test_web/test_system: improve test coverage X-Git-Tag: allmydata-tahoe-1.1.0~106 X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/frontends/%22doc.html/?a=commitdiff_plain;h=88457fbc327c180b53f5ac813d51cc5cf82c8821;p=tahoe-lafs%2Ftahoe-lafs.git test_web/test_system: improve test coverage --- diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 0d7d5873..50662db3 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -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") diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index a76f7151..b97fdf29 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -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