def test_filepath_formatting(tmppath): """Test extension initialization.""" app = Flask('testapp', instance_path=tmppath) app.config.update( dict(DEBUG=True, LOGGING_FS_LOGFILE='{instance_path}/testapp.log')) InvenioLoggingFS(app) assert app.config['LOGGING_FS_LOGFILE'] == join(tmppath, 'testapp.log') assert app.config['LOGGING_FS_LEVEL'] == 'DEBUG'
def test_init(tmppath): """Test extension initialization.""" app = Flask('testapp') InvenioLoggingFS(app) assert 'invenio-logging-fs' not in app.extensions ext = InvenioLoggingFS() app = Flask('testapp') ext.init_app(app) assert 'invenio-logging-fs' not in app.extensions logfile = join(tmppath, 'test.log') app = Flask('testapp') app.config.update(dict(LOGGING_FS_LOGFILE=logfile)) InvenioLoggingFS(app) assert 'invenio-logging-fs' in app.extensions assert app.config['LOGGING_FS_LEVEL'] == 'WARNING'
def test_warnings(tmppath, pywarnlogger): """Test extension initialization.""" app = Flask('testapp', instance_path=tmppath) app.config.update( dict(LOGGING_FS_LOGFILE='{instance_path}/testapp.log', LOGGING_FS_PYWARNINGS=True, LOGGING_FS_LEVEL='WARNING')) InvenioLoggingFS(app) assert RotatingFileHandler in [x.__class__ for x in pywarnlogger.handlers]
def dryrun(sources, source_type, recid): """Load records migration dump.""" from invenio_logging.fs import InvenioLoggingFS current_app.config['LOGGING_FS'] = True current_app.config['LOGGING_FS_LOGFILE'] = '/tmp/migration.log' InvenioLoggingFS(current_app) current_app.config['MIGRATOR_RECORDS_DUMPLOADER_CLS'] = \ 'cds.modules.migrator.records:DryRunCDSRecordDumpLoader' load_records(sources=sources, source_type=source_type, eager=True)
def test_logging(tmppath): """Test extension initialization.""" filepath = join(tmppath, 'test.log') app = Flask('testapp') app.config.update( dict(LOGGING_FS_LOGFILE=filepath, LOGGING_FS_LEVEL='WARNING')) InvenioLoggingFS(app) # Test delay opening of file assert not exists(filepath) app.logger.warn('My warning') assert exists(filepath) app.logger.info('My info') # Test log level with open(filepath) as fp: content = fp.read() assert 'My warning' in content assert 'My info' not in content
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND="cache", MAIL_SUPPRESS_SEND=True, SECRET_KEY="1q2w3e4r5t!Q", SECURITY_PASSWORD_SALT="1q2w3e4r5t!Qw#E$R%T6", ) app.secret_key = 'ExampleApp' app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'sqlite:///instance/test.db') app.testing = True os.environ['CI'] = 'false' Babel(app) Menu(app) InvenioDB(app) InvenioAccounts(app=app, sessionstore=None) InvenioAdmin(app) app.register_blueprint(blueprint_accounts) console = InvenioLoggingConsole(app) fs = InvenioLoggingFS(app) WekoAccounts(app) app.app_context().push() @app.before_request def check_session_time(): current_app.logger.info('first check session timeout') if __name__ == '__main__': app.run(host='0.0.0.0', port=80, debug=True)