Beispiel #1
0
 def test_HTTPException_server_error(self, LOGGER):
     exc = HTTPServerError()
     http_exc = exc_to_http_exc(exc)
     self.assertIs(http_exc, exc)
     self.assertEqual(http_exc.code, 500)
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, ANY, 500, exc_info=True),
     ])
Beispiel #2
0
 def test_HTTPException_no_server_error(self, LOGGER):
     exc = HTTPNotFound()
     http_exc = exc_to_http_exc(exc)
     self.assertIs(http_exc, exc)
     self.assertEqual(http_exc.code, 404)
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY, 404),
     ])
Beispiel #3
0
 def test_other_exception(self, LOGGER):
     exc = ZeroDivisionError
     http_exc = exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPServerError)
     self.assertEqual(http_exc.code, 500)
     self.assertIs(http_exc.detail, None)  # no detail
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, exc_info=True),
     ])
Beispiel #4
0
 def test_other_DataAPIError_2(self, LOGGER):
     exc = DataAPIError()  # no specific public message
     http_exc = exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPServerError)
     self.assertEqual(http_exc.code, 500)
     self.assertIs(http_exc.detail, None)  # *no* detail
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, ANY, exc_info=True),
     ])
Beispiel #5
0
 def test_other_DataAPIError(self, LOGGER):
     exc = DataAPIError(public_message='FOO')  # custom public message
     http_exc = exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPServerError)
     self.assertEqual(http_exc.code, 500)
     self.assertEqual(http_exc.detail,
                      'FOO')  # detail == custom public message
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, ANY, exc_info=True),
     ])
Beispiel #6
0
 def test_ParamCleaningError(self, LOGGER):
     exc = ParamCleaningError(public_message='FOO')  # custom public message
     http_exc = exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPBadRequest)
     self.assertEqual(http_exc.code, 400)
     self.assertEqual(http_exc.detail,
                      'FOO')  # detail == custom public message
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
Beispiel #7
0
 def test_TooMuchDataError(self, LOGGER):
     exc = TooMuchDataError(public_message='FOO')  # custom public message
     http_exc = exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPForbidden)
     self.assertEqual(http_exc.code, 403)
     self.assertEqual(http_exc.detail,
                      'FOO')  # detail == custom public message
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
Beispiel #8
0
 def test_ParamCleaningError_2(self, LOGGER):
     exc = ParamCleaningError()  # no specific public message
     http_exc = exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPBadRequest)
     self.assertEqual(http_exc.code, 400)
     self.assertEqual(
         http_exc.detail,  # detail == default public message
         ParamCleaningError.default_public_message)
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
Beispiel #9
0
 def test_TooMuchDataError_2(self, LOGGER):
     exc = TooMuchDataError()  # no specific public message
     http_exc = exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPForbidden)
     self.assertEqual(http_exc.code, 403)
     self.assertEqual(
         http_exc.detail,  # detail == default public message
         TooMuchDataError.default_public_message)
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
Beispiel #10
0
    def test_subclass_of_DataLookupError_3(self, LOGGER):
        class MyCustomError(DataLookupError):
            default_public_message = 'own_default'

        exc = MyCustomError(public_message='FOO')  # custom public message
        http_exc = exc_to_http_exc(exc)
        self.assertIsInstance(http_exc, HTTPNotFound)
        self.assertEqual(http_exc.code, 404)
        self.assertEqual(http_exc.detail,
                         'FOO')  # detail == custom public message
        self.assertEqual(LOGGER.mock_calls, [
            call.debug(ANY, exc, ANY),
        ])
Beispiel #11
0
    def test_subclass_of_DataLookupError_2(self, LOGGER):
        class MyCustomError(DataLookupError):
            pass

        exc = MyCustomError()  # no specific public message
        http_exc = exc_to_http_exc(exc)
        self.assertIsInstance(http_exc, HTTPNotFound)
        self.assertEqual(http_exc.code, 404)
        self.assertEqual(
            http_exc.
            detail,  # detail == `DataLookupError.default public message`
            DataLookupError.default_public_message)
        self.assertEqual(LOGGER.mock_calls, [
            call.debug(ANY, exc, ANY),
        ])