Ejemplo n.º 1
0
def test_conf_loader_factory():
    """Test the conf factory."""
    tmppath = tempfile.mkdtemp()
    try:
        app = Flask('testapp')

        # Module configuration
        class Config(object):
            MODULE = 'module'
            FOLDER = 'module'
            KWARGS = 'module'
            ENV = 'module'

        # Instance path configuration
        with open(join(tmppath, 'testapp.cfg'), 'w') as f:
            f.write("FOLDER = 'folder'\n")
            f.write("KWARGS = 'folder'\n")
            f.write("ENV = 'folder'\n")

        # Keyword arguments configuration
        kwargs = dict(KWARGS='kwargs', ENV='kwargs')

        # Environment configuraiton
        os.environ['APREFIX_ENV'] = 'env'

        # Create conf loader
        conf_loader = create_conf_loader(Config, env_prefix="APREFIX")
        app = Flask('testapp',
                    instance_path=tmppath,
                    instance_relative_config=True)
        conf_loader(app, **kwargs)

        # Test correct overwriting of values.
        assert app.config['MODULE'] == 'module'
        assert app.config['FOLDER'] == 'folder'
        assert app.config['KWARGS'] == 'kwargs'
        assert app.config['ENV'] == 'env'
    finally:
        shutil.rmtree(tmppath)
def test_conf_loader_factory():
    """Test the conf factory."""
    tmppath = tempfile.mkdtemp()
    try:
        app = Flask('testapp')

        # Module configuration
        class Config(object):
            MODULE = 'module'
            FOLDER = 'module'
            KWARGS = 'module'
            ENV = 'module'

        # Instance path configuration
        with open(join(tmppath, 'testapp.cfg'), 'w') as f:
            f.write("FOLDER = 'folder'\n")
            f.write("KWARGS = 'folder'\n")
            f.write("ENV = 'folder'\n")

        # Keyword arguments configuration
        kwargs = dict(KWARGS='kwargs', ENV='kwargs')

        # Environment configuraiton
        os.environ['APREFIX_ENV'] = 'env'

        # Create conf loader
        conf_loader = create_conf_loader(Config, env_prefix="APREFIX")
        app = Flask(
            'testapp', instance_path=tmppath, instance_relative_config=True)
        conf_loader(app, **kwargs)

        # Test correct overwriting of values.
        assert app.config['MODULE'] == 'module'
        assert app.config['FOLDER'] == 'folder'
        assert app.config['KWARGS'] == 'kwargs'
        assert app.config['ENV'] == 'env'
    finally:
        shutil.rmtree(tmppath)
Ejemplo n.º 3
0
"""Application factory creating the b2share application."""

import os
import sys

from flask import Flask
from invenio_base.app import create_app_factory
from invenio_config import create_conf_loader
from werkzeug.wsgi import DispatcherMiddleware
from werkzeug.contrib.fixers import ProxyFix

from . import config

env_prefix = 'B2SHARE'

config_loader = create_conf_loader(config=config, env_prefix=env_prefix)

instance_path = os.getenv(env_prefix + '_INSTANCE_PATH') or \
    os.path.join(sys.prefix, 'var', 'b2share-instance')
"""Instance path for B2Share."""


def create_api(*args, **kwargs):
    app = create_app_factory(
        'b2share',
        config_loader=config_loader,
        extension_entry_points=['invenio_base.api_apps'],
        blueprint_entry_points=['invenio_base.api_blueprints'],
        converter_entry_points=['invenio_base.api_converters'],
        instance_path=instance_path,
    )(*args, **kwargs)
Ejemplo n.º 4
0
"""

import os
import sys

from flask import Flask
from invenio_base.app import create_app_factory
from invenio_config import create_conf_loader
from werkzeug.wsgi import DispatcherMiddleware
from werkzeug.contrib.fixers import ProxyFix

from . import config

env_prefix = 'B2SHARE'

config_loader = create_conf_loader(config=config, env_prefix=env_prefix)

instance_path = os.getenv(env_prefix + '_INSTANCE_PATH') or \
    os.path.join(sys.prefix, 'var', 'b2share-instance')
"""Instance path for B2Share."""


def create_api(*args, **kwargs):
    """Create Flask application providing B2SHARE REST API."""
    app = create_app_factory(
        'b2share',
        config_loader=config_loader,
        extension_entry_points=['invenio_base.api_apps'],
        blueprint_entry_points=['invenio_base.api_blueprints'],
        converter_entry_points=['invenio_base.api_converters'],
        instance_path=instance_path,