webish: add button to make directories and unit test of it

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.
This commit is contained in:
Zooko O'Whielacronx 2007-12-20 15:31:12 -07:00
parent a7361179aa
commit a85a4d71f7
3 changed files with 35 additions and 4 deletions

View 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"))

View 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>

View 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]