Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 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"))
Exemple #6
0
 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)
Exemple #7
0
 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)
Exemple #8
0
 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"))
Exemple #9
0
 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)
Exemple #10
0
 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)
Exemple #11
0
 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"))
Exemple #12
0
 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"))
Exemple #13
0
 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)
Exemple #14
0
 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)
Exemple #15
0
 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"))
Exemple #16
0
 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"))