From 869e1ed41aa7b36dff3d7a217544cdb289ae7ccb Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 19 May 2008 12:33:39 -0700 Subject: [PATCH] test_web.py: minor cleanups, improved error reporting --- src/allmydata/test/test_web.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index f143fd34..f57ff1be 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -256,7 +256,7 @@ class WebMixin(object): % (substring, str(res))) if response_substring: self.failUnless(response_substring in res.value.response, - "respose substring '%s' not in '%s'" + "response substring '%s' not in '%s'" % (response_substring, res.value.response)) else: self.fail("%s was supposed to raise %s, not get '%s'" % @@ -277,7 +277,7 @@ class WebMixin(object): % (substring, str(res))) if response_substring: self.failUnless(response_substring in res.value.response, - "respose substring '%s' not in '%s'" + "response substring '%s' not in '%s'" % (response_substring, res.value.response)) else: self.fail("%s was supposed to raise %s, not get '%s'" % @@ -305,7 +305,7 @@ class WebMixin(object): % (substring, str(res))) if response_substring: self.failUnless(response_substring in res.value.response, - "respose substring '%s' not in '%s'" + "response substring '%s' not in '%s'" % (response_substring, res.value.response)) else: self.fail("%s was supposed to Error(%s), not get '%s'" % @@ -977,8 +977,22 @@ class Web(WebMixin, unittest.TestCase): self.failUnlessEqual(self._mutable_uri, newnode.get_uri()) d.addCallback(_got3) + d.addErrback(self.dump_error) return d + def dump_error(self, f): + # if the web server returns an error code (like 400 Bad Request), + # web.client.getPage puts the HTTP response body into the .response + # attribute of the exception object that it gives back. It does not + # appear in the Failure's repr(), so the ERROR that trial displays + # will be rather terse and unhelpful. addErrback this method to the + # end of your chain to get more information out of these errors. + if f.check(error.Error): + print "web.error.Error:" + print f + print f.value.response + return f + def test_POST_upload_replace(self): d = self.POST(self.public_url + "/foo", t="upload", file=("bar.txt", self.NEWFILE_CONTENTS)) @@ -1192,6 +1206,7 @@ class Web(WebMixin, unittest.TestCase): self.failUnlessURIMatchesChild(newuri11, self._foo_node, u"atomic_added_3") d.addCallback(_then) + d.addErrback(self.dump_error) return d def test_POST_put_uri(self): -- 2.45.2