Beispiel #1
0
    def test_calls_from_kwargs(self, build_opener, update):
        event = Event(
            data={
                'sentry.interfaces.Stacktrace': {
                    'frames': [
                        {
                            'abs_path': 'http://example.com/foo.js',
                            'filename': 'foo.js',
                            'lineno': 4,
                            'colno': 0,
                        },
                        {
                            'abs_path': 'http://example.com/foo.js',
                            'filename': 'foo.js',
                            'lineno': 1,
                            'colno': 0,
                        },
                    ],
                },
            })
        build_opener.return_value.open.return_value.read.return_value = '\n'.join(
            'hello world')

        fetch_javascript_source(event)

        build_opener.assert_called_once_with()
        build_opener.return_value.open.assert_called_once_with(
            'http://example.com/foo.js')
        build_opener.return_value.open.return_value.read.assert_called_once_with(
        )
        update.assert_called_once_with(data=event.data)

        frame_list = event.data['sentry.interfaces.Stacktrace']['frames']
        frame = frame_list[0]
        assert frame['pre_context'] == ['h', 'e', 'l']
        assert frame['context_line'] == 'l'
        assert frame['post_context'] == ['o', ' ', 'w', 'o', 'r']

        frame = frame_list[1]
        assert frame['pre_context'] == []
        assert frame['context_line'] == 'h'
        assert frame['post_context'] == ['e', 'l', 'l', 'o', ' ']
Beispiel #2
0
    def test_calls_from_kwargs(self, build_opener, save):
        event = Event(data={
            'sentry.interfaces.Stacktrace': {
                'frames': [
                    {
                        'abs_path': 'http://example.com/foo.js',
                        'filename': 'foo.js',
                        'lineno': 4,
                        'colno': 0,
                    },
                    {
                        'abs_path': 'http://example.com/foo.js',
                        'filename': 'foo.js',
                        'lineno': 1,
                        'colno': 0,
                    },
                ],
            },
        })
        build_opener.return_value.open.return_value.read.return_value = '\n'.join('hello world')

        fetch_javascript_source(event)

        build_opener.assert_called_once_with()
        build_opener.return_value.open.assert_called_once_with('http://example.com/foo.js')
        build_opener.return_value.open.return_value.read.assert_called_once_with()
        save.assert_called_once_with()

        frame_list = event.data['sentry.interfaces.Stacktrace']['frames']
        frame = frame_list[0]
        assert frame['pre_context'] == ['h', 'e', 'l']
        assert frame['context_line'] == 'l'
        assert frame['post_context'] == ['o', ' ', 'w', 'o', 'r']

        frame = frame_list[1]
        assert frame['pre_context'] == []
        assert frame['context_line'] == 'h'
        assert frame['post_context'] == ['e', 'l', 'l', 'o', ' ']
Beispiel #3
0
    def test_calls_from_kwargs(self, fetch_sourcemap, fetch_url, update):
        event = Event(data={
            'sentry.interfaces.Stacktrace': {
                'frames': [
                    {
                        'abs_path': 'http://example.com/foo.js',
                        'filename': 'foo.js',
                        'lineno': 4,
                        'colno': 0,
                    },
                    {
                        'abs_path': 'http://example.com/foo.js',
                        'filename': 'foo.js',
                        'lineno': 1,
                        'colno': 0,
                    },
                ],
            },
        })
        fetch_sourcemap.return_value = None
        fetch_url.return_value.body = '\n'.join('hello world')

        fetch_javascript_source(event)

        fetch_url.assert_called_once_with('http://example.com/foo.js')
        update.assert_called_once_with(data=event.data)

        frame_list = event.interfaces['sentry.interfaces.Stacktrace'].frames
        frame = frame_list[0]
        assert frame.pre_context == ['h', 'e', 'l']
        assert frame.context_line == 'l'
        assert frame.post_context == ['o', ' ', 'w', 'o', 'r']

        frame = frame_list[1]
        assert frame.pre_context == []
        assert frame.context_line == 'h'
        assert frame.post_context == ['e', 'l', 'l', 'o', ' ']