Beispiel #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
Beispiel #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
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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
Beispiel #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)
Beispiel #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
Beispiel #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
Beispiel #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)
Beispiel #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
Beispiel #12
0
 def testTimeoutTriggering(self):
     return unittest.assertFailure(
         client.getPage(self.getURL("wait"), timeout=0.5),
         defer.TimeoutError)
Beispiel #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
Beispiel #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)
Beispiel #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