Ejemplo n.º 1
0
 def _cbRedirect(self, pageData):
     self.assertEquals(pageData, "0123456789")
     d = unittest.assertFailure(
         client.getPage(self.getURL("redirect"), followRedirect=0),
         error.PageRedirect)
     d.addCallback(self._cbCheckLocation)
     return d
Ejemplo n.º 2
0
 def _cbRedirect(self, pageData):
     self.assertEquals(pageData, "0123456789")
     d = unittest.assertFailure(
         client.getPage(self.getURL("redirect"), followRedirect=0),
         error.PageRedirect)
     d.addCallback(self._cbCheckLocation)
     return d
Ejemplo n.º 3
0
 def _downloadTest(self, method):
     dl = []
     for (url, code) in [("nosuchfile", "404"), ("error", "401"),
                         ("error?showlength=1", "401")]:
         d = method(url)
         d = unittest.assertFailure(d, error.Error)
         d.addCallback(lambda exc, code=code: self.assertEquals(exc.args[0], code))
         dl.append(d)
     return defer.DeferredList(dl, fireOnOneErrback=True)
Ejemplo n.º 4
0
 def testDownloadPageError2(self):
     class errorfile:
         def write(self, data):
             pass
         def close(self):
             raise IOError, "badness happened during close"
     ef = errorfile()
     return unittest.assertFailure(
         client.downloadPage(self.getURL("file"), ef),
         IOError)
Ejemplo n.º 5
0
 def _downloadTest(self, method):
     dl = []
     for (url, code) in [("nosuchfile", "404"), ("error", "401"),
                         ("error?showlength=1", "401")]:
         d = method(url)
         d = unittest.assertFailure(d, error.Error)
         d.addCallback(
             lambda exc, code=code: self.assertEquals(exc.args[0], code))
         dl.append(d)
     return defer.DeferredList(dl, fireOnOneErrback=True)
Ejemplo n.º 6
0
 def testDownloadPageError3(self):
     if not os.geteuid():
         raise unittest.SkipTest('this does not work as root')
     tmpfile = open("unwritable", "wb")
     tmpfile.close()
     os.chmod("unwritable", 0) # make it unwritable (to us)
     d = unittest.assertFailure(
         client.downloadPage(self.getURL("file"), "unwritable"),
         IOError)
     d.addBoth(self._cleanupDownloadPageError3)
     return d
Ejemplo n.º 7
0
    def testDownloadPageError2(self):
        class errorfile:
            def write(self, data):
                pass

            def close(self):
                raise IOError, "badness happened during close"

        ef = errorfile()
        return unittest.assertFailure(
            client.downloadPage(self.getURL("file"), ef), IOError)
Ejemplo n.º 8
0
 def testDownloadPageError3(self):
     if not os.geteuid():
         raise unittest.SkipTest('this does not work as root')
     # make sure failures in open() are caught too. This is tricky.
     # Might only work on posix.
     tmpfile = open("unwritable", "wb")
     tmpfile.close()
     os.chmod("unwritable", 0)  # make it unwritable (to us)
     d = unittest.assertFailure(
         client.downloadPage(self.getURL("file"), "unwritable"), IOError)
     d.addBoth(self._cleanupDownloadPageError3)
     return d
Ejemplo n.º 9
0
 def testDownloadPageError3(self):
     if not os.geteuid():
         raise unittest.SkipTest('this does not work as root')
     # make sure failures in open() are caught too. This is tricky.
     # Might only work on posix.
     tmpfile = open("unwritable", "wb")
     tmpfile.close()
     os.chmod("unwritable", 0) # make it unwritable (to us)
     d = unittest.assertFailure(
         client.downloadPage(self.getURL("file"), "unwritable"),
         IOError)
     d.addBoth(self._cleanupDownloadPageError3)
     return d
Ejemplo n.º 10
0
 def testTimeoutTriggering(self):
     # Test that when the timeout does trigger, we get a defer.TimeoutError.
     return unittest.assertFailure(
         client.getPage(self.getURL("wait"), timeout=0.5),
         defer.TimeoutError)
Ejemplo n.º 11
0
 def testBrokenDownload(self):
     # test what happens when download gets disconnected in the middle
     d = client.getPage(self.getURL("broken"))
     d = unittest.assertFailure(d, client.PartialDownloadError)
     d.addCallback(lambda exc: self.assertEquals(exc.response, "abc"))
     return d
Ejemplo n.º 12
0
 def testTimeoutTriggering(self):
     return unittest.assertFailure(
         client.getPage(self.getURL("wait"), timeout=0.5),
         defer.TimeoutError)
Ejemplo n.º 13
0
 def testBrokenDownload(self):
     d = client.getPage(self.getURL("broken"))
     d = unittest.assertFailure(d, client.PartialDownloadError)
     d.addCallback(lambda exc: self.assertEquals(exc.response, "abc"))
     return d
Ejemplo n.º 14
0
 def testTimeoutTriggering(self):
     # Test that when the timeout does trigger, we get a defer.TimeoutError.
     return unittest.assertFailure(
         client.getPage(self.getURL("wait"), timeout=0.5),
         defer.TimeoutError)
Ejemplo n.º 15
0
 def testBrokenDownload(self):
     # test what happens when download gets disconnected in the middle
     d = client.getPage(self.getURL("broken"))
     d = unittest.assertFailure(d, client.PartialDownloadError)
     d.addCallback(lambda exc: self.assertEquals(exc.response, "abc"))
     return d