Beispiel #1
0
def base_app():
    """Base uninitialized flask application fixture."""
    from b2share.factory import create_api

    instance_path = tempfile.mkdtemp()
    os.environ.update(
        B2SHARE_INSTANCE_PATH=os.environ.get(
            'INSTANCE_PATH', instance_path),
    )
    app = create_api(
        TESTING=True,
        SERVER_NAME='localhost:5000',
        JSONSCHEMAS_HOST='localhost:5000',
        DEBUG_TB_ENABLED=False,
        SQLALCHEMY_DATABASE_URI=os.environ.get(
            'SQLALCHEMY_DATABASE_URI',
            'postgresql+psycopg2://postgres@localhost:5432/b2sharedb'),
        LOGIN_DISABLED=False,
        WTF_CSRF_ENABLED=False,
        SECRET_KEY="CHANGE_ME",
        SECURITY_PASSWORD_SALT='CHANGEME',
        # register flask_security endpoints for testing purpose.
        ACCOUNTS_REGISTER_BLUEPRINT=True,
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND="cache",
        CELERY_CACHE_BACKEND="memory",
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        SUPPORT_EMAIL='*****@*****.**',
        PREFERRED_URL_SCHEME='https',
    )

    # Disable most of alembic logging.
    logging.getLogger('alembic').setLevel(logging.CRITICAL)
    yield app
    shutil.rmtree(instance_path)
Beispiel #2
0
def base_app():
    """Base uninitialized flask application fixture."""
    from b2share.factory import create_api

    instance_path = tempfile.mkdtemp()
    os.environ.update(
        B2SHARE_INSTANCE_PATH=os.environ.get(
            'INSTANCE_PATH', instance_path),
    )
    app = create_api(
        TESTING=True,
        SERVER_NAME='localhost:5000',
        JSONSCHEMAS_HOST='localhost:5000',
        DEBUG_TB_ENABLED=False,
        SQLALCHEMY_DATABASE_URI=os.environ.get(
            'SQLALCHEMY_DATABASE_URI',
            'postgresql+psycopg2://postgres@localhost:5432/b2sharedb'),
        LOGIN_DISABLED=False,
        WTF_CSRF_ENABLED=False,
        SECRET_KEY="CHANGE_ME",
        SECURITY_PASSWORD_SALT='CHANGEME',
        # register flask_security endpoints for testing purpose.
        ACCOUNTS_REGISTER_BLUEPRINT=True,
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND="cache",
        CELERY_CACHE_BACKEND="memory",
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        SUPPORT_EMAIL='*****@*****.**',
        PREFERRED_URL_SCHEME='https',
    )

    # Disable most of alembic logging.
    logging.getLogger('alembic').setLevel(logging.CRITICAL)
    yield app
    shutil.rmtree(instance_path)
Beispiel #3
0
def app(request, tmpdir):
    """Flask application fixture."""
    from b2share.factory import create_api

    instance_path = tmpdir.mkdir('instance_dir').strpath
    os.environ.update(
        B2SHARE_INSTANCE_PATH=os.environ.get(
            'INSTANCE_PATH', instance_path),
    )
    app = create_api(
        TESTING=True,
        SERVER_NAME='localhost:5000',
        JSONSCHEMAS_HOST='localhost:5000',
        DEBUG_TB_ENABLED=False,
        SQLALCHEMY_DATABASE_URI=os.environ.get(
            'SQLALCHEMY_DATABASE_URI', 'sqlite://'),
        LOGIN_DISABLED=False,
        WTF_CSRF_ENABLED=False,
        SECRET_KEY="CHANGE_ME",
        SECURITY_PASSWORD_SALT='CHANGEME',
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND="cache",
        CELERY_CACHE_BACKEND="memory",
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        SUPPORT_EMAIL='*****@*****.**',
    )

    # update the application with the configuration provided by the test
    if hasattr(request, 'param') and 'config' in request.param:
        app.config.update(**request.param['config'])

    with app.app_context():
        if app.config['SQLALCHEMY_DATABASE_URI'] != 'sqlite://':
            try:
                drop_database(db.engine.url)
            except ProgrammingError:
                pass
            create_database(db.engine.url)
        db.create_all()
        for deleted in current_search.delete(ignore=[404]):
            pass
        for created in current_search.create(None):
            pass

    def finalize():
        with app.app_context():
            db.drop_all()
            if app.config['SQLALCHEMY_DATABASE_URI'] != 'sqlite://':
                drop_database(db.engine.url)

    request.addfinalizer(finalize)
    return app