From: Brian Warner Date: Tue, 3 Mar 2009 23:56:20 +0000 (-0700) Subject: test_web: move shouldHTTPError into common.WebErrorMixin X-Git-Url: https://git.rkrishnan.org/pf/content/en/footer/...?a=commitdiff_plain;h=f15c0be5af68b96c972e4ce2e2bad56ba39f7a53;p=tahoe-lafs%2Ftahoe-lafs.git test_web: move shouldHTTPError into common.WebErrorMixin --- diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index be0834d0..b4401568 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -1074,6 +1074,35 @@ class WebErrorMixin: f.trap(WebError) print "Web Error:", f.value, ":", f.value.response return f + + def _shouldHTTPError(self, res, which, code=None, substring=None, + response_substring=None): + if isinstance(res, failure.Failure): + res.trap(WebError) + if code is not None: + self.failUnlessEqual(res.value.status, str(code)) + if substring: + self.failUnless(substring in str(res), + "substring '%s' not in '%s'" + % (substring, str(res))) + if response_substring: + self.failUnless(response_substring in res.value.response, + "response substring '%s' not in '%s'" + % (response_substring, res.value.response)) + else: + self.fail("%s was supposed to Error(%s), not get '%s'" % + (which, code, res)) + + def shouldHTTPError(self, which, + code=None, substring=None, response_substring=None, + callable=None, *args, **kwargs): + assert substring is None or isinstance(substring, str) + assert callable + d = defer.maybeDeferred(callable, *args, **kwargs) + d.addBoth(self._shouldHTTPError, which, + code, substring, response_substring) + return d + class ErrorMixin(WebErrorMixin): def explain_error(self, f): if f.check(defer.FirstError): diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index fc350658..a7f882f3 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -362,36 +362,8 @@ class WebMixin(object): self.fail("%s was supposed to Error(404), not get '%s'" % (which, res)) - def _shouldHTTPError(self, res, which, code=None, substring=None, - response_substring=None): - if isinstance(res, failure.Failure): - res.trap(error.Error) - if code is not None: - self.failUnlessEqual(res.value.status, str(code)) - if substring: - self.failUnless(substring in str(res), - "substring '%s' not in '%s'" - % (substring, str(res))) - if response_substring: - self.failUnless(response_substring in res.value.response, - "response substring '%s' not in '%s'" - % (response_substring, res.value.response)) - else: - self.fail("%s was supposed to Error(%s), not get '%s'" % - (which, code, res)) - - def shouldHTTPError(self, which, - code=None, substring=None, response_substring=None, - callable=None, *args, **kwargs): - assert substring is None or isinstance(substring, str) - assert callable - d = defer.maybeDeferred(callable, *args, **kwargs) - d.addBoth(self._shouldHTTPError, which, - code, substring, response_substring) - return d - -class Web(WebMixin, testutil.StallMixin, unittest.TestCase): +class Web(WebMixin, WebErrorMixin, testutil.StallMixin, unittest.TestCase): def test_create(self): pass