fix the overwrite button and add unit test for it
This commit is contained in:
parent
cd59cded91
commit
ae90016845
|
@ -169,7 +169,7 @@ class WebMixin(object):
|
||||||
url = self.webish_url + urlpath
|
url = self.webish_url + urlpath
|
||||||
return client.getPage(url, method="DELETE")
|
return client.getPage(url, method="DELETE")
|
||||||
|
|
||||||
def POST(self, urlpath, **fields):
|
def POST(self, urlpath, followRedirect=False, **fields):
|
||||||
url = self.webish_url + urlpath
|
url = self.webish_url + urlpath
|
||||||
sepbase = "boogabooga"
|
sepbase = "boogabooga"
|
||||||
sep = "--" + sepbase
|
sep = "--" + sepbase
|
||||||
|
@ -194,7 +194,7 @@ class WebMixin(object):
|
||||||
headers = {"content-type": "multipart/form-data; boundary=%s" % sepbase,
|
headers = {"content-type": "multipart/form-data; boundary=%s" % sepbase,
|
||||||
}
|
}
|
||||||
return client.getPage(url, method="POST", postdata=body,
|
return client.getPage(url, method="POST", postdata=body,
|
||||||
headers=headers, followRedirect=False)
|
headers=headers, followRedirect=followRedirect)
|
||||||
|
|
||||||
def shouldFail(self, res, expected_failure, which,
|
def shouldFail(self, res, expected_failure, which,
|
||||||
substring=None, response_substring=None):
|
substring=None, response_substring=None):
|
||||||
|
@ -955,24 +955,6 @@ class Web(WebMixin, unittest.TestCase):
|
||||||
self.failUnlessEqual(self._mutable_uri, newnode.get_uri())
|
self.failUnlessEqual(self._mutable_uri, newnode.get_uri())
|
||||||
d.addCallback(_got2)
|
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
|
# finally list the directory, since mutable files are displayed
|
||||||
# differently
|
# differently
|
||||||
|
|
||||||
|
@ -983,8 +965,35 @@ class Web(WebMixin, unittest.TestCase):
|
||||||
# TODO: assert more about the contents
|
# TODO: assert more about the contents
|
||||||
self.failUnless("Overwrite" in res)
|
self.failUnless("Overwrite" in res)
|
||||||
self.failUnless("Choose new file:" in res)
|
self.failUnless("Choose new file:" in res)
|
||||||
|
return res
|
||||||
d.addCallback(_check_page)
|
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('<form action="(.*)" method="post" enctype="multipart/form-data"><fieldset><input type="hidden" name="t" value="overwrite" /><input type="hidden" name="name" value="(.*)" /><input type="hidden" name="when_done" value="(.*)" /><legend class="freeform-form-label">Overwrite</legend>Choose new file: <input type="file" class="freeform-input-file" name="file" /> <input type="submit" value="Overwrite" /></fieldset></form>', 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
|
return d
|
||||||
|
|
||||||
def test_POST_upload_replace(self):
|
def test_POST_upload_replace(self):
|
||||||
|
|
|
@ -336,7 +336,8 @@ class Directory(rend.Page):
|
||||||
def build_overwrite(self, ctx, data):
|
def build_overwrite(self, ctx, data):
|
||||||
name, target = data
|
name, target = data
|
||||||
if IMutableFileNode.providedBy(target) and not target.is_readonly():
|
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")[
|
enctype="multipart/form-data")[
|
||||||
T.fieldset[
|
T.fieldset[
|
||||||
T.input(type="hidden", name="t", value="overwrite"),
|
T.input(type="hidden", name="t", value="overwrite"),
|
||||||
|
|
Loading…
Reference in New Issue