def test_without_auto_report_exceptions(self, mock_hb): FlaskHoneybadger(self.app, report_exceptions=False) @self.app.route('/error') def error(): return 1 / 0 self.app.test_client().get('/error?a=1&b=2&b=3') mock_hb.notify.assert_not_called()
def test_with_auto_report_exceptions(self, mock_hb): FlaskHoneybadger(self.app, report_exceptions=True) @self.app.route('/error') def error(): return 1 / 0 self.app.test_client().get('/error?a=1&b=2&b=3') self.assert_called_with_exception_type(mock_hb, ZeroDivisionError)
def test_auto_report_exceptions_with_view_class(self, mock_hb): from flask.views import MethodView FlaskHoneybadger(self.app, report_exceptions=True) class ErrorView(MethodView): def get(self): return 1 / 0 self.app.add_url_rule('/error', view_func=ErrorView.as_view('error')) self.app.test_client().get('/error?a=1&b=2&b=3') self.assert_called_with_exception_type(mock_hb, ZeroDivisionError)
def test_auto_report_exceptions_with_blueprint(self, mock_hb): from flask import Blueprint FlaskHoneybadger(self.app, report_exceptions=True) bp = Blueprint('blueprint', __name__) @bp.route('/error') def error(): return 1 / 0 self.app.register_blueprint(bp) self.app.test_client().get('/error?a=1&b=2&b=3') self.assert_called_with_exception_type(mock_hb, ZeroDivisionError)
def test_reset_context_when_reporting(self, mock_hb): from flask.views import MethodView FlaskHoneybadger(self.app, report_exceptions=True, reset_context_after_request=True) honeybadger.set_context(foo='bar') class ErrorView(MethodView): def get(self): return 1 / 0 self.app.add_url_rule('/error', view_func=ErrorView.as_view('error')) self.app.test_client().get('/error?a=1&b=2&b=3') self.assert_called_with_exception_type(mock_hb, ZeroDivisionError) self.assertEqual(2, mock_hb.reset_context.call_count)
def test_dont_reset_context_when_not_reporting(self, mock_hb): from flask.views import MethodView FlaskHoneybadger(self.app, report_exceptions=False, reset_context_after_request=False) honeybadger.set_context(foo='bar') class ErrorView(MethodView): def get(self): return 1 / 0 self.app.add_url_rule('/error', view_func=ErrorView.as_view('error')) self.app.test_client().get('/error?a=1&b=2&b=3') mock_hb.notify.assert_not_called() mock_hb.reset_context.assert_not_called()