]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_web: move shouldHTTPError into common.WebErrorMixin
authorBrian Warner <warner@lothar.com>
Tue, 3 Mar 2009 23:56:20 +0000 (16:56 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 3 Mar 2009 23:56:20 +0000 (16:56 -0700)
src/allmydata/test/common.py
src/allmydata/test/test_web.py

index be0834d063018062985f301d3e7af1899b8bab37..b4401568eedc73c499004d2bfd917a8c234cf883 100644 (file)
@@ -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):
index fc350658799012eff2cc3af08776bec7144d8259..a7f882f33f3e19a3b45c29338073f42040c8ef4f 100644 (file)
@@ -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