]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
webish: improve test coverage of WebDownloadTarget
authorBrian Warner <warner@lothar.com>
Tue, 17 Jul 2007 19:16:45 +0000 (12:16 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 17 Jul 2007 19:16:45 +0000 (12:16 -0700)
src/allmydata/test/test_web.py
src/allmydata/webish.py

index f39e00cefc3ccfc611c745234e66b7aa0cdcc7dd..f90cb6dad6c6e372dd2b4cd015c80d909a6fbb57 100644 (file)
@@ -4,7 +4,7 @@ from zope.interface import implements
 from twisted.application import service
 from twisted.trial import unittest
 from twisted.internet import defer
-from twisted.web import client, error
+from twisted.web import client, error, http
 from twisted.python import failure, log
 from allmydata import webish, interfaces, dirnode, uri
 from allmydata.encode import NotEnoughPeersError
@@ -186,6 +186,9 @@ class Web(unittest.TestCase):
         baz_file = self.makefile(2)
         sub.children["baz.txt"] = baz_file
 
+        self._bad_file_uri = self.makefile(3)
+        del self.files[self._bad_file_uri]
+
         rodir = self.makedir()
         rodir._mutable = False
         v.public_root.children["readonly"] = rodir.get_uri()
@@ -334,6 +337,24 @@ class Web(unittest.TestCase):
             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,
+                                "respose 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 test_create(self): # YES
         pass
 
@@ -956,9 +977,14 @@ class Web(unittest.TestCase):
         return d
 
     def test_GET_URI_URL_missing(self): # YES
-        base = "/uri/missing?t=json"
+        base = "/uri/%s" % self._bad_file_uri.replace("/","!")
         d = self.GET(base)
-        d.addBoth(self.should404, "test_GET_URI_URL_missing")
+        d.addBoth(self.shouldHTTPError, "test_GET_URI_URL_missing",
+                  http.GONE, response_substring="NotEnoughPeersError")
+        # TODO: how can we exercise both sides of WebDownloadTarget.fail
+        # here? we must arrange for a download to fail after target.open()
+        # has been called, and then inspect the response to see that it is
+        # shorter than we expected.
         return d
 
     def test_PUT_NEWFILEURL_uri(self): # YES
index 2283d591e819e8d7aae88b1af87b214aa7b1f55b..0dee3288fd3db24297c034748c8d69da0722f3b4 100644 (file)
@@ -237,7 +237,7 @@ class WebDownloadTarget:
             # error message.
             msg = str(why.type)
             msg.replace("\n", "|")
-            self._req.setResponseCode(http.INTERNAL_SERVER_ERROR, msg)
+            self._req.setResponseCode(http.GONE, msg)
             self._req.setHeader("content-type", "text/plain")
             # TODO: HTML-formatted exception?
             self._req.write(str(why))