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_invalid_delivery(self):
c = Configuration()
c.configure(delivery=44, api_key='abc')
client = Client(c)
client.notify(Exception('Oh no'))
def test_middleware_stack_order(self):
client = bugsnag.Client(use_ssl=False,
endpoint=self.server.address,
api_key='tomatoes',
notify_release_stages=['dev'],
release_stage='dev',
asynchronous=False)
def first_callback(notification):
notification.meta_data['test']['array'].append(1)
def second_callback(notification):
notification.meta_data['test']['array'].append(2)
client.configuration.middleware.before_notify(second_callback)
client.configuration.internal_middleware.before_notify(first_callback)
client.notify(ScaryException('unexpected failover'),
def test_internal_middleware_can_change_severity_reason(self):
client = bugsnag.Client(use_ssl=False,
endpoint=self.server.address,
api_key='tomatoes',
notify_release_stages=['dev'],
release_stage='dev',
asynchronous=False)
def severity_reason_callback(notification):
notification.severity_reason['type'] = 'testReason'
internal_middleware = client.configuration.internal_middleware
internal_middleware.before_notify(severity_reason_callback)
client.notify(ScaryException('unexpected failover'))
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
def tearDown(self):
client = bugsnag.Client()
client.configuration.api_key = 'some key'
bugsnag.legacy.default_client = client
bugsnag.legacy.configuration = client.configuration
def test_unregister_installed_except_hook(self):
# Setup an original except hook
def excepthook(*exc_info):
pass
sys.excepthook = excepthook
client = Client()
self.assertNotEqual(sys.excepthook, excepthook)
client.uninstall_sys_hook()
self.assertEqual(sys.excepthook, excepthook)
def test_session_middleware_attaches_session_to_notification(self):
client = Client(
auto_capture_sessions=True,
session_endpoint=self.server.url + '/ignore',
endpoint=self.server.url,
asynchronous=False
)
client.session_tracker.start_session()
client.notify(Exception("Test"))
while len(self.server.received) == 0:
time.sleep(0.5)
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertTrue('session' in event)
session = event['session']
self.assertTrue('id' in session)
self.assertTrue('startedAt' in session)
self.assertTrue('events' in session)
def test_installed_except_hook(self):
client = Client()
# Prevent the existing hook from being called
client.sys_excepthook = None
self.hooked = None
def hooked_except_hook(*exc_info):
self.hooked = exc_info
client.excepthook = hooked_except_hook
try:
raise Exception('Testing excepthook notify')
except Exception:
sys.excepthook(*sys.exc_info())
def wrapped(obj):
client = Client(use_ssl=False,
endpoint=obj.server.address,
api_key='tomatoes',
asynchronous=False)
handler = client.log_handler()
logger = logging.getLogger(__name__)
logger.addHandler(handler)
try:
func(obj, handler, logger)
finally:
logger.removeHandler(handler)
def _configure_error_handler():
handler = None
if BUGSNAG_API_KEY:
client = bugsnag.Client(api_key=BUGSNAG_API_KEY)
handler = client.log_handler()
handler.setLevel(logging.ERROR)
if SENTRY_DSN:
client = RavenClient(SENTRY_DSN)
handler = SentryHandler(client)
handler.setLevel(logging.ERROR)
return handler