def test_init():
    """Test extension initialization."""
    app = Flask('testapp')
    ext = InvenioCollections(app)
    assert 'invenio-collections' in app.extensions
    with app.app_context():
        current_collections.unregister_signals()

    app = Flask('testapp')
    ext = InvenioCollections()
    assert 'invenio-collections' not in app.extensions
    ext.init_app(app)
    assert 'invenio-collections' in app.extensions
    with app.app_context():
        current_collections.unregister_signals()
Ejemplo n.º 2
0
def test_cache_cannot_be_overridden_if_it_was_set(app):
    """Test cache preference from a constructor over configuration."""
    first_cache = SimpleCache()
    second_cache = SimpleCache()
    app.config['COLLECTIONS_CACHE'] = second_cache
    ext = InvenioCollections(app, cache=first_cache)
    assert ext.cache is first_cache
Ejemplo n.º 3
0
def app(request):
    """Flask application fixture."""
    app = Flask('testapp')
    app.config.update(
        TESTING=True,
        SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI',
                                          'sqlite://'),
        SERVER_NAME='localhost',
    )
    Babel(app)
    Menu(app)
    Breadcrumbs(app)
    InvenioDB(app)
    InvenioCollections(app)
    InvenioRecords(app)

    app.register_blueprint(blueprint)

    with app.app_context():
        if str(db.engine.url) != 'sqlite://' and \
                not database_exists(str(db.engine.url)):
            create_database(str(db.engine.url))
        db.create_all()

    def teardown():
        with app.app_context():
            if str(db.engine.url) != 'sqlite://':
                drop_database(str(db.engine.url))

    request.addfinalizer(teardown)

    with app.app_context():
        db.create_all()

    return app
Ejemplo n.º 4
0
def test_init():
    """Test extension initialization."""
    app = Flask('testapp')
    ext = InvenioCollections(app)
    assert 'invenio-collections' in app.extensions
    ext.unregister_signals()

    app = Flask('testapp')
    ext = InvenioCollections()
    assert 'invenio-collections' not in app.extensions
    ext.init_app(app)
    assert 'invenio-collections' in app.extensions
    with app.app_context():
        current_collections.unregister_signals()
Ejemplo n.º 5
0
def app(request):
    """Flask application fixture."""
    instance_path = tempfile.mkdtemp()
    app_ = Flask(__name__, instance_path=instance_path)
    app_.config.update(
        SECRET_KEY='CHANGE_ME',
        SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI',
                                               'sqlite://'),
        SQLALCHEMY_TRACK_MODIFICATIONS=True,
        TESTING=True,
    )
    # app_.register_blueprint(files_rest_blueprint)
    # FlaskCLI(app_)
    InvenioDB(app_)
    InvenioCollections(app_)
    InvenioCollectionsMetadata(app_)
    InvenioJSONSchemas(app_)
    # (app_)

    with app_.app_context():
        yield app_

    shutil.rmtree(instance_path)
Ejemplo n.º 6
0
   $ export FLASK_APP=app.py
   $ export FLASK_DEBUG=1
   $ flask run
"""

from __future__ import absolute_import, print_function

import os

from flask import Flask
from flask_babelex import Babel

from invenio_collections import InvenioCollections
from invenio_collections_metadata import InvenioCollectionsMetadata
from invenio_db import InvenioDB

# Create Flask application
app = Flask(__name__)
app.config.update(
    SECRET_KEY='CHANGE_ME',
    SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI',
                                           'sqlite://'),
    SQLALCHEMY_TRACK_MODIFICATIONS=True,
    TESTING=True,
)
Babel(app)
# instance_path = tempfile.mkdtemp()
InvenioDB(app)
InvenioCollections(application)
InvenioCollectionsMetadata(app)
Ejemplo n.º 7
0
def test_instance_in_config_variable(app):
    """Test that cache instance can be directly used from a config variable."""
    cache = SimpleCache()
    app.config['COLLECTIONS_CACHE'] = cache
    ext = InvenioCollections(app)
    assert ext.cache is cache
Ejemplo n.º 8
0
def test_importable_config_variable(app):
    """Test that cache can be imported from a config variable."""
    app.config['COLLECTIONS_CACHE'] = 'test_receivers._global_simple_cache'
    ext = InvenioCollections(app)
    assert ext.cache is _global_simple_cache
Ejemplo n.º 9
0
from invenio_search import InvenioSearch

from invenio_collections import InvenioCollections
from invenio_collections.models import Collection

# Create Flask application
app = Flask(__name__)
app.config.update(
    SEARCH_ELASTIC_KEYWORD_MAPPING={None: ['_all']},
    SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI',
                                      'sqlite:///app.db'),
)

InvenioDB(app)
InvenioRecords(app)
InvenioCollections(app)
search = InvenioSearch(app)

# Checking that the register record signal is enabled in collections.
assert app.config.get('COLLECTIONS_REGISTER_RECORD_SIGNALS')


@app.route('/', methods=['GET'])
def index():
    """Query Elasticsearch using "collection" param in query string."""
    collection_names = request.values.getlist('collection')

    # Validation of collection names.
    collections = Collection.query
    if collection_names:
        collections = collections.filter(Collection.name.in_(collection_names))