From ae900168457f251a52f99ebd4c3df4ad70f5f728 Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx Date: Fri, 14 Dec 2007 17:52:05 -0700 Subject: [PATCH] fix the overwrite button and add unit test for it --- src/allmydata/test/test_web.py | 49 ++++++++++++++++++++-------------- src/allmydata/webish.py | 3 ++- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 5a677157..45163c04 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -169,7 +169,7 @@ class WebMixin(object): url = self.webish_url + urlpath return client.getPage(url, method="DELETE") - def POST(self, urlpath, **fields): + def POST(self, urlpath, followRedirect=False, **fields): url = self.webish_url + urlpath sepbase = "boogabooga" sep = "--" + sepbase @@ -194,7 +194,7 @@ class WebMixin(object): headers = {"content-type": "multipart/form-data; boundary=%s" % sepbase, } return client.getPage(url, method="POST", postdata=body, - headers=headers, followRedirect=False) + headers=headers, followRedirect=followRedirect) def shouldFail(self, res, expected_failure, which, substring=None, response_substring=None): @@ -955,24 +955,6 @@ class Web(WebMixin, unittest.TestCase): self.failUnlessEqual(self._mutable_uri, newnode.get_uri()) d.addCallback(_got2) - # also test t=overwrite while we're here - EVEN_NEWER_CONTENTS = NEWER_CONTENTS + "even newer\n" - d.addCallback(lambda res: - self.POST(self.public_url + "/foo/new.txt", - t="overwrite", - file=("new.txt", EVEN_NEWER_CONTENTS))) - d.addCallback(self.failUnlessURIMatchesChild, fn, "new.txt") - d.addCallback(lambda res: - self.failUnlessChildContentsAre(fn, "new.txt", - EVEN_NEWER_CONTENTS)) - d.addCallback(lambda res: self._foo_node.get("new.txt")) - def _got3(newnode): - self.failUnless(IMutableFileNode.providedBy(newnode)) - self.failUnless(newnode.is_mutable()) - self.failIf(newnode.is_readonly()) - self.failUnlessEqual(self._mutable_uri, newnode.get_uri()) - d.addCallback(_got3) - # finally list the directory, since mutable files are displayed # differently @@ -983,8 +965,35 @@ class Web(WebMixin, unittest.TestCase): # TODO: assert more about the contents self.failUnless("Overwrite" in res) self.failUnless("Choose new file:" in res) + return res d.addCallback(_check_page) + # test that clicking on the "overwrite" button works + EVEN_NEWER_CONTENTS = NEWER_CONTENTS + "even newer\n" + OVERWRITE_FORM_RE=re.compile('
OverwriteChoose new file:
', re.I) + def _parse_overwrite_form_and_submit(res): + mo = OVERWRITE_FORM_RE.search(res) + self.failUnless(mo) + formaction=mo.group(1) + formname=mo.group(2) + formwhendone=mo.group(3) + + if formaction == ".": + formaction = self.public_url + "/foo" + return self.POST(formaction, t="overwrite", name=formname, when_done=formwhendone, file=("new.txt", EVEN_NEWER_CONTENTS), followRedirect=False) + d.addCallback(_parse_overwrite_form_and_submit) + d.addBoth(self.shouldRedirect, urllib.quote(self.public_url + "/foo/")) + d.addCallback(lambda res: + self.failUnlessChildContentsAre(fn, "new.txt", + EVEN_NEWER_CONTENTS)) + d.addCallback(lambda res: self._foo_node.get("new.txt")) + def _got3(newnode): + self.failUnless(IMutableFileNode.providedBy(newnode)) + self.failUnless(newnode.is_mutable()) + self.failIf(newnode.is_readonly()) + self.failUnlessEqual(self._mutable_uri, newnode.get_uri()) + d.addCallback(_got3) + return d def test_POST_upload_replace(self): diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 88a6c266..dfa28a53 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -336,7 +336,8 @@ class Directory(rend.Page): def build_overwrite(self, ctx, data): name, target = data if IMutableFileNode.providedBy(target) and not target.is_readonly(): - overwrite = T.form(action=".", method="post", + action="/uri/" + urllib.quote(target.get_uri()) + overwrite = T.form(action=action, method="post", enctype="multipart/form-data")[ T.fieldset[ T.input(type="hidden", name="t", value="overwrite"), -- 2.45.2