mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-04 12:14:11 +00:00
test_web: implement API changes from the recent webapi.txt overhaul
This commit is contained in:
parent
151f69d9b5
commit
b8c0217ad5
@ -474,17 +474,12 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
def test_GET_FILEURL_save(self):
|
def test_GET_FILEURL_save(self):
|
||||||
d = self.GET(self.public_url + "/foo/bar.txt?save=bar.txt")
|
d = self.GET(self.public_url + "/foo/bar.txt?filename=bar.txt&save=true")
|
||||||
# TODO: look at the headers, expect a Content-Disposition: attachment
|
# TODO: look at the headers, expect a Content-Disposition: attachment
|
||||||
# header.
|
# header.
|
||||||
d.addCallback(self.failUnlessIsBarDotTxt)
|
d.addCallback(self.failUnlessIsBarDotTxt)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_GET_FILEURL_download(self):
|
|
||||||
d = self.GET(self.public_url + "/foo/bar.txt?t=download")
|
|
||||||
d.addCallback(self.failUnlessIsBarDotTxt)
|
|
||||||
return d
|
|
||||||
|
|
||||||
def test_GET_FILEURL_missing(self):
|
def test_GET_FILEURL_missing(self):
|
||||||
d = self.GET(self.public_url + "/foo/missing")
|
d = self.GET(self.public_url + "/foo/missing")
|
||||||
d.addBoth(self.should404, "test_GET_FILEURL_missing")
|
d.addBoth(self.should404, "test_GET_FILEURL_missing")
|
||||||
@ -534,8 +529,8 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
d = self.PUT(self.public_url + "/foo/blockingfile/new.txt",
|
d = self.PUT(self.public_url + "/foo/blockingfile/new.txt",
|
||||||
self.NEWFILE_CONTENTS)
|
self.NEWFILE_CONTENTS)
|
||||||
d.addBoth(self.shouldFail, error.Error, "PUT_NEWFILEURL_blocked",
|
d.addBoth(self.shouldFail, error.Error, "PUT_NEWFILEURL_blocked",
|
||||||
"400 Bad Request",
|
"409 Conflict",
|
||||||
"cannot create directory because there is a file in the way")
|
"Unable to create directory 'blockingfile': a file was in the way")
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_DELETE_FILEURL(self):
|
def test_DELETE_FILEURL(self):
|
||||||
@ -702,20 +697,19 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
d.addCallback(self.failUnlessNodeKeysAre, [])
|
d.addCallback(self.failUnlessNodeKeysAre, [])
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_PUT_NEWDIRURL_replace(self):
|
def test_PUT_NEWDIRURL_exists(self):
|
||||||
d = self.PUT(self.public_url + "/foo/sub?t=mkdir", "")
|
d = self.PUT(self.public_url + "/foo/sub?t=mkdir", "")
|
||||||
d.addCallback(lambda res:
|
d.addCallback(lambda res:
|
||||||
self.failUnlessNodeHasChild(self._foo_node, u"sub"))
|
self.failUnlessNodeHasChild(self._foo_node, u"sub"))
|
||||||
d.addCallback(lambda res: self._foo_node.get(u"sub"))
|
d.addCallback(lambda res: self._foo_node.get(u"sub"))
|
||||||
d.addCallback(self.failUnlessNodeKeysAre, [])
|
d.addCallback(self.failUnlessNodeKeysAre, [u"baz.txt"])
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_PUT_NEWDIRURL_no_replace(self):
|
def test_PUT_NEWDIRURL_blocked(self):
|
||||||
d = self.PUT(self.public_url + "/foo/sub?t=mkdir&replace=false", "")
|
d = self.shouldFail2(error.Error, "PUT_NEWDIRURL_blocked",
|
||||||
d.addBoth(self.shouldFail, error.Error, "PUT_NEWDIRURL_no_replace",
|
"409 Conflict", "Unable to create directory 'bar.txt': a file was in the way",
|
||||||
"409 Conflict",
|
self.PUT,
|
||||||
"There was already a child by that name, and you asked me "
|
self.public_url + "/foo/bar.txt/sub?t=mkdir", "")
|
||||||
"to not replace it")
|
|
||||||
d.addCallback(lambda res:
|
d.addCallback(lambda res:
|
||||||
self.failUnlessNodeHasChild(self._foo_node, u"sub"))
|
self.failUnlessNodeHasChild(self._foo_node, u"sub"))
|
||||||
d.addCallback(lambda res: self._foo_node.get(u"sub"))
|
d.addCallback(lambda res: self._foo_node.get(u"sub"))
|
||||||
@ -954,18 +948,23 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
# test that clicking on the "overwrite" button works
|
# test that clicking on the "overwrite" button works
|
||||||
EVEN_NEWER_CONTENTS = NEWER_CONTENTS + "even newer\n"
|
EVEN_NEWER_CONTENTS = NEWER_CONTENTS + "even newer\n"
|
||||||
def _parse_overwrite_form_and_submit(res):
|
def _parse_overwrite_form_and_submit(res):
|
||||||
OVERWRITE_FORM_RE=re.compile('<form action="([^"]*)" method="post" .*<input type="hidden" name="t" value="overwrite" /><input type="hidden" name="name" value="([^"]*)" /><input type="hidden" name="when_done" value="([^"]*)" />', re.I)
|
|
||||||
mo = OVERWRITE_FORM_RE.search(res)
|
|
||||||
self.failUnless(mo)
|
|
||||||
formaction=mo.group(1)
|
|
||||||
formname=mo.group(2)
|
|
||||||
formwhendone=mo.group(3)
|
|
||||||
|
|
||||||
if formaction == ".":
|
OVERWRITE_FORM_RE=re.compile('<form action="([^"]*)" method="post" .*<input type="hidden" name="t" value="upload" /><input type="hidden" name="when_done" value="([^"]*)" />', re.I)
|
||||||
formaction = self.public_url + "/foo"
|
mo = OVERWRITE_FORM_RE.search(res)
|
||||||
return self.POST(formaction, t="overwrite", name=formname, when_done=formwhendone, file=("new.txt", EVEN_NEWER_CONTENTS), followRedirect=False)
|
self.failUnless(mo, "overwrite form not found in '" + res +
|
||||||
|
"', in which the overwrite form was not found")
|
||||||
|
formaction=mo.group(1)
|
||||||
|
formwhendone=mo.group(2)
|
||||||
|
|
||||||
|
fileurl = "/uri/" + urllib.quote(self._mutable_uri)
|
||||||
|
self.failUnless(formaction.startswith(fileurl), formaction)
|
||||||
|
return self.POST(formaction,
|
||||||
|
t="upload",
|
||||||
|
file=("new.txt", EVEN_NEWER_CONTENTS),
|
||||||
|
when_done=formwhendone,
|
||||||
|
followRedirect=False)
|
||||||
d.addCallback(_parse_overwrite_form_and_submit)
|
d.addCallback(_parse_overwrite_form_and_submit)
|
||||||
d.addBoth(self.shouldRedirect, urllib.quote(self.public_url + "/foo/"))
|
d.addBoth(self.shouldRedirect, urllib.quote(self.public_url + "/foo"))
|
||||||
d.addCallback(lambda res:
|
d.addCallback(lambda res:
|
||||||
self.failUnlessMutableChildContentsAre(fn, u"new.txt",
|
self.failUnlessMutableChildContentsAre(fn, u"new.txt",
|
||||||
EVEN_NEWER_CONTENTS))
|
EVEN_NEWER_CONTENTS))
|
||||||
@ -1076,6 +1075,23 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
d.addCallback(self.failUnlessNodeKeysAre, [])
|
d.addCallback(self.failUnlessNodeKeysAre, [])
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def test_POST_mkdir_2(self):
|
||||||
|
d = self.POST(self.public_url + "/foo/newdir?t=mkdir", "")
|
||||||
|
d.addCallback(lambda res:
|
||||||
|
self.failUnlessNodeHasChild(self._foo_node, u"newdir"))
|
||||||
|
d.addCallback(lambda res: self._foo_node.get(u"newdir"))
|
||||||
|
d.addCallback(self.failUnlessNodeKeysAre, [])
|
||||||
|
return d
|
||||||
|
|
||||||
|
def test_POST_mkdirs_2(self):
|
||||||
|
d = self.POST(self.public_url + "/foo/bardir/newdir?t=mkdir", "")
|
||||||
|
d.addCallback(lambda res:
|
||||||
|
self.failUnlessNodeHasChild(self._foo_node, u"bardir"))
|
||||||
|
d.addCallback(lambda res: self._foo_node.get(u"bardir"))
|
||||||
|
d.addCallback(lambda bardirnode: bardirnode.get(u"newdir"))
|
||||||
|
d.addCallback(self.failUnlessNodeKeysAre, [])
|
||||||
|
return d
|
||||||
|
|
||||||
def test_POST_mkdir_no_parentdir_noredirect(self):
|
def test_POST_mkdir_no_parentdir_noredirect(self):
|
||||||
d = self.POST("/uri?t=mkdir")
|
d = self.POST("/uri?t=mkdir")
|
||||||
def _after_mkdir(res):
|
def _after_mkdir(res):
|
||||||
@ -1164,7 +1180,7 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
|
|
||||||
def test_POST_bad_t(self):
|
def test_POST_bad_t(self):
|
||||||
d = self.shouldFail2(error.Error, "POST_bad_t", "400 Bad Request",
|
d = self.shouldFail2(error.Error, "POST_bad_t", "400 Bad Request",
|
||||||
"BAD t=BOGUS",
|
"POST to a directory with bad t=BOGUS",
|
||||||
self.POST, self.public_url + "/foo", t="BOGUS")
|
self.POST, self.public_url + "/foo", t="BOGUS")
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@ -1482,7 +1498,7 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
d.addBoth(self.shouldFail, error.Error,
|
d.addBoth(self.shouldFail, error.Error,
|
||||||
"PUT_NEWFILE_URI_only_PUT",
|
"PUT_NEWFILE_URI_only_PUT",
|
||||||
"400 Bad Request",
|
"400 Bad Request",
|
||||||
"/uri only accepts PUT and PUT?t=mkdir")
|
"/uri accepts only PUT, PUT?t=mkdir, POST?t=upload, and POST?t=mkdir")
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_PUT_NEWFILE_URI_mutable(self):
|
def test_PUT_NEWFILE_URI_mutable(self):
|
||||||
@ -1538,12 +1554,15 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
|
|
||||||
def test_bad_method(self):
|
def test_bad_method(self):
|
||||||
url = self.webish_url + self.public_url + "/foo/bar.txt"
|
url = self.webish_url + self.public_url + "/foo/bar.txt"
|
||||||
d = self.shouldHTTPError2("test_bad_method", 404, "Not Found", None,
|
d = self.shouldHTTPError2("test_bad_method",
|
||||||
|
501, "Not Implemented",
|
||||||
|
"I don't know how to treat a BOGUS request.",
|
||||||
client.getPage, url, method="BOGUS")
|
client.getPage, url, method="BOGUS")
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_short_url(self):
|
def test_short_url(self):
|
||||||
url = self.webish_url + "/uri"
|
url = self.webish_url + "/uri"
|
||||||
d = self.shouldHTTPError2("test_short_url", 404, "Not Found", None,
|
d = self.shouldHTTPError2("test_short_url", 501, "Not Implemented",
|
||||||
|
"I don't know how to treat a DELETE request.",
|
||||||
client.getPage, url, method="DELETE")
|
client.getPage, url, method="DELETE")
|
||||||
return d
|
return d
|
||||||
|
Loading…
Reference in New Issue
Block a user