test_web: rewrite all POST(followRedirect=True) calls with do_http

Since POST() is about to lose followRedirect=True
This commit is contained in:
Brian Warner 2017-07-24 18:12:35 -05:00
parent 3f03367d2f
commit 0deb903888

@ -1898,8 +1898,9 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
def test_POST_DIRURL_manifest(self):
d = defer.succeed(None)
def getman(ignored, output):
d = self.POST(self.public_url + "/foo/?t=start-manifest&ophandle=125",
followRedirect=True)
url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=125"
d = do_http("post", url, allow_redirects=True,
browser_like_redirects=True)
d.addCallback(self.wait_for_operation, "125")
d.addCallback(self.get_operation_results, "125", output)
return d
@ -1948,8 +1949,9 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
return d
def test_POST_DIRURL_deepsize(self):
d = self.POST(self.public_url + "/foo/?t=start-deep-size&ophandle=126",
followRedirect=True)
url = self.webish_url + self.public_url + "/foo/?t=start-deep-size&ophandle=126"
d = do_http("post", url, allow_redirects=True,
browser_like_redirects=True)
d.addCallback(self.wait_for_operation, "126")
d.addCallback(self.get_operation_results, "126", "json")
def _got_json(data):
@ -1976,8 +1978,9 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
return d
def test_POST_DIRURL_deepstats(self):
d = self.POST(self.public_url + "/foo/?t=start-deep-stats&ophandle=127",
followRedirect=True)
url = self.webish_url + self.public_url + "/foo/?t=start-deep-stats&ophandle=127"
d = do_http("post", url,
allow_redirects=True, browser_like_redirects=True)
d.addCallback(self.wait_for_operation, "127")
d.addCallback(self.get_operation_results, "127", "json")
def _got_json(stats):
@ -3026,8 +3029,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
self.failUnless(data["results"]["healthy"])
def test_POST_DIRURL_deepcheck_and_repair(self):
d = self.POST(self.public_url, t="start-deep-check", repair="true",
ophandle="124", output="json", followRedirect=True)
url = self.webish_url + self.public_url
body, headers = self.build_form(t="start-deep-check", repair="true",
ophandle="124", output="json")
d = do_http("post", url, data=body, headers=headers,
allow_redirects=True,
browser_like_redirects=True)
d.addCallback(self.wait_for_operation, "124")
def _check_json(data):
self.failUnlessReallyEqual(data["finished"], True)
@ -4399,8 +4406,9 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
return d
def test_ophandle_cancel(self):
d = self.POST(self.public_url + "/foo/?t=start-manifest&ophandle=128",
followRedirect=True)
url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=128"
d = do_http("post", url,
allow_redirects=True, browser_like_redirects=True)
d.addCallback(lambda ignored:
self.GET("/operations/128?t=status&output=JSON"))
def _check1(res):
@ -4425,8 +4433,9 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
return d
def test_ophandle_retainfor(self):
d = self.POST(self.public_url + "/foo/?t=start-manifest&ophandle=129&retain-for=60",
followRedirect=True)
url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=129&retain-for=60"
d = do_http("post", url,
allow_redirects=True, browser_like_redirects=True)
d.addCallback(lambda ignored:
self.GET("/operations/129?t=status&output=JSON&retain-for=0"))
def _check1(res):
@ -4445,8 +4454,9 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
return d
def test_ophandle_release_after_complete(self):
d = self.POST(self.public_url + "/foo/?t=start-manifest&ophandle=130",
followRedirect=True)
url = self.webish_url + self.public_url + "/foo/?t=start-manifest&ophandle=130"
d = do_http("post", url,
allow_redirects=True, browser_like_redirects=True)
d.addCallback(self.wait_for_operation, "130")
d.addCallback(lambda ignored:
self.GET("/operations/130?t=status&output=JSON&release-after-complete=true"))
@ -4462,19 +4472,24 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
def test_uncollected_ophandle_expiration(self):
# uncollected ophandles should expire after 4 days
def _make_uncollected_ophandle(ophandle):
d = self.POST(self.public_url +
"/foo/?t=start-manifest&ophandle=%d" % ophandle,
followRedirect=False)
# When we start the operation, the webapi server will want
# to redirect us to the page for the ophandle, so we get
# confirmation that the operation has started. If the
# manifest operation has finished by the time we get there,
# following that redirect (by setting followRedirect=True
# above) has the side effect of collecting the ophandle that
# we've just created, which means that we can't use the
# ophandle to test the uncollected timeout anymore. So,
# instead, catch the 302 here and don't follow it.
d.addBoth(self.should302, "uncollected_ophandle_creation")
url = (self.webish_url + self.public_url +
"/foo/?t=start-manifest&ophandle=%d" % ophandle)
# When we start the operation, the webapi server will want to
# redirect us to the page for the ophandle, so we get
# confirmation that the operation has started. If the manifest
# operation has finished by the time we get there, following that
# redirect would have the side effect of collecting the ophandle
# that we've just created, which means that we can't use the
# ophandle to test the uncollected timeout anymore. So, instead,
# catch+ignore any 302 here and don't follow it.
d = treq.request("post", url, persistent=False)
def _ignore_redirect(f):
f.trap(client.ResponseFailed)
e = f.value
reasons = e.reasons
r0 = reasons[0]
r0.trap(error.PageRedirect)
d.addErrback(_ignore_redirect)
return d
# 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.
@ -4504,12 +4519,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
def test_collected_ophandle_expiration(self):
# collected ophandles should expire after 1 day
def _make_collected_ophandle(ophandle):
d = self.POST(self.public_url +
"/foo/?t=start-manifest&ophandle=%d" % ophandle,
followRedirect=True)
url = (self.webish_url + self.public_url +
"/foo/?t=start-manifest&ophandle=%d" % ophandle)
# By following the initial redirect, we collect the ophandle
# we've just created.
return d
return do_http("post", url,
allow_redirects=True, browser_like_redirects=True)
# Create a collected ophandle, then collect it after 23 hours
# and 59 seconds to make sure that it is still there.
d = _make_collected_ophandle(133)