Example #1
0
def test_sentry_report_developer_mode(raven_client_mock, importlib_mock):
    traceback = mock.Mock()
    importlib_mock.util.find_spec.return_value = False

    sentry_report(CustomException, 69, traceback)

    assert raven_client_mock.captureException.call_count == 0
Example #2
0
def test_sentry_report_developer_mode(raven_client_mock, stoqserver_mock):
    traceback = mock.Mock()
    stoqserver_mock.library.uninstalled = True

    sentry_report(CustomException, 69, traceback)

    assert raven_client_mock.captureException.call_count == 0
Example #3
0
def test_sentry_report_without_user_context(raven_client_mock, importlib_mock):
    traceback = mock.Mock()
    importlib_mock.util.find_spec.return_value = True
    del raven_client_mock.user_context

    sentry_report(CustomException, 69, traceback)

    assert raven_client_mock.captureException.call_count == 1
Example #4
0
def test_sentry_report(raven_client_mock, stoqserver_mock):
    traceback = mock.Mock()
    stoqserver_mock.library.uninstalled = False

    sentry_report(CustomException, 69, traceback)

    assert raven_client_mock.user_context.call_count == 1
    assert raven_client_mock.captureException.call_count == 1
Example #5
0
    def unhandled_exception(e):
        traceback_info = "\n".join(traceback.format_tb(e.__traceback__))
        traceback_hash = hashlib.sha1(traceback_info.encode('utf-8')).hexdigest()[:8]
        traceback_exception = traceback.format_exception_only(type(e), e)[-1]
        timestamp = localnow().strftime('%Y%m%d-%H%M%S')

        logger.exception('Unhandled Exception: {timestamp} {error} {traceback_hash}'.format(
            timestamp=timestamp, error=e, traceback_hash=traceback_hash))

        sentry_report(type(e), e, e.__traceback__, traceback_hash=traceback_hash)

        return Response(json.dumps({'error': _('bad request!'), 'timestamp': timestamp,
                                    'exception': traceback_exception,
                                    'traceback_hash': traceback_hash}),
                        500, mimetype='application/json')