Ejemplo n.º 1
0
def test_before_send_scrubber_exists(sentry_reporter: SentryReporter):
    # test that in case of a set scrubber, it will be called for scrubbing an event
    event = {'some': 'event'}

    sentry_reporter.global_strategy = SentryStrategy.SEND_ALLOWED
    sentry_reporter.scrubber = Mock()
    assert sentry_reporter._before_send(event, None)
    sentry_reporter.scrubber.scrub_event.assert_called_with(event)
Ejemplo n.º 2
0
def test_before_send_scrubber_doesnt_exists(sentry_reporter: SentryReporter):
    # test that in case of a missed scrubber, it will not be called
    sentry_reporter.scrubber = None
    sentry_reporter.global_strategy = SentryStrategy.SEND_ALLOWED
    assert sentry_reporter._before_send({'some': 'event'}, None)
Ejemplo n.º 3
0
def test_before_send_allowed(sentry_reporter: SentryReporter):
    # test that in case of strategy==SentryStrategy.SEND_ALLOWED, the event will be
    # sent without a confirmation
    sentry_reporter.global_strategy = SentryStrategy.SEND_ALLOWED
    assert sentry_reporter._before_send({'some': 'event'}, None)
Ejemplo n.º 4
0
def test_before_send_allowed_with_confiration(sentry_reporter: SentryReporter):
    # test that in case of strategy==SentryStrategy.SEND_ALLOWED_WITH_CONFIRMATION, the event will be
    # sent after the positive confirmation
    sentry_reporter.global_strategy = SentryStrategy.SEND_ALLOWED_WITH_CONFIRMATION
    assert sentry_reporter._before_send({'some': 'event'}, None)
Ejemplo n.º 5
0
def test_before_send_suppressed(sentry_reporter: SentryReporter):
    # test that in case of strategy==SentryStrategy.SEND_SUPPRESSED, the event will be stored in `self.last_event`
    sentry_reporter.global_strategy = SentryStrategy.SEND_SUPPRESSED
    assert not sentry_reporter._before_send({'some': 'event'}, None)
    assert sentry_reporter.last_event == {'some': 'event'}
Ejemplo n.º 6
0
def test_before_send_ignored_exceptions(sentry_reporter: SentryReporter):
    # test that in case of an ignored exception, `_before_send` will return None
    assert not sentry_reporter._before_send({'some': 'event'},
                                            {'exc_info': [KeyboardInterrupt]})
Ejemplo n.º 7
0
def test_before_send_no_event(sentry_reporter: SentryReporter):
    # test that in case of a None event, `_before_send` will never fail
    assert not sentry_reporter._before_send(None, None)
Ejemplo n.º 8
0
def test_before_send():
    SentryReporter.thread_strategy.set(None)  # default

    scrubber = SentryScrubber()
    SentryReporter.init('', scrubber=scrubber)

    # pylint: disable=protected-access
    SentryReporter.last_event = None

    assert SentryReporter._before_send({}, {}) == {}
    assert SentryReporter._before_send(None, {}) is None
    assert SentryReporter._before_send(None, None) is None

    SentryReporter.global_strategy = SentryStrategy.SEND_SUPPRESSED
    assert SentryReporter.last_event is None

    # check that an event is stored
    assert SentryReporter._before_send({'a': 'b'}, None) is None
    assert SentryReporter.last_event == {'a': 'b'}

    # check an event has been processed
    SentryReporter.global_strategy = SentryStrategy.SEND_ALLOWED
    assert SentryReporter._before_send({'c': 'd'}, None) == {'c': 'd'}
    assert SentryReporter.last_event == {'a': 'b'}

    # check that event can be ignored
    assert SentryReporter._before_send(
        {'a': 'b'}, {'exc_info': [KeyboardInterrupt]}) is None

    # check information has been scrubbed
    assert SentryReporter._before_send(
        {'contexts': {
            'reporter': {
                '_stacktrace': ['/Users/username/']
            }
        }}, None) == {
            'contexts': {
                'reporter': {
                    '_stacktrace': [f'/Users/{scrubber.placeholder_user}/']
                }
            }
        }

    # check release
    assert SentryReporter._before_send({'release': '7.6.0'}, None) == {
        'release': '7.6.0'
    }
    assert SentryReporter._before_send({'release': '7.6.0-GIT'}, None) == {
        'release': None
    }

    # check confirmation
    SentryReporter.global_strategy = SentryStrategy.SEND_ALLOWED_WITH_CONFIRMATION
    SentryReporter.get_confirmation = lambda e: False
    assert SentryReporter._before_send({'a': 'b'}, None) is None

    SentryReporter.get_confirmation = lambda e: True
    assert SentryReporter._before_send({'a': 'b'}, None) == {'a': 'b'}