def test_polyerror(self): p = PolyStorageError('hell') try: try: raise NameError('dwight') except NameError: p.gather_current_exception() try: raise KeyError('wilma') except KeyError: p.gather_current_exception() try: raise AttributeError('sarita') except AttributeError: p.gather_current_exception() raise p except PolyStorageError, x: eq_(len(x), 3) ok_(x.has_exceptions()) types = [NameError, KeyError, AttributeError] [eq_(a[0], b) for a, b in zip(x, types)] ok_(1 not in x) ok_(str(x[0][1]), 'dwight') x[0] = x[1] eq_(x[0], x[1])
def test_polyerror(self): p = PolyStorageError('hell') try: try: raise NameError('dwight') except NameError: p.gather_current_exception() try: raise KeyError('wilma') except KeyError: p.gather_current_exception() try: raise AttributeError('sarita') except AttributeError: p.gather_current_exception() raise p except PolyStorageError as x: assert len(x) == 3 assert x.has_exceptions() expected = [NameError, KeyError, AttributeError] assert [exc[0] for exc in x] == expected assert 1 not in x assert str(x[0][1]) == 'dwight' assert all( sample in str(x) for sample in ['hell', 'NameError', 'KeyError', 'AttributeError'] ) x[0] = x[1] assert x[0] == x[1]
def test_polyerror_str_missing_args(self): p = PolyStorageError() try: try: raise NameError('dwight') except NameError: p.gather_current_exception() try: raise KeyError('wilma') except KeyError: p.gather_current_exception() raise p except PolyStorageError as x: assert str(x) == "NameError('dwight',),KeyError('wilma',)"
def test_polyerror(self): p = PolyStorageError("hell") try: try: raise NameError("dwight") except NameError: p.gather_current_exception() try: raise KeyError("wilma") except KeyError: p.gather_current_exception() try: raise AttributeError("sarita") except AttributeError: p.gather_current_exception() raise p except PolyStorageError as x: assert len(x) == 3 assert x.has_exceptions() expected = [NameError, KeyError, AttributeError] assert [exc[0] for exc in x] == expected assert 1 not in x assert str(x[0][1]) == "dwight" assert all(sample in str(x) for sample in ["hell", "NameError", "KeyError", "AttributeError"]) assert ( str(x) == "hell,NameError('dwight'),KeyError('wilma'),AttributeError('sarita')" ) x[0] = x[1] assert x[0] == x[1]
def test_transform_polystorage_error_with_raven_configured_failing( self, mock_raven): raven_mock_client = mock.MagicMock() # Mock this to throw an error if it's called because it shouldn't get called raven_mock_client.captureException.side_effect = ValueError( 'raven error') mock_raven.Client.return_value = raven_mock_client # Set up processor and mock .save_raw_and_processed() to raise an exception config = self.get_standard_config( sentry_dsn='https://[email protected]/project') pa = ProcessorApp(config) pa._setup_source_and_destination() pa.source.get_raw_crash.return_value = DotDict({'raw': 'crash'}) pa.source.get_raw_dumps_as_files.return_value = {} expected_exception = PolyStorageError() expected_exception.exceptions.append(NameError('waldo')) expected_exception.exceptions.append(AssertionError(False)) pa.destination.save_raw_and_processed.side_effect = expected_exception # Make sure the PolyStorageError is raised and not the error from # .captureException() with pytest.raises(PolyStorageError): pa.transform('mycrashid') # Assert that the logger logged raven isn't right config.logger.error.assert_called_with( 'Unable to report error with Raven', exc_info=True)
def test_transform_polystorage_error_with_sentry_configured_successful( self, is_enabled, mock_get_hub, caplogpp): caplogpp.set_level('DEBUG') # Mock everything mock_hub = mock.MagicMock() mock_hub.capture_exception.return_value = 'someidentifier' mock_get_hub.return_value = mock_hub # Set up a processor and mock out .save_raw_and_processed() with multiple # errors config = self.get_standard_config() pa = ProcessorApp(config) pa._setup_source_and_destination() pa.source.get_raw_crash.return_value = DotDict({'raw': 'crash'}) pa.source.get_raw_dumps_as_files.return_value = {} expected_exception = PolyStorageError() expected_exception.exceptions.append(NameError('waldo')) expected_exception.exceptions.append(AssertionError(False)) pa.destination.save_raw_and_processed.side_effect = expected_exception # The important thing is that this is the exception that is raised and # not something from the sentry error handling with pytest.raises(PolyStorageError): pa.transform('mycrashid') # Assert that we sent both exceptions to Sentry mock_hub.capture_exception.assert_has_calls( [mock.call(error=exc) for exc in expected_exception.exceptions]) # Assert that the logger logged the appropriate thing logging_msgs = [rec.message for rec in caplogpp.records] assert 'Error captured in Sentry! Reference: someidentifier' in logging_msgs
def test_transform_polystorage_error_with_raven_configured_successful(self, mock_raven): # Mock everything raven_mock_client = mock.MagicMock() raven_mock_client.captureException.return_value = 'someidentifier' mock_raven.Client.return_value = raven_mock_client # Set up a processor and mock out .save_raw_and_processed() with multiple # errors config = self.get_standard_config(sentry_dsn='https://[email protected]/project') pa = ProcessorApp(config) pa._setup_source_and_destination() pa.source.get_raw_crash.return_value = DotDict({'raw': 'crash'}) pa.source.get_raw_dumps_as_files.return_value = {} expected_exception = PolyStorageError() expected_exception.exceptions.append(NameError('waldo')) expected_exception.exceptions.append(AssertionError(False)) pa.destination.save_raw_and_processed.side_effect = expected_exception # The important thing is that this is the exception that is raised and # not something from the raven error handling with pytest.raises(PolyStorageError): pa.transform('mycrashid') # Assert that we sent both exceptions to Sentry raven_mock_client.captureException.assert_has_calls( [mock.call(exc) for exc in expected_exception.exceptions] ) # Assert that the logger logged the appropriate thing config.logger.info.assert_called_with( 'Error captured in Sentry! Reference: someidentifier' )
def test_polyerror(self): p = PolyStorageError('hell') try: try: raise NameError('dwight') except NameError: p.gather_current_exception() try: raise KeyError('wilma') except KeyError: p.gather_current_exception() try: raise AttributeError('sarita') except AttributeError: p.gather_current_exception() raise p except PolyStorageError, x: self.assertEqual(len(x), 3) self.assertTrue(x.has_exceptions()) types = [NameError, KeyError, AttributeError] [self.assertEqual(a[0], b) for a, b in zip(x, types)] self.assertTrue(1 not in x) self.assertTrue(str(x[0][1]), 'dwight') x[0] = x[1] self.assertEqual(x[0], x[1])
def test_polyerror(self): p = PolyStorageError('hell') try: try: raise NameError('dwight') except NameError: p.gather_current_exception() try: raise KeyError('wilma') except KeyError: p.gather_current_exception() try: raise AttributeError('sarita') except AttributeError: p.gather_current_exception() raise p except PolyStorageError as x: assert len(x) == 3 assert x.has_exceptions() expected = [NameError, KeyError, AttributeError] assert [exc[0] for exc in x] == expected assert 1 not in x assert str(x[0][1]) == 'dwight' assert all( sample in str(x) for sample in ['hell', 'NameError', 'KeyError', 'AttributeError'] ) assert ( str(x) == "hell,NameError('dwight',),KeyError('wilma',),AttributeError('sarita',)" ) x[0] = x[1] assert x[0] == x[1]
def test_polyerror(self): p = PolyStorageError("hell") try: try: raise NameError("dwight") except NameError: p.gather_current_exception() try: raise KeyError("wilma") except KeyError: p.gather_current_exception() try: raise AttributeError("sarita") except AttributeError: p.gather_current_exception() raise p except PolyStorageError, x: eq_(len(x), 3) ok_(x.has_exceptions()) types = [NameError, KeyError, AttributeError] [eq_(a[0], b) for a, b in zip(x, types)] ok_(1 not in x) ok_(str(x[0][1]), "dwight") x[0] = x[1] eq_(x[0], x[1])
def test_polyerror(self): p = PolyStorageError('hell') try: try: raise NameError('dwight') except NameError: p.gather_current_exception() try: raise KeyError('wilma') except KeyError: p.gather_current_exception() try: raise AttributeError('sarita') except AttributeError: p.gather_current_exception() raise p except PolyStorageError, x: eq_(len(x), 3) ok_(x.has_exceptions()) types = [NameError, KeyError, AttributeError] [eq_(a[0], b) for a, b in zip(x, types)] ok_(1 not in x) ok_(str(x[0][1]), 'dwight') ok_( all(sample in str(x) for sample in ['hell', 'NameError', 'KeyError', 'AttributeError']), x ) x[0] = x[1] eq_(x[0], x[1])
def test_transform_polystorage_error_with_sentry_configured_failing( self, is_enabled, mock_get_hub, caplogpp): caplogpp.set_level("DEBUG") mock_hub = mock.MagicMock() # Mock this to throw an error if it's called because it shouldn't get called mock_hub.capture_exception.side_effect = ValueError("sentry error") mock_get_hub.return_value = mock_hub # Set up processor and mock .save_processed_crash() to raise an exception config = self.get_standard_config() pa = ProcessorApp(config) pa._setup_source_and_destination() pa.source.get_raw_crash.return_value = DotDict({"raw": "crash"}) pa.source.get_raw_dumps_as_files.return_value = {} try: raise NameError("waldo") except NameError: first_exc_info = sys.exc_info() try: raise AssertionError(False) except AssertionError: second_exc_info = sys.exc_info() expected_exception = PolyStorageError() expected_exception.exceptions.append(first_exc_info) expected_exception.exceptions.append(second_exc_info) pa.destination.save_processed_crash.side_effect = expected_exception # Make sure the PolyStorageError is raised and not the error from # .captureException() with pytest.raises(PolyStorageError): pa.transform("mycrashid") # Assert logs for failing to process crash expected = [ # Logs for failed Sentry reporting for first exception ("Unable to report error with Sentry", mock.ANY), ("Sentry DSN is not configured and an exception happened", None), ("Exception occurred", first_exc_info), # Logs for failed Sentry reporting for second exception ("Unable to report error with Sentry", mock.ANY), ("Sentry DSN is not configured and an exception happened", None), ("Exception occurred", second_exc_info), # Log for failing to process or save the crash ("error in processing or saving crash mycrashid", None), ] actual = [(rec.message, rec.exc_info) for rec in caplogpp.records] assert actual == expected
def test_transform_polystorage_error_with_sentry_configured_failing( self, is_enabled, mock_get_hub, caplogpp): caplogpp.set_level('DEBUG') mock_hub = mock.MagicMock() # Mock this to throw an error if it's called because it shouldn't get called mock_hub.capture_exception.side_effect = ValueError('sentry error') mock_get_hub.return_value = mock_hub # Set up processor and mock .save_raw_and_processed() to raise an exception config = self.get_standard_config() pa = ProcessorApp(config) pa._setup_source_and_destination() pa.source.get_raw_crash.return_value = DotDict({'raw': 'crash'}) pa.source.get_raw_dumps_as_files.return_value = {} first_exc_info = (NameError, NameError('waldo'), 'fake tb 1') second_exc_info = (AssertionError, AssertionError(False), 'fake tb 2') expected_exception = PolyStorageError() expected_exception.exceptions.append(first_exc_info) expected_exception.exceptions.append(second_exc_info) pa.destination.save_raw_and_processed.side_effect = expected_exception # Make sure the PolyStorageError is raised and not the error from # .captureException() with pytest.raises(PolyStorageError): pa.transform('mycrashid') # Assert logs for failing to process crash expected = [ # Logs for failed Sentry reporting for first exception ('Unable to report error with Sentry', WHATEVER), ('Sentry DSN is not configured and an exception happened', None), ('Exception occurred', first_exc_info), # Logs for failed Sentry reporting for second exception ('Unable to report error with Sentry', WHATEVER), ('Sentry DSN is not configured and an exception happened', None), ('Exception occurred', second_exc_info), # Log for failing to process or save the crash ('error in processing or saving crash mycrashid', None) ] actual = [(rec.message, rec.exc_info) for rec in caplogpp.records] assert actual == expected
def test_transform_polystorage_error_with_raven_configured_failing( self, mock_raven, caplogpp): caplogpp.set_level('DEBUG') raven_mock_client = mock.MagicMock() # Mock this to throw an error if it's called because it shouldn't get called raven_mock_client.captureException.side_effect = ValueError( 'raven error') mock_raven.Client.return_value = raven_mock_client # Set up processor and mock .save_raw_and_processed() to raise an exception config = self.get_standard_config( sentry_dsn='https://[email protected]/project') pa = ProcessorApp(config) pa._setup_source_and_destination() pa.source.get_raw_crash.return_value = DotDict({'raw': 'crash'}) pa.source.get_raw_dumps_as_files.return_value = {} first_exc_info = (NameError, NameError('waldo'), 'fake tb 1') second_exc_info = (AssertionError, AssertionError(False), 'fake tb 2') expected_exception = PolyStorageError() expected_exception.exceptions.append(first_exc_info) expected_exception.exceptions.append(second_exc_info) pa.destination.save_raw_and_processed.side_effect = expected_exception # Make sure the PolyStorageError is raised and not the error from # .captureException() with pytest.raises(PolyStorageError): pa.transform('mycrashid') # Assert calls to logger--one set for each of the errors in # PolyStorageError expected = [ ('Unable to report error with Raven', WHATEVER), ('Sentry DSN is not configured and an exception happened', None), ('Exception occurred', first_exc_info), ('error in processing or saving crash mycrashid', None), ('Unable to report error with Raven', WHATEVER), ('Sentry DSN is not configured and an exception happened', None), ('Exception occurred', second_exc_info), ('error in processing or saving crash mycrashid', None) ] actual = [(rec.message, rec.exc_info) for rec in caplogpp.records] assert actual == expected
def test_polyerror_str_missing_args(self): p = PolyStorageError() try: try: raise NameError("dwight") except NameError: p.gather_current_exception() try: raise KeyError("wilma") except KeyError: p.gather_current_exception() raise p except PolyStorageError as x: assert str(x) == "NameError('dwight'),KeyError('wilma')"
def mocked_save_raw_and_processed(*args, **kwargs): exception = PolyStorageError() exception.exceptions.append(NameError('waldo')) raise exception
def mocked_save_raw_and_processed(*_): exception = PolyStorageError() exception.exceptions.append(NameError('waldo')) exception.exceptions.append(AssertionError(False)) raise exception
def mocked_save_processed_crash(*args, **kwargs): exception = PolyStorageError() exception.exceptions.append(NameError("waldo")) raise exception