test_web: replace all shouldHTTPError with assertHTTPError

and update to inlineCallbacks while we're in there
This commit is contained in:
Brian Warner 2017-07-24 19:53:48 -05:00
parent 2687ee90c5
commit 05317d4d12

View File

@ -1511,12 +1511,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(lambda json: self.failUnlessIn("SDMF", json)) d.addCallback(lambda json: self.failUnlessIn("SDMF", json))
return d return d
@inlineCallbacks
def test_PUT_NEWFILEURL_unlinked_bad_format(self): def test_PUT_NEWFILEURL_unlinked_bad_format(self):
contents = self.NEWFILE_CONTENTS * 300000 contents = self.NEWFILE_CONTENTS * 300000
return self.shouldHTTPError("PUT_NEWFILEURL_unlinked_bad_format", yield self.assertHTTPError(self.webish_url + "/uri?format=foo", 400,
400, "Bad Request", "Unknown format: foo", "Unknown format: foo",
self.PUT, "/uri?format=foo", method="put", data=contents)
contents)
def test_PUT_NEWFILEURL_range_bad(self): def test_PUT_NEWFILEURL_range_bad(self):
headers = {"content-range": "bytes 1-10/%d" % len(self.NEWFILE_CONTENTS)} headers = {"content-range": "bytes 1-10/%d" % len(self.NEWFILE_CONTENTS)}
@ -1695,12 +1695,10 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(_check2) d.addCallback(_check2)
return d return d
@inlineCallbacks
def test_GET_FILEURL_badtype(self): def test_GET_FILEURL_badtype(self):
d = self.shouldHTTPError("GET t=bogus", 400, "Bad Request", url = self.webish_url + self.public_url + "/foo/bar.txt?t=bogus"
"bad t=bogus", yield self.assertHTTPError(url, 400, "bad t=bogus")
self.GET,
self.public_url + "/foo/bar.txt?t=bogus")
return d
def test_CSS_FILE(self): def test_CSS_FILE(self):
d = self.GET("/tahoe.css", followRedirect=True) d = self.GET("/tahoe.css", followRedirect=True)
@ -1844,13 +1842,10 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(_check5) d.addCallback(_check5)
return d return d
@inlineCallbacks
def test_GET_DIRURL_badtype(self): def test_GET_DIRURL_badtype(self):
d = self.shouldHTTPError("test_GET_DIRURL_badtype", url = self.webish_url + self.public_url + "/foo?t=bogus"
400, "Bad Request", yield self.assertHTTPError(url, 400, "bad t=bogus")
"bad t=bogus",
self.GET,
self.public_url + "/foo?t=bogus")
return d
def test_GET_DIRURL_json(self): def test_GET_DIRURL_json(self):
d = self.GET(self.public_url + "/foo?t=json") d = self.GET(self.public_url + "/foo?t=json")
@ -2068,11 +2063,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
self.failUnlessEqual(node._node.get_version(), SDMF_VERSION)) self.failUnlessEqual(node._node.get_version(), SDMF_VERSION))
return d return d
@inlineCallbacks
def test_PUT_NEWDIRURL_bad_format(self): def test_PUT_NEWDIRURL_bad_format(self):
return self.shouldHTTPError("PUT_NEWDIRURL_bad_format", url = (self.webish_url + self.public_url +
400, "Bad Request", "Unknown format: foo", "/foo/newdir=?t=mkdir&format=foo")
self.PUT, self.public_url + yield self.assertHTTPError(url, 400, "Unknown format: foo",
"/foo/newdir=?t=mkdir&format=foo", "") method="put", data="")
def test_POST_NEWDIRURL(self): def test_POST_NEWDIRURL(self):
d = self.POST2(self.public_url + "/foo/newdir?t=mkdir", "") d = self.POST2(self.public_url + "/foo/newdir?t=mkdir", "")
@ -2100,11 +2096,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
self.failUnlessEqual(node._node.get_version(), SDMF_VERSION)) self.failUnlessEqual(node._node.get_version(), SDMF_VERSION))
return d return d
@inlineCallbacks
def test_POST_NEWDIRURL_bad_format(self): def test_POST_NEWDIRURL_bad_format(self):
return self.shouldHTTPError("POST_NEWDIRURL_bad_format", url = (self.webish_url + self.public_url +
400, "Bad Request", "Unknown format: foo", "/foo/newdir?t=mkdir&format=foo")
self.POST2, self.public_url + \ yield self.assertHTTPError(url, 400, "Unknown format: foo",
"/foo/newdir?t=mkdir&format=foo", "") method="post", data="")
def test_POST_NEWDIRURL_emptyname(self): def test_POST_NEWDIRURL_emptyname(self):
# an empty pathname component (i.e. a double-slash) is disallowed # an empty pathname component (i.e. a double-slash) is disallowed
@ -2175,13 +2172,13 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
def test_POST_NEWDIRURL_initial_children_sdmf(self): def test_POST_NEWDIRURL_initial_children_sdmf(self):
return self._do_POST_NEWDIRURL_initial_children_test(SDMF_VERSION) return self._do_POST_NEWDIRURL_initial_children_test(SDMF_VERSION)
@inlineCallbacks
def test_POST_NEWDIRURL_initial_children_bad_format(self): def test_POST_NEWDIRURL_initial_children_bad_format(self):
(newkids, caps) = self._create_initial_children() (newkids, caps) = self._create_initial_children()
return self.shouldHTTPError("POST_NEWDIRURL_initial_children_bad_format", url = (self.webish_url + self.public_url +
400, "Bad Request", "Unknown format: foo", "/foo/newdir?t=mkdir-with-children&format=foo")
self.POST2, self.public_url + \ yield self.assertHTTPError(url, 400, "Unknown format: foo",
"/foo/newdir?t=mkdir-with-children&format=foo", method="post", data=json.dumps(newkids))
json.dumps(newkids))
def test_POST_NEWDIRURL_immutable(self): def test_POST_NEWDIRURL_immutable(self):
(newkids, caps) = self._create_immutable_children() (newkids, caps) = self._create_immutable_children()
@ -2300,12 +2297,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
self.failUnlessEqual(newdir._node.get_version(), SDMF_VERSION)) self.failUnlessEqual(newdir._node.get_version(), SDMF_VERSION))
return d return d
@inlineCallbacks
def test_PUT_NEWDIRURL_mkdirs_bad_format(self): def test_PUT_NEWDIRURL_mkdirs_bad_format(self):
return self.shouldHTTPError("PUT_NEWDIRURL_mkdirs_bad_format", url = (self.webish_url + self.public_url +
400, "Bad Request", "Unknown format: foo", "/foo/subdir/newdir?t=mkdir&format=foo")
self.PUT, self.public_url + \ yield self.assertHTTPError(url, 400, "Unknown format: foo",
"/foo/subdir/newdir?t=mkdir&format=foo", method="put", data="")
"")
def test_DELETE_DIRURL(self): def test_DELETE_DIRURL(self):
d = self.DELETE(self.public_url + "/foo") d = self.DELETE(self.public_url + "/foo")
@ -2575,12 +2572,13 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(_check_upload_unlinked, "mdmf", "URI:MDMF") d.addCallback(_check_upload_unlinked, "mdmf", "URI:MDMF")
return d return d
@inlineCallbacks
def test_POST_upload_bad_format_unlinked(self): def test_POST_upload_bad_format_unlinked(self):
return self.shouldHTTPError("POST_upload_bad_format_unlinked", url = self.webish_url + "/uri?t=upload&format=foo"
400, "Bad Request", "Unknown format: foo", body, headers = self.build_form(file=("foo.txt", self.NEWFILE_CONTENTS * 300000))
self.POST, yield self.assertHTTPError(url, 400,
"/uri?t=upload&format=foo", "Unknown format: foo",
file=("foo.txt", self.NEWFILE_CONTENTS * 300000)) method="post", data=body, headers=headers)
def test_POST_upload_format(self): def test_POST_upload_format(self):
def _check_upload(ign, format, uri_prefix, fn=None): def _check_upload(ign, format, uri_prefix, fn=None):
@ -2610,12 +2608,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(_check_upload, "MDMF", "URI:MDMF") d.addCallback(_check_upload, "MDMF", "URI:MDMF")
return d return d
@inlineCallbacks
def test_POST_upload_bad_format(self): def test_POST_upload_bad_format(self):
return self.shouldHTTPError("POST_upload_bad_format", url = self.webish_url + self.public_url + "/foo?t=upload&format=foo"
400, "Bad Request", "Unknown format: foo", body, headers = self.build_form(file=("foo.txt", self.NEWFILE_CONTENTS * 300000))
self.POST, self.public_url + \ yield self.assertHTTPError(url, 400, "Unknown format: foo",
"/foo?t=upload&format=foo", method="post", data=body, headers=headers)
file=("foo.txt", self.NEWFILE_CONTENTS * 300000))
def test_POST_upload_mutable(self): def test_POST_upload_mutable(self):
# this creates a mutable file # this creates a mutable file
@ -3096,11 +3094,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
self.failUnlessEqual(node._node.get_version(), SDMF_VERSION)) self.failUnlessEqual(node._node.get_version(), SDMF_VERSION))
return d return d
@inlineCallbacks
def test_POST_mkdir_bad_format(self): def test_POST_mkdir_bad_format(self):
return self.shouldHTTPError("POST_mkdir_bad_format", url = (self.webish_url + self.public_url +
400, "Bad Request", "Unknown format: foo", "/foo?t=mkdir&name=newdir&format=foo")
self.POST, self.public_url + yield self.assertHTTPError(url, 400, "Unknown format: foo",
"/foo?t=mkdir&name=newdir&format=foo") method="post")
def test_POST_mkdir_initial_children(self): def test_POST_mkdir_initial_children(self):
(newkids, caps) = self._create_initial_children() (newkids, caps) = self._create_initial_children()
@ -3146,13 +3145,13 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
caps['filecap1']) caps['filecap1'])
return d return d
@inlineCallbacks
def test_POST_mkdir_initial_children_bad_format(self): def test_POST_mkdir_initial_children_bad_format(self):
(newkids, caps) = self._create_initial_children() (newkids, caps) = self._create_initial_children()
return self.shouldHTTPError("POST_mkdir_initial_children_bad_format", url = (self.webish_url + self.public_url +
400, "Bad Request", "Unknown format: foo", "/foo?t=mkdir-with-children&name=newdir&format=foo")
self.POST2, self.public_url + \ yield self.assertHTTPError(url, 400, "Unknown format: foo",
"/foo?t=mkdir-with-children&name=newdir&format=foo", method="post", data=json.dumps(newkids))
json.dumps(newkids))
def test_POST_mkdir_immutable(self): def test_POST_mkdir_immutable(self):
(newkids, caps) = self._create_immutable_children() (newkids, caps) = self._create_immutable_children()
@ -3227,11 +3226,11 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(_after_mkdir) d.addCallback(_after_mkdir)
return d return d
@inlineCallbacks
def test_POST_mkdir_no_parentdir_noredirect_bad_format(self): def test_POST_mkdir_no_parentdir_noredirect_bad_format(self):
return self.shouldHTTPError("POST_mkdir_no_parentdir_noredirect_bad_format", url = self.webish_url + self.public_url + "/uri?t=mkdir&format=foo"
400, "Bad Request", "Unknown format: foo", yield self.assertHTTPError(url, 400, "Unknown format: foo",
self.POST, self.public_url + method="post")
"/uri?t=mkdir&format=foo")
def test_POST_mkdir_no_parentdir_noredirect2(self): def test_POST_mkdir_no_parentdir_noredirect2(self):
# make sure form-based arguments (as on the welcome page) still work # make sure form-based arguments (as on the welcome page) still work
@ -3360,25 +3359,24 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(_after_mkdir) d.addCallback(_after_mkdir)
return d return d
@inlineCallbacks
def test_POST_mkdir_no_parentdir_unexpected_children(self): def test_POST_mkdir_no_parentdir_unexpected_children(self):
# the regular /uri?t=mkdir operation is specified to ignore its body. # the regular /uri?t=mkdir operation is specified to ignore its body.
# Only t=mkdir-with-children pays attention to it. # Only t=mkdir-with-children pays attention to it.
(newkids, caps) = self._create_initial_children() (newkids, caps) = self._create_initial_children()
d = self.shouldHTTPError("POST_mkdir_no_parentdir_unexpected_children", url = self.webish_url + "/uri?t=mkdir" # without children
400, "Bad Request", yield self.assertHTTPError(url, 400,
"t=mkdir does not accept children=, " "t=mkdir does not accept children=, "
"try t=mkdir-with-children instead", "try t=mkdir-with-children instead",
self.POST2, "/uri?t=mkdir", # without children method="post", data=json.dumps(newkids))
json.dumps(newkids))
return d
@inlineCallbacks
def test_POST_noparent_bad(self): def test_POST_noparent_bad(self):
d = self.shouldHTTPError("POST_noparent_bad", url = self.webish_url + "/uri?t=bogus"
400, "Bad Request", yield self.assertHTTPError(url, 400,
"/uri accepts only PUT, PUT?t=mkdir, " "/uri accepts only PUT, PUT?t=mkdir, "
"POST?t=upload, and POST?t=mkdir", "POST?t=upload, and POST?t=mkdir",
self.POST, "/uri?t=bogus") method="post")
return d
def test_POST_mkdir_no_parentdir_immutable(self): def test_POST_mkdir_no_parentdir_immutable(self):
(newkids, caps) = self._create_immutable_children() (newkids, caps) = self._create_immutable_children()
@ -4065,16 +4063,15 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(self.failUnlessIsFooJSON) d.addCallback(self.failUnlessIsFooJSON)
return d return d
@inlineCallbacks
def test_GET_URI_URL_missing(self): def test_GET_URI_URL_missing(self):
base = "/uri/%s" % self._bad_file_uri base = "/uri/%s" % self._bad_file_uri
d = self.shouldHTTPError("test_GET_URI_URL_missing", url = self.webish_url + base
http.GONE, None, "NotEnoughSharesError", yield self.assertHTTPError(url, http.GONE, "NotEnoughSharesError")
self.GET, base)
# TODO: how can we exercise both sides of WebDownloadTarget.fail # TODO: how can we exercise both sides of WebDownloadTarget.fail
# here? we must arrange for a download to fail after target.open() # here? we must arrange for a download to fail after target.open()
# has been called, and then inspect the response to see that it is # has been called, and then inspect the response to see that it is
# shorter than we expected. # shorter than we expected.
return d
def test_PUT_DIRURL_uri(self): def test_PUT_DIRURL_uri(self):
d = self.s.create_dirnode() d = self.s.create_dirnode()
@ -4162,13 +4159,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(_got_json) d.addCallback(_got_json)
return d return d
@inlineCallbacks
def test_PUT_NEWFILEURL_bad_format(self): def test_PUT_NEWFILEURL_bad_format(self):
new_contents = self.NEWFILE_CONTENTS * 300000 new_contents = self.NEWFILE_CONTENTS * 300000
return self.shouldHTTPError("PUT_NEWFILEURL_bad_format", url = self.webish_url + self.public_url + "/foo/foo.txt?format=foo"
400, "Bad Request", "Unknown format: foo", yield self.assertHTTPError(url, 400, "Unknown format: foo",
self.PUT, self.public_url + \ method="put", data=new_contents)
"/foo/foo.txt?format=foo",
new_contents)
def test_PUT_NEWFILEURL_uri_replace(self): def test_PUT_NEWFILEURL_uri_replace(self):
contents, n, new_uri = self.makefile(8) contents, n, new_uri = self.makefile(8)
@ -4297,11 +4293,11 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
d.addCallback(_got) d.addCallback(_got)
return d return d
@inlineCallbacks
def test_PUT_mkdir_bad_format(self): def test_PUT_mkdir_bad_format(self):
return self.shouldHTTPError("PUT_mkdir_bad_format", url = self.webish_url + "/uri?t=mkdir&format=foo"
400, "Bad Request", "Unknown format: foo", yield self.assertHTTPError(url, 400, "Unknown format: foo",
self.PUT, "/uri?t=mkdir&format=foo", method="put", data="")
"")
def test_POST_check(self): def test_POST_check(self):
d = self.POST(self.public_url + "/foo", t="check", name="bar.txt") d = self.POST(self.public_url + "/foo", t="check", name="bar.txt")
@ -4352,37 +4348,22 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
self.failUnlessEqual(results, "begin"+self.new_data[len("begin"):]+("puppies"*100))) self.failUnlessEqual(results, "begin"+self.new_data[len("begin"):]+("puppies"*100)))
return d return d
@inlineCallbacks
def test_PUT_update_at_invalid_offset(self): def test_PUT_update_at_invalid_offset(self):
file_contents = "test file" * 100000 # about 900 KiB file_contents = "test file" * 100000 # about 900 KiB
d = self.PUT("/uri?mutable=true", file_contents) filecap = yield self.PUT("/uri?mutable=true", file_contents)
def _then(filecap):
self.filecap = filecap
d.addCallback(_then)
# Negative offsets should cause an error. # Negative offsets should cause an error.
d.addCallback(lambda ignored: url = self.webish_url + "/uri/%s?offset=-1" % filecap
self.shouldHTTPError("PUT_update_at_invalid_offset", yield self.assertHTTPError(url, 400, "Invalid offset",
400, "Bad Request", method="put", data="foo")
"Invalid offset",
self.PUT,
"/uri/%s?offset=-1" % self.filecap,
"foo"))
return d
@inlineCallbacks
def test_PUT_update_at_offset_immutable(self): def test_PUT_update_at_offset_immutable(self):
file_contents = "Test file" * 100000 file_contents = "Test file" * 100000
d = self.PUT("/uri", file_contents) filecap = yield self.PUT("/uri", file_contents)
def _then(filecap): url = self.webish_url + "/uri/%s?offset=50" % filecap
self.filecap = filecap yield self.assertHTTPError(url, 400, "immutable",
d.addCallback(_then) method="put", data="foo")
d.addCallback(lambda ignored:
self.shouldHTTPError("PUT_update_at_offset_immutable",
400, "Bad Request",
"immutable",
self.PUT,
"/uri/%s?offset=50" % self.filecap,
"foo"))
return d
@inlineCallbacks @inlineCallbacks
def test_bad_method(self): def test_bad_method(self):
@ -4404,70 +4385,51 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
yield self.assertHTTPError(url, 404, yield self.assertHTTPError(url, 404,
"unknown/expired handle 'bogus'") "unknown/expired handle 'bogus'")
@inlineCallbacks
def test_ophandle_cancel(self): def test_ophandle_cancel(self):
url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=128" url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=128"
d = do_http("post", url, yield do_http("post", url,
allow_redirects=True, browser_like_redirects=True) allow_redirects=True, browser_like_redirects=True)
d.addCallback(lambda ignored: res = yield self.GET("/operations/128?t=status&output=JSON")
self.GET("/operations/128?t=status&output=JSON")) data = json.loads(res)
def _check1(res): self.failUnless("finished" in data, res)
data = json.loads(res) monitor = self.ws.root.child_operations.handles["128"][0]
self.failUnless("finished" in data, res)
monitor = self.ws.root.child_operations.handles["128"][0]
d = self.POST("/operations/128?t=cancel&output=JSON")
def _check2(res):
data = json.loads(res)
self.failUnless("finished" in data, res)
# t=cancel causes the handle to be forgotten
self.failUnless(monitor.is_cancelled())
d.addCallback(_check2)
return d
d.addCallback(_check1)
d.addCallback(lambda ignored:
self.shouldHTTPError("ophandle_cancel",
404, "404 Not Found",
"unknown/expired handle '128'",
self.GET,
"/operations/128?t=status&output=JSON"))
return d
res = yield self.POST("/operations/128?t=cancel&output=JSON")
data = json.loads(res)
self.failUnless("finished" in data, res)
# t=cancel causes the handle to be forgotten
self.failUnless(monitor.is_cancelled())
url = self.webish_url + "/operations/128?t=status&output=JSON"
yield self.assertHTTPError(url, 404, "unknown/expired handle '128'")
@inlineCallbacks
def test_ophandle_retainfor(self): def test_ophandle_retainfor(self):
url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=129&retain-for=60" url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=129&retain-for=60"
d = do_http("post", url, yield do_http("post", url,
allow_redirects=True, browser_like_redirects=True) allow_redirects=True, browser_like_redirects=True)
d.addCallback(lambda ignored: res = yield self.GET("/operations/129?t=status&output=JSON&retain-for=0")
self.GET("/operations/129?t=status&output=JSON&retain-for=0")) data = json.loads(res)
def _check1(res): self.failUnless("finished" in data, res)
data = json.loads(res)
self.failUnless("finished" in data, res)
d.addCallback(_check1)
# the retain-for=0 will cause the handle to be expired very soon
d.addCallback(lambda ign:
self.clock.advance(2.0))
d.addCallback(lambda ignored:
self.shouldHTTPError("ophandle_retainfor",
404, "404 Not Found",
"unknown/expired handle '129'",
self.GET,
"/operations/129?t=status&output=JSON"))
return d
# the retain-for=0 will cause the handle to be expired very soon
yield self.clock.advance(2.0)
url = self.webish_url + "/operations/129?t=status&output=JSON"
yield self.assertHTTPError(url, 404, "unknown/expired handle '129'")
@inlineCallbacks
def test_ophandle_release_after_complete(self): def test_ophandle_release_after_complete(self):
url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=130" url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=130"
d = do_http("post", url, yield do_http("post", url,
allow_redirects=True, browser_like_redirects=True) allow_redirects=True, browser_like_redirects=True)
d.addCallback(self.wait_for_operation, "130") yield self.wait_for_operation(None, "130")
d.addCallback(lambda ignored: yield self.GET("/operations/130?t=status&output=JSON&release-after-complete=true")
self.GET("/operations/130?t=status&output=JSON&release-after-complete=true"))
# the release-after-complete=true will cause the handle to be expired # the release-after-complete=true will cause the handle to be expired
d.addCallback(lambda ignored: op_url = self.webish_url + "/operations/130?t=status&output=JSON"
self.shouldHTTPError("ophandle_release_after_complete", yield self.assertHTTPError(op_url, 404, "unknown/expired handle '130'")
404, "404 Not Found",
"unknown/expired handle '130'",
self.GET,
"/operations/130?t=status&output=JSON"))
return d
@inlineCallbacks
def test_uncollected_ophandle_expiration(self): def test_uncollected_ophandle_expiration(self):
# uncollected ophandles should expire after 4 days # uncollected ophandles should expire after 4 days
def _make_uncollected_ophandle(ophandle): def _make_uncollected_ophandle(ophandle):
@ -4492,29 +4454,20 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
return d return d
# Create an ophandle, don't collect it, then advance the clock by # Create an ophandle, don't collect it, then advance the clock by
# 4 days - 1 second and make sure that the ophandle is still there. # 4 days - 1 second and make sure that the ophandle is still there.
d = _make_uncollected_ophandle(131) yield _make_uncollected_ophandle(131)
d.addCallback(lambda ign: yield self.clock.advance((96*60*60) - 1) # 96 hours = 4 days
self.clock.advance((96*60*60) - 1)) # 96 hours = 4 days res = yield self.GET("/operations/131?t=status&output=JSON")
d.addCallback(lambda ign: data = json.loads(res)
self.GET("/operations/131?t=status&output=JSON")) self.failUnless("finished" in data, res)
def _check1(res):
data = json.loads(res)
self.failUnless("finished" in data, res)
d.addCallback(_check1)
# Create an ophandle, don't collect it, then try to collect it # Create an ophandle, don't collect it, then try to collect it
# after 4 days. It should be gone. # after 4 days. It should be gone.
d.addCallback(lambda ign: yield _make_uncollected_ophandle(132)
_make_uncollected_ophandle(132)) yield self.clock.advance(96*60*60)
d.addCallback(lambda ign: op_url = self.webish_url + "/operations/132?t=status&output=JSON"
self.clock.advance(96*60*60)) yield self.assertHTTPError(op_url, 404, "unknown/expired handle '132'")
d.addCallback(lambda ign:
self.shouldHTTPError("uncollected_ophandle_expired_after_100_hours",
404, "404 Not Found",
"unknown/expired handle '132'",
self.GET,
"/operations/132?t=status&output=JSON"))
return d
@inlineCallbacks
def test_collected_ophandle_expiration(self): def test_collected_ophandle_expiration(self):
# collected ophandles should expire after 1 day # collected ophandles should expire after 1 day
def _make_collected_ophandle(ophandle): def _make_collected_ophandle(ophandle):
@ -4526,28 +4479,18 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
allow_redirects=True, browser_like_redirects=True) allow_redirects=True, browser_like_redirects=True)
# Create a collected ophandle, then collect it after 23 hours # Create a collected ophandle, then collect it after 23 hours
# and 59 seconds to make sure that it is still there. # and 59 seconds to make sure that it is still there.
d = _make_collected_ophandle(133) yield _make_collected_ophandle(133)
d.addCallback(lambda ign: yield self.clock.advance((24*60*60) - 1)
self.clock.advance((24*60*60) - 1)) res = yield self.GET("/operations/133?t=status&output=JSON")
d.addCallback(lambda ign: data = json.loads(res)
self.GET("/operations/133?t=status&output=JSON")) self.failUnless("finished" in data, res)
def _check1(res):
data = json.loads(res)
self.failUnless("finished" in data, res)
d.addCallback(_check1)
# Create another uncollected ophandle, then try to collect it # Create another uncollected ophandle, then try to collect it
# after 24 hours to make sure that it is gone. # after 24 hours to make sure that it is gone.
d.addCallback(lambda ign: yield _make_collected_ophandle(134)
_make_collected_ophandle(134)) yield self.clock.advance(24*60*60)
d.addCallback(lambda ign: op_url = self.webish_url + "/operations/134?t=status&output=JSON"
self.clock.advance(24*60*60)) yield self.assertHTTPError(op_url, 404, "unknown/expired handle '134'")
d.addCallback(lambda ign:
self.shouldHTTPError("collected_ophandle_expired_after_1_day",
404, "404 Not Found",
"unknown/expired handle '134'",
self.GET,
"/operations/134?t=status&output=JSON"))
return d
def test_incident(self): def test_incident(self):
d = self.POST("/report_incident", details="eek") d = self.POST("/report_incident", details="eek")