Ejemplo n.º 1
0
    def test_setup_cache_custom_function(self):
        app = Flask(__name__)
        CustomCache = type("CustomCache", (object,), {"__init__": lambda *args: None})

        def init_cache(app):
            return CustomCache(app, {})

        assert isinstance(setup_cache(app, init_cache), CustomCache) is True
Ejemplo n.º 2
0
 def test_setup_cache_standard_config(self):
     app = Flask(__name__)
     cache_config = {
         "CACHE_TYPE": "redis",
         "CACHE_DEFAULT_TIMEOUT": 60,
         "CACHE_KEY_PREFIX": "superset_results",
         "CACHE_REDIS_URL": "redis://localhost:6379/0",
     }
     assert isinstance(setup_cache(app, cache_config), Cache) is True
Ejemplo n.º 3
0

@app.context_processor
def get_manifest():
    return dict(
        loaded_chunks=set(),
        get_unloaded_chunks=get_unloaded_chunks,
        js_manifest=get_js_manifest_files,
        css_manifest=get_css_manifest_files,
    )


#################################################################

# Setup the cache prior to registering the blueprints.
cache = setup_cache(app, conf.get("CACHE_CONFIG"))
tables_cache = setup_cache(app, conf.get("TABLE_NAMES_CACHE_CONFIG"))

for bp in conf.get("BLUEPRINTS"):
    try:
        print("Registering blueprint: '{}'".format(bp.name))
        app.register_blueprint(bp)
    except Exception as e:
        print("blueprint registration failed")
        logging.exception(e)

if conf.get("SILENCE_FAB"):
    logging.getLogger("flask_appbuilder").setLevel(logging.ERROR)

db = SQLA(app)
Ejemplo n.º 4
0
 def test_setup_cache_null_config(self):
     app = Flask(__name__)
     cache_config = {"CACHE_TYPE": "null"}
     self.assertIsNone(setup_cache(app, cache_config))
Ejemplo n.º 5
0
 def test_setup_cache_no_config(self):
     app = Flask(__name__)
     cache_config = None
     self.assertIsNone(setup_cache(app, cache_config))
Ejemplo n.º 6
0
    # In production mode, add log handler to sys.stderr.
    app.logger.addHandler(logging.StreamHandler())  # pylint: disable=no-member
    app.logger.setLevel(logging.INFO)  # pylint: disable=no-member
logging.getLogger('pyhive.presto').setLevel(logging.INFO)

db = SQLA(app)

if conf.get('WTF_CSRF_ENABLED'):
    csrf = CSRFProtect(app)
    csrf_exempt_list = conf.get('WTF_CSRF_EXEMPT_LIST', [])
    for ex in csrf_exempt_list:
        csrf.exempt(ex)

pessimistic_connection_handling(db.engine)

cache = setup_cache(app, conf.get('CACHE_CONFIG'))
tables_cache = setup_cache(app, conf.get('TABLE_NAMES_CACHE_CONFIG'))

migrate = Migrate(app, db, directory=APP_DIR + '/migrations')

# Logging configuration
logging.basicConfig(format=app.config.get('LOG_FORMAT'))
logging.getLogger().setLevel(app.config.get('LOG_LEVEL'))

if app.config.get('ENABLE_TIME_ROTATE'):
    logging.getLogger().setLevel(app.config.get('TIME_ROTATE_LOG_LEVEL'))
    handler = TimedRotatingFileHandler(
        app.config.get('FILENAME'),
        when=app.config.get('ROLLOVER'),
        interval=app.config.get('INTERVAL'),
        backupCount=app.config.get('BACKUP_COUNT'))
Ejemplo n.º 7
0
    # In production mode, add log handler to sys.stderr.
    app.logger.addHandler(logging.StreamHandler())  # pylint: disable=no-member
    app.logger.setLevel(logging.INFO)  # pylint: disable=no-member
logging.getLogger('pyhive.presto').setLevel(logging.INFO)

db = SQLA(app)

if conf.get('WTF_CSRF_ENABLED'):
    csrf = CSRFProtect(app)
    csrf_exempt_list = conf.get('WTF_CSRF_EXEMPT_LIST', [])
    for ex in csrf_exempt_list:
        csrf.exempt(ex)

pessimistic_connection_handling(db.engine)

cache = setup_cache(app, conf.get('CACHE_CONFIG'))
tables_cache = setup_cache(app, conf.get('TABLE_NAMES_CACHE_CONFIG'))
# For example:
# DATAFRAME_CACHE_CONFIG = {
#    'CACHE_TYPE': 'contrib.connectors.pandas.cache.dataframe',
#    'CACHE_DEFAULT_TIMEOUT': 60 * 60 * 24,
#    'CACHE_DIR': '/tmp/pandasdatasource_cache',
#    'CACHE_THRESHOLD': 200}
dataframe_cache = setup_cache(app, conf.get('DATAFRAME_CACHE_CONFIG'))

migrate = Migrate(app, db, directory=APP_DIR + '/migrations')

# Logging configuration
logging.basicConfig(format=app.config.get('LOG_FORMAT'))
logging.getLogger().setLevel(app.config.get('LOG_LEVEL'))