def test_cannot_unset_mixin(self): # Reset mixins flask_reportable_error.config.mixins = set() exc = flask_reportable_error.reportable(ValueError) self.assertTrue(issubclass(exc, ValueError)) self.assertTrue( issubclass(exc, flask_reportable_error.ReportableErrorMixin))
def test_custom_headers(self): class ExceptionWithHeaders(ValueError): headers = {'Content-Type': 'plain/text'} exc = flask_reportable_error.reportable(ExceptionWithHeaders)( 'some value error') report, status_code, headers = self.handler(exc) self.assertEqual(headers, {'Content-Type': 'plain/text'})
def test_handle_template(self, render_template): app = self.app app.config = { 'REPORTABLE_ERROR': { 'TEMPLATE': 'application/error.html', }, } flask_reportable_error.init(app) exc = flask_reportable_error.reportable(ValueError)('some value error') body, status_code, headers = self.handler(exc) render_template.assert_called_once_with('application/error.html', exc=exc) self.assertEqual(body, render_template.return_value)
def test_handle_default_headers(self): app = self.app app.config = { 'REPORTABLE_ERROR': { 'HEADERS': { 'Content-Type': 'plain/text' }, }, } flask_reportable_error.init(app) exc = flask_reportable_error.reportable(ValueError)('some value error') report, status_code, headers = self.handler(exc) self.assertEqual(headers, {'Content-Type': 'plain/text'})
def test_add_mixins(self): class Mixin(object): pass class SomeError2(ValueError): pass flask_reportable_error.add_mixins(Mixin) exc_class = flask_reportable_error.reportable(SomeError2) self.assertTrue(issubclass(exc_class, Mixin)) self.assertTrue(issubclass(exc_class, SomeError2)) self.assertTrue( issubclass(exc_class, flask_reportable_error.ReportableErrorMixin))
def test_mixin_decorator(self): @flask_reportable_error.mixin class Mixin(object): pass class SomeError1(ValueError): pass exc_class = flask_reportable_error.reportable(SomeError1) self.assertTrue(issubclass(exc_class, Mixin)) self.assertTrue(issubclass(exc_class, SomeError1)) self.assertTrue( issubclass(exc_class, flask_reportable_error.ReportableErrorMixin))
def test_reportable_factory_response_be_memoized(self): exc1 = flask_reportable_error.reportable(ValueError) exc2 = flask_reportable_error.reportable(ValueError) exc3 = flask_reportable_error.reportable(AttributeError) self.assertIs(exc1, exc2) self.assertNotEqual(exc1, exc3)
def test_reportable_factory_response_report_error(self): s = 'test reportable error' exc = flask_reportable_error.reportable(ValueError)(s) self.assertEqual(exc.report(), s)
def test_reportable_factory_return_reportable_error(self): exc_class = flask_reportable_error.reportable(ValueError) self.assertTrue( issubclass(exc_class, flask_reportable_error.ReportableErrorMixin)) self.assertTrue(issubclass(exc_class, ValueError))
def test_reportable_type_name(self): exc_class = flask_reportable_error.reportable(ValueError) self.assertEqual(exc_class.type_name, 'ValueError')