Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_notify_configured_api_key(self):
bugsnag.notify(ScaryException('unexpected failover'))
headers = self.server.received[0]['headers']
self.assertEqual('tomatoes', headers['Bugsnag-Api-Key'])
def test_notify_recursive_metadata_array(self):
a = ['foo', 'bar']
a.append(a)
bugsnag.add_metadata_tab('a', {'b': a})
bugsnag.notify(ScaryException('unexpected failover'))
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertEqual(['foo', 'bar', '[RECURSIVE]'],
event['metaData']['a']['b'])
def test_notify_override_metadata_sections(self):
bugsnag.add_metadata_tab('food', {'beans': 3, 'corn': 'purple'})
bugsnag.notify(ScaryException('unexpected failover'),
meta_data={'food': {'beans': 5},
'skills': {'spear': 6}})
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertEqual(6, event['metaData']['skills']['spear'])
self.assertEqual('purple', event['metaData']['food']['corn'])
self.assertEqual(5, event['metaData']['food']['beans'])
def test_notify_device_filter(self):
bugsnag.configure(params_filters=['hostname'])
bugsnag.notify(ScaryException('unexpected failover'))
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertEqual('[FILTERED]', event['device']['hostname'])
def test_notify_recursive_metadata_dict(self):
a = {'foo': 'bar'}
a['baz'] = a
bugsnag.add_metadata_tab('a', a)
bugsnag.notify(ScaryException('unexpected failover'))
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertEqual('bar', event['metaData']['a']['foo'])
self.assertEqual('[RECURSIVE]', event['metaData']['a']['baz']['baz'])
def test_middleware_stack_order_legacy(self):
def first_callback(notification):
notification.meta_data['test']['array'].append(1)
def second_callback(notification):
notification.meta_data['test']['array'].append(2)
# Add a regular callback function
bugsnag.before_notify(second_callback)
# Simulate an internal middleware
bugsnag.legacy.configuration.internal_middleware.before_notify(
first_callback)
bugsnag.notify(ScaryException('unexpected failover'),
test={'array': []})
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertEqual(event['metaData']['test']['array'], [1, 2])
def test_notify_override_user(self):
bugsnag.notify(ScaryException('unexpected failover'),
user={'name': 'bob',
'email': 'mcbob@example.com',
'id': '542347329'})
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertEqual('bob', event['user']['name'])
self.assertEqual('542347329', event['user']['id'])
self.assertEqual('mcbob@example.com', event['user']['email'])
def get(self):
msg = "Bugsnag Tornado demo says: False alarm, your application "
msg += "didn't crash"
bugsnag.notify(Exception(msg))
self.write(
"Bugsnag Tornado demo says: It didn't crash! But still go " +
"check <a href="\"bugsnag.com\"">bugsnag.com</a> for a new " +
"notification.")
def handle_zero_div():
"""Deliberately triggers a handled exception, and reports it to Bugsnag.
"""
try:
x = 1/0
except Exception as e:
bugsnag.notify(e)
return 'The app hasn\'t crashed, but check <a href="\"https://app.bugsnag.com\"">app.bugsnag.com</a> to view notifications'
def notifywithcontext():
"""Notifies Bugsnag of a handled exception, which has a modified 'context' attribute for the purpose of improving how these exceptions will group together in the Bugsnag dashboard, and a severity attribute that has been modifed to overwrite the default level (warning).
"""
bugsnag.notify(
Exception('Flask demo: Manual notification with context and severity'),
context = 'notifywithcontext',
severity = 'info'
)
return 'The context and severity were changed.'