webish: add button to make directories and unit test of it
authorZooko O'Whielacronx <zooko@zooko.com>
Thu, 20 Dec 2007 22:31:12 +0000 (15:31 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Thu, 20 Dec 2007 22:31:12 +0000 (15:31 -0700)
Unfortunately although it passes the unit tests, it doesn't work, because the unit tests and the implementation use the "encode params into URL" technique but the button uses the "encode params into request body" technique.

src/allmydata/test/test_web.py
src/allmydata/web/welcome.xhtml
src/allmydata/webish.py

index 1c96c8d397699b5f01e811db8e24734b764d9c1e..8cf6e64838c10e6be6d65bda5840e349a8e0651a 100644 (file)
@@ -1114,6 +1114,25 @@ class Web(WebMixin, unittest.TestCase):
         d.addBoth(self.shouldRedirect, None, statuscode='303')
         return d
 
+    def test_welcome_page_mkdir_button(self):
+        # Fetch the welcome page.
+        d = self.GET("/")
+        def _after_get_welcome_page(res):
+            MKDIR_BUTTON_RE=re.compile('<form action="([^"]*)" method="post".*<input type="hidden" name="t" value="([^"]*)" /><input type="hidden" name="([^"]*)" value="([^"]*)" /><input type="submit" value="create" />', re.I)
+            mo = MKDIR_BUTTON_RE.search(res)
+            formaction = mo.group(1)
+            formt = mo.group(2)
+            formaname = mo.group(3)
+            formavalue = mo.group(4)
+            return (formaction, formt, formaname, formavalue)
+        d.addCallback(_after_get_welcome_page)
+        def _after_parse_form(res):
+            (formaction, formt, formaname, formavalue) = res
+            return self.POST("/%s?t=%s&%s=%s" % (formaction, formt, formaname, formavalue))
+        d.addCallback(_after_parse_form)
+        d.addBoth(self.shouldRedirect, None, statuscode='303')
+        return d
+
     def test_POST_mkdir_replace(self): # return value?
         d = self.POST(self.public_url + "/foo", t="mkdir", name="sub")
         d.addCallback(lambda res: self._foo_node.get("sub"))
index 300f598ddb99daeed75b8979217ce682eaf33bea..bc0deee76bccaa5cd0b9fb166ba54e71b27be9a8 100644 (file)
@@ -37,6 +37,7 @@ tool</a> may also be useful.</div>
 </div>
 
 <div n:render="download_form"/>
+<div n:render="mkdir_form"/>
 
   </body>
 </html>
index 91539c8b357e0e22d02a900a6ae2ee550b96c9e5..46605df0970e74b8c9f919aaaaccb09ffbcd6252 100644 (file)
@@ -1237,7 +1237,7 @@ class URIPOSTHandler(rend.Page):
             return d
 
         if t == "mkdir":
-            # "PUT /uri?t=mkdir", to create an unlinked directory.
+            # "POST /uri?t=mkdir", to create an unlinked directory.
             d = IClient(ctx).create_empty_dirnode()
             redirect = req.args.has_key("redirect_to_result") and boolean_of_arg(req.args["redirect_to_result"][0])
             if redirect:
@@ -1352,17 +1352,28 @@ class Root(rend.Page):
         return T.p["personal vdrive not available."]
 
     # this is a form where users can download files by URI
-
     def render_download_form(self, ctx, data):
         form = T.form(action="uri", method="get",
                       enctype="multipart/form-data")[
             T.fieldset[
-            T.legend(class_="freeform-form-label")["Download a file"],
+            T.legend(class_="freeform-form-label")["download a file"],
             "URI of file to download: ",
             T.input(type="text", name="uri"), " ",
             "Filename to download as: ",
             T.input(type="text", name="filename"), " ",
-            T.input(type="submit", value="Download"),
+            T.input(type="submit", value="download"),
+            ]]
+        return T.div[form]
+
+    # this is a form where users can create new directories
+    def render_mkdir_form(self, ctx, data):
+        form = T.form(action="uri", method="post",
+                      enctype="multipart/form-data")[
+            T.fieldset[
+            T.legend(class_="freeform-form-label")["create a directory"],
+            T.input(type="hidden", name="t", value="mkdir"),
+            T.input(type="hidden", name="redirect_to_result", value="true"),
+            T.input(type="submit", value="create"),
             ]]
         return T.div[form]