def test_create_logger(self): with mock.patch.object(LogConfiguration, '__init__', return_value=None): with mock.patch('logging.getLogger') as mock_get: with mock.patch.object(LogConfiguration, 'file_logger'): with mock.patch.object(LogConfiguration, 'console_logger'): log_config = LogConfiguration('foo', 'bar') name = 'foobar' result = log_config.create_logger(name) mock_get.assert_called_once_with(name) mock_get().setLevel.assert_called_once_with( logging.DEBUG) mock_get().addHandler.assert_has_calls([ mock.call(log_config.file_logger), mock.call(log_config.console_logger) ]) self.assertEqual(result, mock_get())
app.config['DEBUG'] = False # embed flask-migrate in the app itself try: app.config['SQLALCHEMY_DATABASE_URI'] = app.config['DATABASE_URI'] Migrate(app, Base) except KeyError: traceback.print_exc() raise IncompleteConfigException() # Init logger log_configuration = LogConfiguration( app.root_path, # type: ignore # type error skipped since flask 'platform', # now gives as Str but not yet updated in mypy app.config['DEBUG']) # https://github.com/python/typeshed/issues/2791 log = log_configuration.create_logger("Platform") def load_secret_keys(application: Flask, secret_session: str = 'secret_key', secret_csrf: str = 'secret_csrf') -> None: """ Configure the SECRET_KEY from a file in the instance directory. If the file does not exist, print instructions to create it from a shell with a random key, then exit. """ do_exit = False session_file_path = os.path.join( application.root_path, secret_session) # type: ignore # same issue as L42 csrf_file_path = os.path.join(
from mod_upload.controllers import mod_upload from mod_customized.controllers import mod_customized app = Flask(__name__) app.wsgi_app = ProxyFix(app.wsgi_app) # Load config config = parse_config('config') app.config.from_mapping(config) try: app.config['DEBUG'] = os.environ['DEBUG'] except KeyError: app.config['DEBUG'] = False # Init logger log_configuration = LogConfiguration(app.root_path, 'platform', app.config['DEBUG']) log = log_configuration.create_logger("Platform") def install_secret_keys(application, secret_session='secret_key', secret_csrf='secret_csrf'): """ Configure the SECRET_KEY from a file in the instance directory. If the file does not exist, print instructions to create it from a shell with a random key, then exit. """ do_exit = False session_file_path = os.path.join(application.root_path, secret_session) csrf_file_path = os.path.join(application.root_path, secret_csrf) try: with open(session_file_path, 'rb') as session_file: application.config['SECRET_KEY'] = session_file.read() except IOError: