Ejemplo n.º 1
0
def test_init():
    """Test extension initialization."""
    app = Flask('testapp')
    ext = InvenioMARC21(app)
    assert 'invenio-marc21' in app.extensions

    app = Flask('testapp')
    ext = InvenioMARC21()
    assert 'invenio-marc21' not in app.extensions
    ext.init_app(app)
    assert 'invenio-marc21' in app.extensions
Ejemplo n.º 2
0
def es_app(request):
    """Flask application with records fixture."""
    app = Flask(__name__)
    app.config.update(
        JSONSCHEMAS_HOST='http://localhost:5000',
        SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI',
                                               'sqlite:///test.db'),
    )
    app.config[InvenioJSONSchemas.CONFIG_ENDPOINT] = '/'

    Babel(app)
    FlaskCLI(app)
    InvenioDB(app)
    InvenioRecords(app)
    InvenioMARC21(app)
    search = InvenioSearch(app)
    InvenioIndexer(app)
    InvenioJSONSchemas(app)

    with app.app_context():
        db.create_all()
        list(search.create())
        sleep(10)

    def teardown():
        with app.app_context():
            db.drop_all()
            list(search.delete())

    request.addfinalizer(teardown)

    return app
Ejemplo n.º 3
0
def app():
    """Flask application fixture."""
    instance_path = tempfile.mkdtemp()
    app = Flask('testapp', instance_path=instance_path)
    app.config.update(
        CELERY_ALWAYS_EAGER=True,
        CELERY_TASK_ALWAYS_EAGER=True,
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        CELERY_TASK_EAGER_PROPAGATES=True,
        CELERY_RESULT_BACKEND='cache',
        JSONSCHEMAS_HOST='inveniosoftware.org',
        TESTING=True,
        SECRET_KEY='CHANGE_ME',
        SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI',
                                               'sqlite:///test.db'),
        SQLALCHEMY_TRACK_MODIFICATIONS=True,
        SERVER_NAME='app',
        OAISERVER_ID_PREFIX='oai:inveniosoftware.org:recid/',
        OAISERVER_QUERY_PARSER_FIELDS=["title_statement"],
        OAISERVER_RECORD_INDEX='_all',
        OAISERVER_REGISTER_SET_SIGNALS=True,
    )
    if not hasattr(app, 'cli'):
        from flask_cli import FlaskCLI
        FlaskCLI(app)
    InvenioDB(app)
    FlaskCeleryExt(app)
    InvenioJSONSchemas(app)
    InvenioRecords(app)
    InvenioPIDStore(app)
    InvenioMARC21(app)
    client = Elasticsearch(hosts=[os.environ.get('ES_HOST', 'localhost')])
    search = InvenioSearch(app, client=client)
    search.register_mappings('records', 'data')
    InvenioIndexer(app)
    InvenioOAIServer(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()
        list(search.delete(ignore=[404]))
        list(search.create())
        search.flush_and_refresh('_all')

    with app.app_context():
        yield app

    with app.app_context():
        db.session.close()
        if str(db.engine.url) != 'sqlite://':
            drop_database(str(db.engine.url))
        list(search.delete(ignore=[404]))
        search.client.indices.delete("*-percolators")
    shutil.rmtree(instance_path)
def test_view(app):
    """Test view."""
    Babel(app)
    InvenioMARC21(app)
    with app.test_client() as client:
        res = client.get("/")
        assert res.status_code == 200
        assert 'Welcome to Invenio-MARC21' in str(res.data)
Ejemplo n.º 5
0
def es_app(request):
    """Flask application with records fixture."""
    app = Flask(__name__)
    app.config.update(SQLALCHEMY_DATABASE_URI=os.environ.get(
        'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'), )

    Babel(app)
    FlaskCLI(app)
    InvenioDB(app)
    InvenioRecords(app)
    InvenioMARC21(app)

    sleep(10)

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

    def teardown():
        with app.app_context():
            db.drop_all()

    request.addfinalizer(teardown)

    return app
Ejemplo n.º 6
0
def es_app(request):
    """Flask application with records fixture."""
    app = Flask(__name__)
    app.config.update(
        JSONSCHEMAS_ENDPOINT="/",
        JSONSCHEMAS_HOST="http://localhost:5000",
        SQLALCHEMY_DATABASE_URI=os.environ.get(
            "SQLALCHEMY_DATABASE_URI", "sqlite:///test.db"
        ),
    )

    Babel(app)
    if not hasattr(app, "cli"):
        from flask_cli import FlaskCLI

        FlaskCLI(app)
    InvenioDB(app)
    InvenioRecords(app)
    InvenioMARC21(app)
    search = InvenioSearch(app)
    InvenioIndexer(app)
    InvenioJSONSchemas(app)

    with app.app_context():
        db.create_all()
        list(search.create())
        sleep(10)

    def teardown():
        with app.app_context():
            db.drop_all()
            list(search.delete())

    request.addfinalizer(teardown)

    return app
Ejemplo n.º 7
0
# Create Flask application
app = Flask(__name__)
app.config.update(
    APP_BASE_TEMPLATE="app/base.html",
    SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI',
                                      'sqlite:///app.db'),
)
Babel(app)
FlaskCLI(app)
InvenioDB(app)
InvenioTheme(app)
assets = InvenioAssets(app)
InvenioRecords(app)
InvenioPIDStore(app)
InvenioSearch(app)
InvenioMARC21(app)

# register CSS bundle
css = NpmBundle(
    # my scss file
    'app/scss/app.scss',
    filters='scss, cleancss',
    output='gen/styles.%(version)s.css',
)
# register my stylesheets
assets.env.register('app_css', css)


@app.route('/example/<string:index>', methods=['GET'])
def example(index):
    """Index page."""