]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
web: even more test coverage
authorBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 18:33:14 +0000 (11:33 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 18:33:14 +0000 (11:33 -0700)
src/allmydata/test/test_web.py
src/allmydata/web/filenode.py

index a78b339e8bafeaf3b122b5c79241832b34b0f056..a07457b8cce165ebab81372ba5e3a9710b7c5ef2 100644 (file)
@@ -521,6 +521,28 @@ class Web(WebMixin, unittest.TestCase):
                              self.GET, base)
         return d
 
+    def test_GET_FILE_URI(self):
+        base = "/uri/%s" % urllib.quote(self._bar_txt_uri)
+        d = self.GET(base)
+        d.addCallback(self.failUnlessIsBarDotTxt)
+        return d
+
+    def test_GET_FILE_URI_badchild(self):
+        base = "/uri/%s/boguschild" % urllib.quote(self._bar_txt_uri)
+        errmsg = "Files have no children, certainly not named 'boguschild'"
+        d = self.shouldFail2(error.Error, "test_GET_FILE_URI_badchild",
+                             "400 Bad Request", errmsg,
+                             self.GET, base)
+        return d
+
+    def test_PUT_FILE_URI_badchild(self):
+        base = "/uri/%s/boguschild" % urllib.quote(self._bar_txt_uri)
+        errmsg = "Cannot create directory 'boguschild', because its parent is a file, not a directory"
+        d = self.shouldFail2(error.Error, "test_GET_FILE_URI_badchild",
+                             "400 Bad Request", errmsg,
+                             self.PUT, 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
@@ -1092,6 +1114,17 @@ class Web(WebMixin, unittest.TestCase):
             self.failUnlessEqual(new_json[1]["ro_uri"], ro_uri)
         d.addCallback(_check_page_json)
 
+        # and look at t=uri and t=readonly-uri
+        d.addCallback(lambda res:
+                      self.GET(self.public_url + "/foo/new.txt?t=uri"))
+        d.addCallback(lambda res: self.failUnlessEqual(res, self._mutable_uri))
+        d.addCallback(lambda res:
+                      self.GET(self.public_url + "/foo/new.txt?t=readonly-uri"))
+        def _check_ro_uri(res):
+            ro_uri = unicode(self._mutable_node.get_readonly().to_string())
+            self.failUnlessEqual(res, ro_uri)
+        d.addCallback(_check_ro_uri)
+
         d.addErrback(self.dump_error)
         return d
 
@@ -1185,6 +1218,22 @@ class Web(WebMixin, unittest.TestCase):
                                                   u"sub"]))
         return d
 
+    def test_POST_FILEURL_check(self):
+        d = self.POST(self.public_url + "/foo/bar.txt", t="check")
+        def _check(res):
+            # this currently just returns "None". You'd only really use it
+            # with a when_done= redirect.
+            self.failUnlessEqual(res, "None")
+        d.addCallback(_check)
+        return d
+
+    def test_POST_FILEURL_bad_t(self):
+        d = self.shouldFail2(error.Error, "POST_bad_t", "400 Bad Request",
+                             "POST to file: bad t=bogus",
+                             self.POST, self.public_url + "/foo/bar.txt",
+                             t="bogus")
+        return d
+
     def test_POST_mkdir(self): # return value?
         d = self.POST(self.public_url + "/foo", t="mkdir", name="newdir")
         d.addCallback(lambda res: self._foo_node.get(u"newdir"))
index 6d09e13e4da895dec3e7fdd93fb4fa92276d77db..751e097b2416909c054f57c928e3bd8fcecd661e 100644 (file)
@@ -368,7 +368,7 @@ def FileURI(ctx, filenode):
 def FileReadOnlyURI(ctx, filenode):
     if filenode.is_readonly():
         return text_plain(filenode.get_uri(), ctx)
-    return text_plain(filenode.get_readonly().get_uri(), ctx)
+    return text_plain(filenode.get_readonly_uri(), ctx)
 
 class FileNodeDownloadHandler(FileNodeHandler):
     def childFactory(self, ctx, name):