def create_app(config=None): app = Flask(__name__) app.wsgi_app = ProxyFix(app.wsgi_app) config = config or os.environ.get("WEBHOOKDB_CONFIG") or "default" app.config.from_object(expand_config(config)) if not app.config["TESTING"]: handle_exceptions(app) db.init_app(app) bootstrap.init_app(app) login_manager.init_app(app) create_celery_app(app) if not app.debug: SSLify(app) from .oauth import github_bp app.register_blueprint(github_bp, url_prefix="/login") from .replication import replication as repl_blueprint app.register_blueprint(repl_blueprint, url_prefix="/replication") from .load import load as load_blueprint app.register_blueprint(load_blueprint, url_prefix="/load") from .tasks import tasks as tasks_blueprint app.register_blueprint(tasks_blueprint, url_prefix="/tasks") from .ui import ui as ui_blueprint app.register_blueprint(ui_blueprint) return app
def test_bugsnag_custom_data(self): meta_data = [{"hello": {"world": "once"}}, {"again": {"hello": "world"}}] app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.configure_request(meta_data=meta_data.pop()) raise SentinelError("oops") handle_exceptions(app) with app.test_client() as client: client.get('/hello') client.get('/hello') payload = self.server.received[0]['json_body'] event = payload['events'][0] self.assertEqual(event['metaData'].get('hello'), None) self.assertEqual(event['metaData']['again']['hello'], 'world') payload = self.server.received[1]['json_body'] event = payload['events'][0] self.assertEqual(event['metaData']['hello']['world'], 'once') self.assertEqual(event['metaData'].get('again'), None) self.assertEqual(2, len(self.server.received))
def configure_exceptions(app): if app.config['BUGSNAG_API_KEY']: # pragma: no cover bugsnag.configure( api_key=app.config['BUGSNAG_API_KEY'], project_root=app.config['ROOT'], ) handle_exceptions(app)
def make_application(): from metadataproxy.settings import Settings flask_app = Flask(__name__, static_url_path='') if Settings.BUGSNAG_API_KEY: import bugsnag from bugsnag.flask import handle_exceptions bugsnag.configure(api_key=Settings.BUGSNAG_API_KEY) handle_exceptions(flask_app) elif Settings.SENTRY_DSN: from raven.contrib.flask import Sentry sentry = Sentry() sentry.init_app(flask_app, dsn=Settings.SENTRY_DSN) flask_app.config.from_object('metadataproxy.settings.Settings') flask_app.debug = Settings.DEBUG if flask_app.config['MOCK_API']: import metadataproxy.routes.mock flask_app.register_blueprint(metadataproxy.routes.mock.blueprint_http) metadataproxy.routes.mock.blueprint_http.config = flask_app.config else: import metadataproxy.routes.proxy flask_app.register_blueprint(metadataproxy.routes.proxy.blueprint_http) metadataproxy.routes.proxy.blueprint_http.config = flask_app.config return flask_app
def test_bugsnag_custom_data(self, deliver): meta_data = [{"hello": {"world": "once"}}, {"again": {"hello": "world"}}] app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.configure_request(meta_data=meta_data.pop()) raise SentinelError("oops") handle_exceptions(app) app.test_client().get('/hello') app.test_client().get('/hello') self.assertEqual(deliver.call_count, 2) payload = deliver.call_args_list[0][0][0] event = payload['events'][0] self.assertEqual(event['metaData'].get('hello'), None) self.assertEqual(event['metaData']['again']['hello'], 'world') payload = deliver.call_args_list[1][0][0] event = payload['events'][0] self.assertEqual(event['metaData']['hello']['world'], 'once') self.assertEqual(event['metaData'].get('again'), None)
def test_bugsnag_custom_data(self): meta_data = [{ "hello": { "world": "once" } }, { "again": { "hello": "world" } }] app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.configure_request(meta_data=meta_data.pop()) raise SentinelError("oops") handle_exceptions(app) with app.test_client() as client: client.get('/hello') client.get('/hello') payload = self.server.received[0]['json_body'] event = payload['events'][0] self.assertEqual(event['metaData'].get('hello'), None) self.assertEqual(event['metaData']['again']['hello'], 'world') payload = self.server.received[1]['json_body'] event = payload['events'][0] self.assertEqual(event['metaData']['hello']['world'], 'once') self.assertEqual(event['metaData'].get('again'), None) self.assertEqual(2, len(self.server.received))
def test_bugsnag_includes_posted_json_data(self): app = Flask("bugsnag") @app.route("/ajax", methods=["POST"]) def hello(): raise SentinelError("oops") handle_exceptions(app) body = { '_links': { 'self': { 'href': 'http://example.com/api/resource/a' } }, 'id': 'res-a', 'name': 'Resource A' } app.test_client().post( '/ajax', data=json.dumps(body), content_type='application/hal+json') self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] event = payload['events'][0] self.assertEqual(event['exceptions'][0]['errorClass'], 'test_flask.SentinelError') self.assertEqual(event['metaData']['request']['url'], 'http://localhost/ajax') self.assertEqual(event['metaData']['request']['data'], body)
def test_bugsnag_middleware_working(deliver): app = Flask("working") @app.route("/hello") def hello(): return "OK" handle_exceptions(app) resp = app.test_client().get('/hello') eq_(resp.data, b'OK') eq_(deliver.call_count, 0)
def register_extensions(app): """Register Flask extensions.""" bcrypt.init_app(app) db.init_app(app) csrf_protect.init_app(app) debug_toolbar.init_app(app) migrate.init_app(app, db) mail.init_app(app) login_manager.init_app(app) principal.init_app(app) handle_exceptions(app) return None
def test_bugsnag_notify(deliver): app = Flask("notifying") @app.route("/hello") def hello(): bugsnag.notify(SentinalError("oops")) return "OK" handle_exceptions(app) resp = app.test_client().get('/hello') eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload['events'][0]['metaData']['request']['url'], 'http://localhost/hello')
def test_bugsnag_crash(deliver): app = Flask("crashing") @app.route("/hello") def hello(): raise SentinalError("oops") handle_exceptions(app) resp = app.test_client().get('/hello') eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload['events'][0]['exceptions'][0]['errorClass'], 'test_flask.SentinalError') eq_(payload['events'][0]['metaData']['request']['url'], 'http://localhost/hello')
def test_bugsnag_middleware_working(self): app = Flask("bugsnag") @app.route("/hello") def hello(): return "OK" handle_exceptions(app) resp = app.test_client().get('/hello') self.assertEqual(resp.data, b'OK') self.assertEqual(0, len(self.server.received))
def test_bugsnag_middleware_working(deliver): app = Flask("bugsnag") @app.route("/hello") def hello(): return "OK" handle_exceptions(app) resp = app.test_client().get('/hello') eq_(resp.data, b'OK') eq_(deliver.call_count, 0)
def test_bugsnag_crash(deliver): app = Flask("bugsnag") @app.route("/hello") def hello(): raise SentinalError("oops") handle_exceptions(app) app.test_client().get("/hello") eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload["events"][0]["exceptions"][0]["errorClass"], "test_flask.SentinalError") eq_(payload["events"][0]["metaData"]["request"]["url"], "http://localhost/hello")
def test_bugsnag_notify(deliver): app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.notify(SentinalError("oops")) return "OK" handle_exceptions(app) app.test_client().get("/hello") eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload["events"][0]["metaData"]["request"]["url"], "http://localhost/hello")
def test_bugsnag_includes_posted_json_data(deliver): app = Flask("bugsnag") @app.route("/ajax", methods=["POST"]) def hello(): raise SentinalError("oops") handle_exceptions(app) app.test_client().post("/ajax", data='{"key": "value"}', content_type="application/json") eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload["events"][0]["exceptions"][0]["errorClass"], "test_flask.SentinalError") eq_(payload["events"][0]["metaData"]["request"]["url"], "http://localhost/ajax") eq_(payload["events"][0]["metaData"]["request"]["data"], dict(key="value"))
def test_bugsnag_notify(deliver): app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.notify(SentinalError("oops")) return "OK" handle_exceptions(app) app.test_client().get('/hello') eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload['events'][0]['metaData']['request']['url'], 'http://localhost/hello')
def test_bugsnag_notify(self): app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.notify(SentinelError("oops")) return "OK" handle_exceptions(app) app.test_client().get('/hello') self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] self.assertEqual(payload['events'][0]['metaData']['request']['url'], 'http://localhost/hello')
def test_bugsnag_includes_unknown_content_type_posted_data(deliver): app = Flask("bugsnag") @app.route("/form", methods=["PUT"]) def hello(): raise SentinalError("oops") handle_exceptions(app) app.test_client().put("/form", data="_data", content_type="application/octet-stream") eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload["events"][0]["exceptions"][0]["errorClass"], "test_flask.SentinalError") eq_(payload["events"][0]["metaData"]["request"]["url"], "http://localhost/form") ok_("_data" in payload["events"][0]["metaData"]["request"]["data"]["body"])
def test_bugsnag_notify(self, deliver): app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.notify(SentinelError("oops")) return "OK" handle_exceptions(app) app.test_client().get('/hello') self.assertEqual(deliver.call_count, 1) payload = deliver.call_args[0][0] self.assertEqual(payload['events'][0]['metaData']['request']['url'], 'http://localhost/hello')
def test_disable_environment(self): bugsnag.configure(send_environment=False) app = Flask("bugsnag") @app.route("/hello") def hello(): raise SentinelError("oops") handle_exceptions(app) app.test_client().get('/hello') self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] assert 'environment' not in payload['events'][0]['metaData']
def test_bugsnag_crash(self): app = Flask("bugsnag") @app.route("/hello") def hello(): raise SentinelError("oops") handle_exceptions(app) app.test_client().get('/hello') self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] self.assertEqual(payload['events'][0]['exceptions'][0]['errorClass'], 'test_flask.SentinelError') self.assertEqual(payload['events'][0]['metaData']['request']['url'], 'http://localhost/hello')
def test_bugsnag_crash(deliver): app = Flask("bugsnag") @app.route("/hello") def hello(): raise SentinalError("oops") handle_exceptions(app) app.test_client().get('/hello') eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload['events'][0]['exceptions'][0]['errorClass'], 'test_flask.SentinalError') eq_(payload['events'][0]['metaData']['request']['url'], 'http://localhost/hello')
def test_bugsnag_notify_with_custom_context(self): app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.notify(SentinelError("oops"), context="custom_context_notification_testing") return "OK" handle_exceptions(app) app.test_client().get('/hello') self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] self.assertEqual(payload['events'][0]['context'], 'custom_context_notification_testing')
def test_bugsnag_add_metadata_tab(deliver): app = Flask("bugsnag") @app.route("/form", methods=["PUT"]) def hello(): bugsnag.add_metadata_tab("account", {"id": 1, "premium": True}) bugsnag.add_metadata_tab("account", {"premium": False}) raise SentinalError("oops") handle_exceptions(app) app.test_client().put("/form", data="_data", content_type="application/octet-stream") eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload["events"][0]["metaData"]["account"]["premium"], False) eq_(payload["events"][0]["metaData"]["account"]["id"], 1)
def test_enable_environment(self): bugsnag.configure(send_environment=True) app = Flask("bugsnag") @app.route("/hello") def hello(): raise SentinelError("oops") handle_exceptions(app) app.test_client().get('/hello') self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] event = payload['events'][0] self.assertEqual(event['metaData']['environment']['REMOTE_ADDR'], '127.0.0.1')
def create_app(config_name): app = FlaskAPI(__name__, instance_relative_config=False) app.config.from_object(env.app_env[config_name]) app.config.from_pyfile('../config/env.py') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.url_map.converters['date'] = DateValidator app.url_map.strict_slashes = False # CORS CORS(app) # Blueprints blueprint = BaseBlueprint(app) blueprint.register() # cron = Cron(app) # scheduler = BackgroundScheduler("Africa/Lagos") # # in your case you could change seconds to hours # scheduler.add_job(cron.run_24_hourly, trigger='interval', hours=24) # scheduler.add_job(cron.meal_session_cron) # scheduler.start() from . import models db.init_app(app) cron = Cron(app) scheduler = BackgroundScheduler(timezone="Africa/Lagos") # in your case you could change seconds to hours scheduler.add_job(cron.run_24_hourly, trigger='interval', hours=24) scheduler.add_job(cron.run_meal_session_cron, 'cron', day_of_week='mon-fri', hour=0, minute=0, misfire_grace_time=None) scheduler.add_job(cron.run_5_minute, trigger='interval', minutes=5) scheduler.start() swg = Swagger(app) handle_exceptions(app) # register error handlers app.register_error_handler(Exception, handle_exception) app.register_error_handler(BaseModelValidationError, handle_exception) return app
def test_bugsnag_add_metadata_tab(self): app = Flask("bugsnag") @app.route("/form", methods=["PUT"]) def hello(): bugsnag.add_metadata_tab("account", {"id": 1, "premium": True}) bugsnag.add_metadata_tab("account", {"premium": False}) raise SentinelError("oops") handle_exceptions(app) app.test_client().put( '/form', data='_data', content_type='application/octet-stream') self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] event = payload['events'][0] self.assertEqual(event['metaData']['account']['premium'], False) self.assertEqual(event['metaData']['account']['id'], 1)
def test_read_request_in_callback(self): def callback(event): event.set_user(id=event.request.args['id']) return True app = Flask("bugsnag") @app.route("/hello") def hello(): raise SentinelError("oops") bugsnag.before_notify(callback) handle_exceptions(app) app.test_client().get('/hello?id=foo') assert len(self.server.received) == 1 payload = self.server.received[0]['json_body'] assert payload['events'][0]['user']['id'] == 'foo'
def test_bugsnag_includes_posted_json_data(deliver): app = Flask("bugsnag") @app.route("/ajax", methods=["POST"]) def hello(): raise SentinalError("oops") handle_exceptions(app) app.test_client().post( '/ajax', data='{"key": "value"}', content_type='application/json') eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload['events'][0]['exceptions'][0]['errorClass'], 'test_flask.SentinalError') eq_(payload['events'][0]['metaData']['request']['url'], 'http://localhost/ajax') eq_(payload['events'][0]['metaData']['request']['data'], dict(key='value'))
def test_bugsnag_includes_unknown_content_type_posted_data(deliver): app = Flask("bugsnag") @app.route("/form", methods=["PUT"]) def hello(): raise SentinalError("oops") handle_exceptions(app) app.test_client().put( '/form', data='_data', content_type='application/octet-stream') eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload['events'][0]['exceptions'][0]['errorClass'], 'test_flask.SentinalError') eq_(payload['events'][0]['metaData']['request']['url'], 'http://localhost/form') ok_('_data' in payload['events'][0]['metaData']['request']['data']['body'])
def setup_app(app): #setup syslog app.logger.addFilter(app_logging.ContextFilter()) syslog_handler = app_logging.get_syslog_handler() if syslog_handler: app.logger.addHandler(syslog_handler) #send application error exception message to log def log_exception(sender, exception, **extra): sender.logger.error(exception) got_request_exception.connect(log_exception, app) #setup bugsnag bugsnag_api_key = os.getenv('SS_SORAYA_RECO_BUGSNAG_API_KEY') if bugsnag_api_key: bugsnag.configure( api_key= bugsnag_api_key, project_root=os.path.abspath(os.path.dirname(__file__)), release_stage=os.getenv('SS_SORAYA_RECO_RELEASE_STAGE')) handle_exceptions(app)
def test_bugsnag_add_metadata_tab(deliver): app = Flask("bugsnag") @app.route("/form", methods=["PUT"]) def hello(): bugsnag.add_metadata_tab("account", {"id": 1, "premium": True}) bugsnag.add_metadata_tab("account", {"premium": False}) raise SentinalError("oops") handle_exceptions(app) app.test_client().put('/form', data='_data', content_type='application/octet-stream') eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload['events'][0]['metaData']['account']['premium'], False) eq_(payload['events'][0]['metaData']['account']['id'], 1)
def test_bugsnag_includes_unknown_content_type_posted_data(deliver): app = Flask("bugsnag") @app.route("/form", methods=["PUT"]) def hello(): raise SentinalError("oops") handle_exceptions(app) app.test_client().put('/form', data='_data', content_type='application/octet-stream') eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload['events'][0]['exceptions'][0]['errorClass'], 'test_flask.SentinalError') eq_(payload['events'][0]['metaData']['request']['url'], 'http://localhost/form') ok_('_data' in payload['events'][0]['metaData']['request']['data']['body'])
def test_bugsnag_includes_request_when_json_malformed(self): app = Flask("bugsnag") @app.route("/ajax", methods=["POST"]) def hello(): raise SentinelError("oops") handle_exceptions(app) app.test_client().post( '/ajax', data='{"key": "value"', content_type='application/json') self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] event = payload['events'][0] self.assertEqual(event['exceptions'][0]['errorClass'], 'test_flask.SentinelError') self.assertEqual(event['metaData']['request']['url'], 'http://localhost/ajax') self.assertEqual(event['metaData']['request']['data']['body'], '{"key": "value"')
def test_bugsnag_includes_posted_json_data(deliver): app = Flask("bugsnag") @app.route("/ajax", methods=["POST"]) def hello(): raise SentinalError("oops") handle_exceptions(app) app.test_client().post('/ajax', data='{"key": "value"}', content_type='application/json') eq_(deliver.call_count, 1) payload = deliver.call_args[0][0] eq_(payload['events'][0]['exceptions'][0]['errorClass'], 'test_flask.SentinalError') eq_(payload['events'][0]['metaData']['request']['url'], 'http://localhost/ajax') eq_(payload['events'][0]['metaData']['request']['data'], dict(key='value'))
def _config_bugsnag(self): # Configure Bugsnag if self.config.get( 'TESTING') or not self.config.get('BUGSNAG_API_KEY'): self.log.info('Bugsnag NOT configured.') return import bugsnag from bugsnag.flask import handle_exceptions from bugsnag.handlers import BugsnagHandler bugsnag.configure( api_key=self.config['BUGSNAG_API_KEY'], project_root="/data/git/pillar/pillar", ) handle_exceptions(self) bs_handler = BugsnagHandler() bs_handler.setLevel(logging.ERROR) self.log.addHandler(bs_handler)
def test_flask_intergration_includes_middleware_severity(self): app = Flask("bugsnag") @app.route("/test") def test(): raise SentinelError("oops") handle_exceptions(app) app.test_client().get("/test") self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] event = payload['events'][0] self.assertTrue(event['unhandled']) self.assertEqual(event['severityReason'], { "type": "unhandledExceptionMiddleware", "attributes": { "framework": "Flask" } })
def test_bugsnag_includes_unknown_content_type_posted_data(self): app = Flask("bugsnag") @app.route("/form", methods=["PUT"]) def hello(): raise SentinelError("oops") handle_exceptions(app) app.test_client().put( '/form', data='_data', content_type='application/octet-stream') self.assertEqual(1, len(self.server.received)) payload = self.server.received[0]['json_body'] event = payload['events'][0] self.assertEqual(event['exceptions'][0]['errorClass'], 'test_flask.SentinelError') self.assertEqual(event['metaData']['request']['url'], 'http://localhost/form') body = event['metaData']['request']['data']['body'] self.assertTrue('_data' in body)
def test_appends_framework_version(self): app = Flask("bugsnag") @app.route("/hello") def hello(): raise SentinelError("oops") handle_exceptions(app) app.test_client().get('/hello') self.assertEqual(len(self.server.received), 1) payload = self.server.received[0]['json_body'] device_data = payload['events'][0]['device'] self.assertEquals(len(device_data['runtimeVersions']), 2) self.assertTrue(re.match(r'\d+\.\d+\.\d+', device_data['runtimeVersions']['python'])) self.assertTrue(re.match(r'\d+\.\d+\.\d+', device_data['runtimeVersions']['flask']))
def init_before_first_request(): import datetime init_tag = "[Initiation of Service Process]\n" # Configure Bugsnag bugsnag.configure( api_key=BUGSNAG_TOKEN, project_root=os.path.dirname(os.path.realpath(__file__)), ) # Attach Bugsnag to Flask's exception handler handle_exceptions(app) log_init_time = "Initiation START at: \t%s\n" % datetime.datetime.now() log_app_env = "Environment Variable: \t%s\n" % APP_ENV log_bugsnag_token = "Bugsnag Service TOKEN: \t%s\n" % BUGSNAG_TOKEN log_logentries_token = "Logentries Service TOKEN: \t%s\n" % LOGENTRIES_TOKEN logger.info(init_tag + log_init_time) logger.info(init_tag + log_app_env) logger.info(init_tag + log_bugsnag_token) logger.info(init_tag + log_logentries_token)
def create_app_factory(package_name, package_path, settings_override=None): """Returns a :class:`Flask` application instance configured with project-wide functionality. :param package_name: application package name. :param package_path: application package path. :param settings_override: a dictionary of settings to override. """ app = Flask(package_name, instance_relative_config=True) app.config.from_object(settings) app.config.from_object(settings_override) app.es = ElasticsearchService(app.config['ELASTICSEARCH_HOST'], app.config['ELASTICSEARCH_PORT']) register_blueprints(app, package_name, package_path) if BUGSNAG_APIKEY: from bugsnag.flask import handle_exceptions handle_exceptions(app) return app
def make_application(): from flask import Flask from cronq.config import Config import cronq.web import os flask_app = Flask(__name__, static_url_path='/static') if Config.BUGSNAG_API_KEY: import bugsnag from bugsnag.flask import handle_exceptions bugsnag.configure(api_key=Config.BUGSNAG_API_KEY) handle_exceptions(flask_app) elif Config.SENTRY_DSN: from raven.contrib.flask import Sentry sentry = Sentry() sentry.init_app(flask_app, dsn=Config.SENTRY_DSN) flask_app.config.from_object('cronq.config.Config') flask_app.register_blueprint(cronq.web.blueprint_http) cronq.web.blueprint_http.config = flask_app.config return flask_app
def test_bugsnag_custom_data(deliver): meta_data = [{"hello": {"world": "once"}}, {"again": {"hello": "world"}}] app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.configure_request(meta_data=meta_data.pop()) raise SentinalError("oops") handle_exceptions(app) app.test_client().get('/hello') app.test_client().get('/hello') eq_(deliver.call_count, 2) payload = deliver.call_args_list[0][0][0] eq_(payload['events'][0]['metaData'].get('hello'), None) eq_(payload['events'][0]['metaData']['again']['hello'], 'world') payload = deliver.call_args_list[1][0][0] eq_(payload['events'][0]['metaData']['hello']['world'], 'once') eq_(payload['events'][0]['metaData'].get('again'), None)
def test_bugsnag_custom_data(deliver): meta_data = [{"hello": {"world": "once"}}, {"again": {"hello": "world"}}] app = Flask("bugsnag") @app.route("/hello") def hello(): bugsnag.configure_request(meta_data=meta_data.pop()) raise SentinalError("oops") handle_exceptions(app) app.test_client().get("/hello") app.test_client().get("/hello") eq_(deliver.call_count, 2) payload = deliver.call_args_list[0][0][0] eq_(payload["events"][0]["metaData"].get("hello"), None) eq_(payload["events"][0]["metaData"]["again"]["hello"], "world") payload = deliver.call_args_list[1][0][0] eq_(payload["events"][0]["metaData"]["hello"]["world"], "once") eq_(payload["events"][0]["metaData"].get("again"), None)
app.debug = config.DEBUG app.secret_key = config.FLASK_SESSION_SECRET_KEY app.root_path = os.path.abspath(os.path.dirname(__file__)) if config.BUGSNAG_KEY: import bugsnag from bugsnag.flask import handle_exceptions bugsnag.configure( api_key=config.BUGSNAG_KEY, project_root=app.root_path, # 'production' is a magic string for bugsnag, rest are arbitrary release_stage=config.REALM.replace("prod", "production"), notify_release_stages=["production", "test"], use_ssl=True) handle_exceptions(app) from .filters import * app.jinja_env.filters['status_class'] = status_class app.jinja_env.filters['friendly_time'] = friendly_time app.jinja_env.filters['friendly_size'] = friendly_size app.jinja_env.filters['to_qs'] = to_qs app.jinja_env.filters['approximate_time'] = approximate_time app.jinja_env.filters['exact_time'] = exact_time app.jinja_env.filters['short_date'] = short_date app.add_url_rule('/', 'views.home') app.add_url_rule('/<path:name>', 'views.bin', methods=[ 'GET', 'POST', 'DELETE', 'PUT', 'OPTIONS', 'HEAD',
app.config.from_object(config) Compress(app) CsrfProtect(app) app_db = SQLAlchemy(app) login_manager = LoginManager() login_manager.login_view = "login" login_manager.login_message = None login_manager.init_app(app) if config.ENVIRONMENT == 'production': # Configure Bugsnag bugsnag.configure( api_key=config.BUGSNAG_KEY, project_root=config.FLASK_PROJECT_PATH, ) handle_exceptions(app) # Configure Logging stream_handler = logging.StreamHandler() app.logger.addHandler(stream_handler) app.logger.setLevel(logging.INFO) else: # Configure local logging from logging.handlers import RotatingFileHandler file_handler = RotatingFileHandler('logs/kateheddleston.log', 'a', 1 * 1024 * 1024, 10) file_handler.setLevel(logging.INFO) file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) app.logger.addHandler(file_handler) app.logger.setLevel(logging.INFO)