def testFailureFinishesRequest(self): """ The C{Request.finish} method is invoked if a non-connection-related C{Failure} causes error handling logic to be invoked. """ failure = Failure(Exception("Another failure occurred.")) handleRequestError(failure, self.request, self.resource) self.assertTrue(self.request.finished)
def testFailureFinishesRequest(self): """ The C{Request.finish} method is invoked if a non-connection-related C{Failure} causes error handling logic to be invoked. """ failure = Failure(Exception("Another failure occurred.")) handleRequestError(failure, self.request, self.resource) self.assertTrue(self.request.finished)
def testUnknownErrorTypeReturnsInternalServerErrorHTTPStatus(self): """ If the exception that caused L{handleRequestError} to be invoked is of an unexpected type, the HTTP response code will be set to C{INTERNAL_SERVER_ERROR}. """ failure = Failure(Exception("Unknown error occurred.")) handleRequestError(failure, self.request, self.resource) self.assertEqual(INTERNAL_SERVER_ERROR, self.request.status)
def testKnownErrorTypeReturnsAppropriateHTTPStatus(self): """ If the exception that caused L{handleRequestError} to be invoked is of a wellknown type, the HTTP response code will be set appropriately. """ failure = Failure(ContentSeekError("Client disconnected immediately.")) handleRequestError(failure, self.request, self.resource) self.assertEqual(BAD_REQUEST, self.request.status)
def testFailureReportsRequestID(self): """ The unique request ID is included in HTTP response headers when a failure occurs. """ failure = Failure(Exception("Another failure occurred.")) handleRequestError(failure, self.request, self.resource) self.assertEqual( "xxx", self.request.getResponseHeader("X-FluidDB-Request-Id"))
def testUnknownErrorTypeReturnsInternalServerErrorHTTPStatus(self): """ If the exception that caused L{handleRequestError} to be invoked is of an unexpected type, the HTTP response code will be set to C{INTERNAL_SERVER_ERROR}. """ failure = Failure(Exception("Unknown error occurred.")) handleRequestError(failure, self.request, self.resource) self.assertEqual(INTERNAL_SERVER_ERROR, self.request.status)
def testKnownErrorTypeReturnsAppropriateHTTPStatus(self): """ If the exception that caused L{handleRequestError} to be invoked is of a wellknown type, the HTTP response code will be set appropriately. """ failure = Failure(ContentSeekError("Client disconnected immediately.")) handleRequestError(failure, self.request, self.resource) self.assertEqual(BAD_REQUEST, self.request.status)
def testFailureReportsRequestID(self): """ The unique request ID is included in HTTP response headers when a failure occurs. """ failure = Failure(Exception("Another failure occurred.")) handleRequestError(failure, self.request, self.resource) self.assertEqual( "xxx", self.request.getResponseHeader("X-FluidDB-Request-Id"))
def testDelayedDisconnectDoesNotFinishRequest(self): """ A C{CancelledError} exception is raised if content cannot be read from the request midway through processing, due to the client disconnecting. In such cases, the C{Request.finish} method is not invoked by the L{handleRequestError} handler to avoid causing a failure in Twisted. """ failure = Failure(CancelledError("Client disconnected partway.")) handleRequestError(failure, self.request, self.resource) self.assertFalse(self.request.finished)
def testImmediateDisconnectDoesNotFinishRequest(self): """ A L{ContentSeekError} exception is raised if content cannot be read from the request, such as when a client disconnected immediately. In such cases, the C{Request.finish} method is not invoked by the L{handleRequestError} handler to avoid causing a failure in Twisted. """ failure = Failure(ContentSeekError("Client disconnected immediately.")) handleRequestError(failure, self.request, self.resource) self.assertFalse(self.request.finished)
def testUnknownErrorTypeReportsInternalServerErrorClass(self): """ If an unknown exception causes L{handleRequestError} to run the C{X-FluidDB-Error-Class} HTTP response header will be set to C{InternalServerError}. """ failure = Failure(Exception("Unknown error occurred.")) handleRequestError(failure, self.request, self.resource) self.assertEqual( "InternalServerError", self.request.getResponseHeader("X-FluidDB-Error-Class"))
def testKnownErrorTypeReportsErrorClass(self): """ If a known exception causes L{handleRequestError} to run the C{X-FluidDB-Error-Class} HTTP response header will be set with the name of the exception class. """ failure = Failure(ContentSeekError("Client disconnected immediately.")) handleRequestError(failure, self.request, self.resource) self.assertEqual( "ContentSeekError", self.request.getResponseHeader("X-FluidDB-Error-Class"))
def testDelayedDisconnectDoesNotFinishRequest(self): """ A C{CancelledError} exception is raised if content cannot be read from the request midway through processing, due to the client disconnecting. In such cases, the C{Request.finish} method is not invoked by the L{handleRequestError} handler to avoid causing a failure in Twisted. """ failure = Failure(CancelledError("Client disconnected partway.")) handleRequestError(failure, self.request, self.resource) self.assertFalse(self.request.finished)
def testImmediateDisconnectDoesNotFinishRequest(self): """ A L{ContentSeekError} exception is raised if content cannot be read from the request, such as when a client disconnected immediately. In such cases, the C{Request.finish} method is not invoked by the L{handleRequestError} handler to avoid causing a failure in Twisted. """ failure = Failure(ContentSeekError("Client disconnected immediately.")) handleRequestError(failure, self.request, self.resource) self.assertFalse(self.request.finished)
def testUnknownErrorTypeReportsInternalServerErrorClass(self): """ If an unknown exception causes L{handleRequestError} to run the C{X-FluidDB-Error-Class} HTTP response header will be set to C{InternalServerError}. """ failure = Failure(Exception("Unknown error occurred.")) handleRequestError(failure, self.request, self.resource) self.assertEqual( "InternalServerError", self.request.getResponseHeader("X-FluidDB-Error-Class"))
def testKnownErrorTypeReportsErrorClass(self): """ If a known exception causes L{handleRequestError} to run the C{X-FluidDB-Error-Class} HTTP response header will be set with the name of the exception class. """ failure = Failure(ContentSeekError("Client disconnected immediately.")) handleRequestError(failure, self.request, self.resource) self.assertEqual( "ContentSeekError", self.request.getResponseHeader("X-FluidDB-Error-Class"))