From: Brian Warner Date: Wed, 4 Mar 2009 02:40:59 +0000 (-0700) Subject: test/common: rearrange shouldHTTPError X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/%22doc.html/architecture.txt?a=commitdiff_plain;h=53f50fcc78be5bba71028f9524f7bedb4ce0f2c9;p=tahoe-lafs%2Ftahoe-lafs.git test/common: rearrange shouldHTTPError --- diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index d0dad7a4..03d5a2dd 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -1075,32 +1075,35 @@ class WebErrorMixin: print "Web Error:", f.value, ":", f.value.response return f - def _shouldHTTPError(self, res, which, code=None, substring=None, - response_substring=None): + def _shouldHTTPError(self, res, which, validator): 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)) + return validator(res) else: - self.fail("%s was supposed to Error(%s), not get '%s'" % - (which, code, res)) + self.fail("%s was supposed to Error, not get '%s'" % (which, res)) def shouldHTTPError(self, which, code=None, substring=None, response_substring=None, callable=None, *args, **kwargs): + # returns a Deferred with the response body assert substring is None or isinstance(substring, str) assert callable + def _validate(f): + if code is not None: + self.failUnlessEqual(f.value.status, str(code)) + if substring: + code_string = str(f) + self.failUnless(substring in code_string, + "substring '%s' not in '%s'" + % (substring, code_string)) + response_body = f.value.response + if response_substring: + self.failUnless(response_substring in response_body, + "response substring '%s' not in '%s'" + % (response_substring, response_body)) + return response_body d = defer.maybeDeferred(callable, *args, **kwargs) - d.addBoth(self._shouldHTTPError, which, - code, substring, response_substring) + d.addBoth(self._shouldHTTPError, which, _validate) return d class ErrorMixin(WebErrorMixin):