mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 15:16:41 +00:00
test_web: use inlineCallbacks in many functions
specifically everywhere we use self.shouldRedirect2
This commit is contained in:
parent
73d09082d7
commit
4745239c2c
@ -2501,20 +2501,19 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
|||||||
d.addBoth(done)
|
d.addBoth(done)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
def test_POST_upload_no_link_whendone_results(self):
|
def test_POST_upload_no_link_whendone_results(self):
|
||||||
def check(statuscode, target):
|
def check(statuscode, target):
|
||||||
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
||||||
self.failUnless(target.startswith(self.webish_url), target)
|
self.failUnless(target.startswith(self.webish_url), target)
|
||||||
return client.getPage(target, method="GET")
|
return client.getPage(target, method="GET")
|
||||||
# We encode "uri" as "%75ri" to exercise a case affected by ticket #1860.
|
# We encode "uri" as "%75ri" to exercise a case affected by ticket #1860.
|
||||||
d = self.shouldRedirect2("test_POST_upload_no_link_whendone_results",
|
res = yield self.shouldRedirect2("test_POST_upload_no_link_whendone_results",
|
||||||
check,
|
check,
|
||||||
self.POST, "/uri", t="upload",
|
self.POST, "/uri", t="upload",
|
||||||
when_done="/%75ri/%(uri)s",
|
when_done="/%75ri/%(uri)s",
|
||||||
file=("new.txt", self.NEWFILE_CONTENTS))
|
file=("new.txt", self.NEWFILE_CONTENTS))
|
||||||
d.addCallback(lambda res:
|
self.failUnlessReallyEqual(res, self.NEWFILE_CONTENTS)
|
||||||
self.failUnlessReallyEqual(res, self.NEWFILE_CONTENTS))
|
|
||||||
return d
|
|
||||||
|
|
||||||
def test_POST_upload_no_link_mutable(self):
|
def test_POST_upload_no_link_mutable(self):
|
||||||
d = self.POST("/uri", t="upload", mutable="true",
|
d = self.POST("/uri", t="upload", mutable="true",
|
||||||
@ -2861,123 +2860,95 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
|||||||
u"sub"]))
|
u"sub"]))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
def test_POST_FILEURL_check(self):
|
def test_POST_FILEURL_check(self):
|
||||||
bar_url = self.public_url + "/foo/bar.txt"
|
bar_url = self.public_url + "/foo/bar.txt"
|
||||||
d = self.POST(bar_url, t="check")
|
res = yield self.POST(bar_url, t="check")
|
||||||
def _check(res):
|
self.failUnlessIn("Healthy :", res)
|
||||||
self.failUnlessIn("Healthy :", res)
|
|
||||||
d.addCallback(_check)
|
|
||||||
redir_url = "http://allmydata.org/TARGET"
|
redir_url = "http://allmydata.org/TARGET"
|
||||||
def _check2(statuscode, target):
|
def _check2(statuscode, target):
|
||||||
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
||||||
self.failUnlessReallyEqual(target, redir_url)
|
self.failUnlessReallyEqual(target, redir_url)
|
||||||
d.addCallback(lambda res:
|
yield self.shouldRedirect2("test_POST_FILEURL_check",
|
||||||
self.shouldRedirect2("test_POST_FILEURL_check",
|
_check2,
|
||||||
_check2,
|
self.POST, bar_url,
|
||||||
self.POST, bar_url,
|
t="check",
|
||||||
t="check",
|
when_done=redir_url)
|
||||||
when_done=redir_url))
|
res = yield self.POST(bar_url, t="check", return_to=redir_url)
|
||||||
d.addCallback(lambda res:
|
self.failUnlessIn("Healthy :", res)
|
||||||
self.POST(bar_url, t="check", return_to=redir_url))
|
self.failUnlessIn("Return to file", res)
|
||||||
def _check3(res):
|
self.failUnlessIn(redir_url, res)
|
||||||
self.failUnlessIn("Healthy :", res)
|
|
||||||
self.failUnlessIn("Return to file", res)
|
|
||||||
self.failUnlessIn(redir_url, res)
|
|
||||||
d.addCallback(_check3)
|
|
||||||
|
|
||||||
d.addCallback(lambda res:
|
res = yield self.POST(bar_url, t="check", output="JSON")
|
||||||
self.POST(bar_url, t="check", output="JSON"))
|
data = json.loads(res)
|
||||||
def _check_json(res):
|
self.failUnlessIn("storage-index", data)
|
||||||
data = json.loads(res)
|
self.failUnless(data["results"]["healthy"])
|
||||||
self.failUnlessIn("storage-index", data)
|
|
||||||
self.failUnless(data["results"]["healthy"])
|
|
||||||
d.addCallback(_check_json)
|
|
||||||
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
def test_POST_FILEURL_check_and_repair(self):
|
def test_POST_FILEURL_check_and_repair(self):
|
||||||
bar_url = self.public_url + "/foo/bar.txt"
|
bar_url = self.public_url + "/foo/bar.txt"
|
||||||
d = self.POST(bar_url, t="check", repair="true")
|
res = yield self.POST(bar_url, t="check", repair="true")
|
||||||
def _check(res):
|
self.failUnlessIn("Healthy :", res)
|
||||||
self.failUnlessIn("Healthy :", res)
|
|
||||||
d.addCallback(_check)
|
|
||||||
redir_url = "http://allmydata.org/TARGET"
|
redir_url = "http://allmydata.org/TARGET"
|
||||||
def _check2(statuscode, target):
|
def _check2(statuscode, target):
|
||||||
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
||||||
self.failUnlessReallyEqual(target, redir_url)
|
self.failUnlessReallyEqual(target, redir_url)
|
||||||
d.addCallback(lambda res:
|
yield self.shouldRedirect2("test_POST_FILEURL_check_and_repair",
|
||||||
self.shouldRedirect2("test_POST_FILEURL_check_and_repair",
|
_check2,
|
||||||
_check2,
|
self.POST, bar_url,
|
||||||
self.POST, bar_url,
|
t="check", repair="true",
|
||||||
t="check", repair="true",
|
when_done=redir_url)
|
||||||
when_done=redir_url))
|
res = yield self.POST(bar_url, t="check", return_to=redir_url)
|
||||||
d.addCallback(lambda res:
|
self.failUnlessIn("Healthy :", res)
|
||||||
self.POST(bar_url, t="check", return_to=redir_url))
|
self.failUnlessIn("Return to file", res)
|
||||||
def _check3(res):
|
self.failUnlessIn(redir_url, res)
|
||||||
self.failUnlessIn("Healthy :", res)
|
|
||||||
self.failUnlessIn("Return to file", res)
|
|
||||||
self.failUnlessIn(redir_url, res)
|
|
||||||
d.addCallback(_check3)
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
def test_POST_DIRURL_check(self):
|
def test_POST_DIRURL_check(self):
|
||||||
foo_url = self.public_url + "/foo/"
|
foo_url = self.public_url + "/foo/"
|
||||||
d = self.POST(foo_url, t="check")
|
res = yield self.POST(foo_url, t="check")
|
||||||
def _check(res):
|
self.failUnlessIn("Healthy :", res)
|
||||||
self.failUnlessIn("Healthy :", res)
|
|
||||||
d.addCallback(_check)
|
|
||||||
redir_url = "http://allmydata.org/TARGET"
|
redir_url = "http://allmydata.org/TARGET"
|
||||||
def _check2(statuscode, target):
|
def _check2(statuscode, target):
|
||||||
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
||||||
self.failUnlessReallyEqual(target, redir_url)
|
self.failUnlessReallyEqual(target, redir_url)
|
||||||
d.addCallback(lambda res:
|
yield self.shouldRedirect2("test_POST_DIRURL_check",
|
||||||
self.shouldRedirect2("test_POST_DIRURL_check",
|
_check2,
|
||||||
_check2,
|
self.POST, foo_url,
|
||||||
self.POST, foo_url,
|
t="check",
|
||||||
t="check",
|
when_done=redir_url)
|
||||||
when_done=redir_url))
|
res = yield self.POST(foo_url, t="check", return_to=redir_url)
|
||||||
d.addCallback(lambda res:
|
self.failUnlessIn("Healthy :", res)
|
||||||
self.POST(foo_url, t="check", return_to=redir_url))
|
self.failUnlessIn("Return to file/directory", res)
|
||||||
def _check3(res):
|
self.failUnlessIn(redir_url, res)
|
||||||
self.failUnlessIn("Healthy :", res)
|
|
||||||
self.failUnlessIn("Return to file/directory", res)
|
|
||||||
self.failUnlessIn(redir_url, res)
|
|
||||||
d.addCallback(_check3)
|
|
||||||
|
|
||||||
d.addCallback(lambda res:
|
res = yield self.POST(foo_url, t="check", output="JSON")
|
||||||
self.POST(foo_url, t="check", output="JSON"))
|
data = json.loads(res)
|
||||||
def _check_json(res):
|
self.failUnlessIn("storage-index", data)
|
||||||
data = json.loads(res)
|
self.failUnless(data["results"]["healthy"])
|
||||||
self.failUnlessIn("storage-index", data)
|
|
||||||
self.failUnless(data["results"]["healthy"])
|
|
||||||
d.addCallback(_check_json)
|
|
||||||
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
def test_POST_DIRURL_check_and_repair(self):
|
def test_POST_DIRURL_check_and_repair(self):
|
||||||
foo_url = self.public_url + "/foo/"
|
foo_url = self.public_url + "/foo/"
|
||||||
d = self.POST(foo_url, t="check", repair="true")
|
res = yield self.POST(foo_url, t="check", repair="true")
|
||||||
def _check(res):
|
self.failUnlessIn("Healthy :", res)
|
||||||
self.failUnlessIn("Healthy :", res)
|
|
||||||
d.addCallback(_check)
|
|
||||||
redir_url = "http://allmydata.org/TARGET"
|
redir_url = "http://allmydata.org/TARGET"
|
||||||
def _check2(statuscode, target):
|
def _check2(statuscode, target):
|
||||||
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
||||||
self.failUnlessReallyEqual(target, redir_url)
|
self.failUnlessReallyEqual(target, redir_url)
|
||||||
d.addCallback(lambda res:
|
yield self.shouldRedirect2("test_POST_DIRURL_check_and_repair",
|
||||||
self.shouldRedirect2("test_POST_DIRURL_check_and_repair",
|
_check2,
|
||||||
_check2,
|
self.POST, foo_url,
|
||||||
self.POST, foo_url,
|
t="check", repair="true",
|
||||||
t="check", repair="true",
|
when_done=redir_url)
|
||||||
when_done=redir_url))
|
res = yield self.POST(foo_url, t="check", return_to=redir_url)
|
||||||
d.addCallback(lambda res:
|
self.failUnlessIn("Healthy :", res)
|
||||||
self.POST(foo_url, t="check", return_to=redir_url))
|
self.failUnlessIn("Return to file/directory", res)
|
||||||
def _check3(res):
|
self.failUnlessIn(redir_url, res)
|
||||||
self.failUnlessIn("Healthy :", res)
|
|
||||||
self.failUnlessIn("Return to file/directory", res)
|
|
||||||
self.failUnlessIn(redir_url, res)
|
|
||||||
d.addCallback(_check3)
|
|
||||||
return d
|
|
||||||
|
|
||||||
def test_POST_FILEURL_mdmf_check(self):
|
def test_POST_FILEURL_mdmf_check(self):
|
||||||
quux_url = "/uri/%s" % urllib.quote(self._quux_txt_uri)
|
quux_url = "/uri/%s" % urllib.quote(self._quux_txt_uri)
|
||||||
@ -3038,45 +3009,40 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
|||||||
self.POST, self.public_url, t="start-deep-check")
|
self.POST, self.public_url, t="start-deep-check")
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
def test_POST_DIRURL_deepcheck(self):
|
def test_POST_DIRURL_deepcheck(self):
|
||||||
def _check_redirect(statuscode, target):
|
def _check_redirect(statuscode, target):
|
||||||
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
self.failUnlessReallyEqual(statuscode, str(http.FOUND))
|
||||||
self.failUnless(target.endswith("/operations/123"))
|
self.failUnless(target.endswith("/operations/123"))
|
||||||
d = self.shouldRedirect2("test_POST_DIRURL_deepcheck", _check_redirect,
|
yield self.shouldRedirect2("test_POST_DIRURL_deepcheck", _check_redirect,
|
||||||
self.POST, self.public_url,
|
self.POST, self.public_url,
|
||||||
t="start-deep-check", ophandle="123")
|
t="start-deep-check", ophandle="123")
|
||||||
d.addCallback(self.wait_for_operation, "123")
|
data = yield self.wait_for_operation(None, "123")
|
||||||
def _check_json(data):
|
self.failUnlessReallyEqual(data["finished"], True)
|
||||||
self.failUnlessReallyEqual(data["finished"], True)
|
self.failUnlessReallyEqual(data["count-objects-checked"], 11)
|
||||||
self.failUnlessReallyEqual(data["count-objects-checked"], 11)
|
self.failUnlessReallyEqual(data["count-objects-healthy"], 11)
|
||||||
self.failUnlessReallyEqual(data["count-objects-healthy"], 11)
|
|
||||||
d.addCallback(_check_json)
|
|
||||||
d.addCallback(self.get_operation_results, "123", "html")
|
|
||||||
def _check_html(res):
|
|
||||||
self.failUnlessIn("Objects Checked: <span>11</span>", res)
|
|
||||||
self.failUnlessIn("Objects Healthy: <span>11</span>", res)
|
|
||||||
self.failUnlessIn(FAVICON_MARKUP, res)
|
|
||||||
d.addCallback(_check_html)
|
|
||||||
|
|
||||||
d.addCallback(lambda res:
|
res = yield self.get_operation_results(None, "123", "html")
|
||||||
self.GET("/operations/123/"))
|
self.failUnlessIn("Objects Checked: <span>11</span>", res)
|
||||||
d.addCallback(_check_html) # should be the same as without the slash
|
self.failUnlessIn("Objects Healthy: <span>11</span>", res)
|
||||||
|
self.failUnlessIn(FAVICON_MARKUP, res)
|
||||||
|
|
||||||
d.addCallback(lambda res:
|
res = yield self.GET("/operations/123/")
|
||||||
self.shouldFail2(error.Error, "one", "404 Not Found",
|
# should be the same as without the slash
|
||||||
"No detailed results for SI bogus",
|
self.failUnlessIn("Objects Checked: <span>11</span>", res)
|
||||||
self.GET, "/operations/123/bogus"))
|
self.failUnlessIn("Objects Healthy: <span>11</span>", res)
|
||||||
|
self.failUnlessIn(FAVICON_MARKUP, res)
|
||||||
|
|
||||||
|
yield self.shouldFail2(error.Error, "one", "404 Not Found",
|
||||||
|
"No detailed results for SI bogus",
|
||||||
|
self.GET, "/operations/123/bogus")
|
||||||
|
|
||||||
foo_si = self._foo_node.get_storage_index()
|
foo_si = self._foo_node.get_storage_index()
|
||||||
foo_si_s = base32.b2a(foo_si)
|
foo_si_s = base32.b2a(foo_si)
|
||||||
d.addCallback(lambda res:
|
res = yield self.GET("/operations/123/%s?output=JSON" % foo_si_s)
|
||||||
self.GET("/operations/123/%s?output=JSON" % foo_si_s))
|
data = json.loads(res)
|
||||||
def _check_foo_json(res):
|
self.failUnlessEqual(data["storage-index"], foo_si_s)
|
||||||
data = json.loads(res)
|
self.failUnless(data["results"]["healthy"])
|
||||||
self.failUnlessEqual(data["storage-index"], foo_si_s)
|
|
||||||
self.failUnless(data["results"]["healthy"])
|
|
||||||
d.addCallback(_check_foo_json)
|
|
||||||
return d
|
|
||||||
|
|
||||||
def test_POST_DIRURL_deepcheck_and_repair(self):
|
def test_POST_DIRURL_deepcheck_and_repair(self):
|
||||||
d = self.POST(self.public_url, t="start-deep-check", repair="true",
|
d = self.POST(self.public_url, t="start-deep-check", repair="true",
|
||||||
|
Loading…
Reference in New Issue
Block a user