def test_wrap_controller_exception_with_client_error(self): error_args = dict(reason="foo") expected_error_msg = six.text_type( exception.BadRequest.msg_fmt % error_args) def error_func(): raise exception.BadRequest(**error_args) try: exception.wrap_wsme_controller_exception(error_func)() self.assertTrue(False) except wsme.exc.ClientSideError as e: self.assertEqual(e.msg, expected_error_msg)
def test_wrap_controller_exception_with_client_error(self): error_args = dict(reason="foo") expected_error_msg = six.text_type( exception.BadRequest.msg_fmt % error_args) def error_func(): raise exception.BadRequest(**error_args) try: exception.wrap_wsme_controller_exception(error_func)() self.assertTrue(False) except wsme.exc.ClientSideError as e: self.assertEqual(expected_error_msg, e.msg)
def test_wrap_controller_exception_with_server_error(self): exception.LOG.error = mock.Mock() def error_func(): raise exception.NotImplemented() correlation_id = None try: exception.wrap_wsme_controller_exception(error_func)() except wsme.exc.ClientSideError as e: correlation_id = six.text_type(e).split(":")[1].strip() self.assertIsNotNone(correlation_id) self.assertIsInstance(uuid.UUID(correlation_id), uuid.UUID) self.assertTrue(exception.LOG.error.called) (args, kargs) = exception.LOG.error.call_args self.assertTrue(correlation_id in args) self.assertTrue(correlation_id in str(args[0] % args[1:]))
def test_wrap_controller_exception_with_server_error(self): exception.LOG.error = mock.Mock() def error_func(): raise exception.NotImplemented() correlation_id = None try: exception.wrap_wsme_controller_exception(error_func)() except wsme.exc.ClientSideError as e: correlation_id = six.text_type(e).split(":")[1].strip() self.assertIsNotNone(correlation_id) self.assertIsInstance(uuid.UUID(correlation_id), uuid.UUID) self.assertTrue(exception.LOG.error.called) (args, kargs) = exception.LOG.error.call_args self.assertIn(correlation_id, args) self.assertIn(correlation_id, str(args[0] % args[1:]))
def test_wrap_controller_exception_with_uncatched_error(self): exception.LOG.error = mock.Mock() def error_func(): raise ValueError('Hey!') correlation_id = None try: exception.wrap_wsme_controller_exception(error_func)() except wsme.exc.ClientSideError as e: correlation_id = e.message.split(":")[1].strip() self.assertIsNotNone(correlation_id) self.assertIsInstance(uuid.UUID(correlation_id), uuid.UUID) self.assertTrue(exception.LOG.error.called) (args, kargs) = exception.LOG.error.call_args self.assertTrue(correlation_id in args) self.assertTrue(correlation_id in str(args[0] % args[1:]))
def test_wrap_controller_exception_with_uncatched_error(self): exception.LOG.error = mock.Mock() def error_func(): value_error = ValueError('Hey!') value_error.code = 500 raise value_error correlation_id = None try: exception.wrap_wsme_controller_exception(error_func)() except wsme.exc.ClientSideError as e: correlation_id = six.text_type(e).split(":")[1].strip() self.assertIsNotNone(correlation_id) self.assertIsInstance(uuid.UUID(correlation_id), uuid.UUID) self.assertTrue(exception.LOG.error.called) (args, kargs) = exception.LOG.error.call_args self.assertIn(correlation_id, args) self.assertIn(correlation_id, str(args[0] % args[1:]))