rendered paste bodyclass HTTP(twisted.web2.dav.test.util.TestCase): """ HTTP Utilities """ def test_statusForFailure_errno(self): """ statusForFailure() for exceptions with known errno values """ for ex_class in (IOError, OSError): for exception, result in ( (ex_class(errno.EACCES, "Permission denied" ), responsecode.FORBIDDEN), (ex_class(errno.EPERM , "Permission denied" ), responsecode.FORBIDDEN), (ex_class(errno.ENOSPC, "No space available"), responsecode.INSUFFICIENT_STORAGE_SPACE), (ex_class(errno.ENOENT, "No such file" ), responsecode.NOT_FOUND), ): self._check_exception(exception, result) def test_statusForFailure_HTTPError(self): """ statusForFailure() for HTTPErrors """ for code in responsecode.RESPONSES: self._check_exception(HTTPError(code), code) self._check_exception(HTTPError(ErrorResponse(code, ("http://twistedmatrix.com/", "bar"))), code) def test_statusForFailure_exception(self): """ statusForFailure() for known exceptions """ for exception, result in ( (NotImplementedError("Duh..."), responsecode.NOT_IMPLEMENTED), ): self._check_exception(exception, result) def _check_exception(self, exception, result): try: raise exception except Exception, e: failure = Failure() status = statusForFailure(failure) self.failUnless( status == result, "Failure %r (%s) generated incorrect status code: %s != %s" % (failure, failure.value, status, result) ) else: raise AssertionError("We shouldn't be here.")