Example #1
0
def test_logging_with_missing_file(capsys):
    """Assert that a message is sent to STDERR when the configuration doesn't exist."""
    file_path = None
    setup_logging(file_path)  # important to do this first

    captured = capsys.readouterr()

    assert captured.err.startswith('Unable to configure logging')
Example #2
0
def test_logging_with_file(capsys):
    """Assert that logging is setup with the configuration file."""
    file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                             'logging.conf')
    setup_logging(file_path)  # important to do this first

    captured = capsys.readouterr()

    assert captured.out.startswith('Configure logging, from conf')
Example #3
0
import os

import sentry_sdk  # noqa: I001; pylint: disable=ungrouped-imports,wrong-import-order; conflicts with Flake8
from flask import Flask
from sentry_sdk.integrations.flask import FlaskIntegration  # noqa: I001
from sbc_common_components.exception_handling.exception_handler import ExceptionHandler  # noqa: I001

import config
from api import models
from api.utils.auth import jwt
from api.utils.logging import setup_logging
from api.utils.run_version import get_run_version

setup_logging(
    os.path.join(os.path.abspath(os.path.dirname(__file__)),
                 'logging.conf'))  # important to do this first


def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):
    """Return a configured Flask App using the Factory method."""
    app = Flask(__name__)
    app.config.from_object(config.CONFIGURATION[run_mode])  # pylint: disable=no-member

    # Configure Sentry
    if app.config.get('SENTRY_DSN', None):
        sentry_sdk.init(dsn=app.config.get('SENTRY_DSN'),
                        integrations=[FlaskIntegration()])

    from api.resources import API_BLUEPRINT, OPS_BLUEPRINT  # pylint: disable=import-outside-toplevel
Example #4
0
from api.utils.logging import setup_logging
setup_logging()  ## important to do this first

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow

from config import Config

db = SQLAlchemy()
ma = Marshmallow()

from .endpoints import api


def create_app(config=Config):
    app = Flask(__name__)
    app.config.from_object(config)
    api.init_app(app)

    db.init_app(app)
    ma.init_app(app)

    return app