def app(request):
    """Flask application fixture."""
    app = create_app()
    app.config.update({'DEBUG': True})

    with app.app_context():
        # Imports must be local, otherwise tasks default to pickle serializer.
        from inspirehep.modules.migrator.tasks import add_citation_counts, migrate
        from inspirehep.modules.fixtures.files import init_all_storage_paths
        from inspirehep.modules.fixtures.users import init_users_and_permissions

        db.drop_all()
        db.create_all()

        sleep(10)  # Makes sure that ES is up.
        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()

        migrate('./inspirehep/demosite/data/demo-records.xml.gz',
                wait_for_results=True)
        es.indices.refresh(
            'records-hep')  # Makes sure that all HEP records were migrated.

        add_citation_counts()
        es.indices.refresh(
            'records-hep')  # Makes sure that all citation counts were added.

        yield app
示例#2
0
def app(request):
    """Flask application fixture."""
    app = create_app()

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

            sleep(10)  # Makes sure that ES is up.
            _es = app.extensions['invenio-search']
            list(_es.delete(ignore=[404]))

    request.addfinalizer(teardown)

    with app.app_context():
        # Imports must be local, otherwise tasks default to pickle serializer.
        from inspirehep.modules.migrator.tasks import add_citation_counts, migrate

        db.drop_all()
        db.create_all()

        sleep(10)  # Makes sure that ES is up.
        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        migrate('./inspirehep/demosite/data/demo-records.xml.gz', wait_for_results=True)
        es.indices.refresh('records-hep')  # Makes sure that all HEP records were migrated.

        add_citation_counts(request_timeout=40)
        es.indices.refresh('records-hep')  # Makes sure that all citation counts were added.

        yield app
示例#3
0
def workflow_app(higgs_ontology):
    """Flask application with no records and function scope.

    .. deprecated:: 2017-09-18
       Use ``app`` instead.
    """
    RT_URL = "http://rt.inspire"

    with requests_mock.Mocker() as m:
        m.register_uri(requests_mock.ANY,
                       re.compile('.*' + RT_URL + '.*'),
                       status_code=200,
                       text='Status 200')

        app = create_app(
            BEARD_API_URL="http://example.com/beard",
            CELERY_TASK_ALWAYS_EAGER=True,
            CELERY_CACHE_BACKEND='memory',
            CELERY_TASK_EAGER_PROPAGATES=True,
            CELERY_RESULT_BACKEND='cache',
            CFG_BIBCATALOG_SYSTEM_RT_URL=RT_URL,
            DEBUG=False,
            # Tests may fail when turned on because of Flask bug (A setup function was called after the first request was handled. when initializing - when Alembic initialization)
            HEP_ONTOLOGY_FILE=higgs_ontology,
            PRODUCTION_MODE=True,
            LEGACY_ROBOTUPLOAD_URL=('http://localhost:1234'),
            MAGPIE_API_URL="http://example.com/magpie",
            WORKFLOWS_FILE_LOCATION="/",
            WORKFLOWS_MATCH_REMOTE_SERVER_URL="http://legacy_search.endpoint/",
            WTF_CSRF_ENABLED=False,
        )

    with app.app_context():
        yield app
示例#4
0
def small_app():
    """Flask application fixture."""
    app = create_app()
    app.config.update({'DEBUG': True})

    with app.app_context():
        # Imports must be local, otherwise tasks default to pickle serializer.
        from inspirehep.modules.migrator.tasks.records import migrate
        from inspirehep.modules.fixtures.collections import init_collections
        from inspirehep.modules.fixtures.files import init_all_storage_paths
        from inspirehep.modules.fixtures.users import init_users_and_permissions

        db.drop_all()
        db.create_all()

        sleep(10)
        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()
        init_collections()

        migrate('./inspirehep/demosite/data/demo-records-small.xml', wait_for_results=True)
        es.indices.refresh('records-hep')

        yield app
示例#5
0
def app(request):
    """Flask application fixture."""
    app = create_app()
    app.config.update({"DEBUG": True})

    with app.app_context():
        # Imports must be local, otherwise tasks default to pickle serializer.
        from inspirehep.modules.migrator.tasks import add_citation_counts, migrate
        from inspirehep.modules.fixtures.files import init_all_storage_paths
        from inspirehep.modules.fixtures.users import init_users_and_permissions

        db.drop_all()
        db.create_all()

        sleep(10)  # Makes sure that ES is up.
        _es = app.extensions["invenio-search"]
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()

        migrate("./inspirehep/demosite/data/demo-records.xml.gz", wait_for_results=True)
        es.indices.refresh("records-hep")  # Makes sure that all HEP records were migrated.

        add_citation_counts()
        es.indices.refresh("records-hep")  # Makes sure that all citation counts were added.

        yield app
示例#6
0
def small_app():
    """Flask application with few records and module scope.

    .. deprecated:: 2017-09-18
       Use ``app`` instead.
    """
    app = create_app()
    app.config.update({'DEBUG': True})

    with app.app_context():
        # Celery task imports must be local, otherwise their
        # configuration would use the default pickle serializer.
        from inspirehep.modules.migrator.tasks import migrate

        db.drop_all()
        db.create_all()

        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()
        init_collections()

        migrate('./inspirehep/demosite/data/demo-records-small.xml',
                wait_for_results=True)
        es.indices.refresh('records-hep')

        yield app
示例#7
0
def app(request):
    """Flask application fixture."""
    app = create_app()

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

            sleep(10)  # Makes sure that ES is up.
            _es = app.extensions['invenio-search']
            list(_es.delete(ignore=[400]))

    request.addfinalizer(teardown)

    with app.app_context():
        # Imports must be local, otherwise tasks default to pickle serializer.
        from inspirehep.modules.migrator.tasks import add_citation_counts, migrate

        db.drop_all()
        db.create_all()

        sleep(10)  # Makes sure that ES is up.
        _es = app.extensions['invenio-search']
        list(_es.create(ignore=[400]))

        migrate('./inspirehep/demosite/data/demo-records.xml.gz',
                wait_for_results=True)
        es.indices.refresh(
            'records-hep')  # Makes sure that all HEP records were migrated.

        add_citation_counts(request_timeout=20)
        es.indices.refresh(
            'records-hep')  # Makes sure that all citation counts were added.

        yield app
示例#8
0
def app(request):
    """Flask application fixture.

    Creates a Flask application with a simple testing configuration,
    then creates an application context and inside of it recreates
    all databases and indices from the fixtures. Finally it yields,
    so that all tests that explicitly use the ``app`` fixture have
    access to an application context.

    See: http://flask.pocoo.org/docs/0.12/appcontext/.
    """
    app = create_app()
    app.config.update({'DEBUG': True})

    with app.app_context():
        # Celery task imports must be local, otherwise their
        # configuration would use the default pickle serializer.
        from inspirehep.modules.migrator.tasks import migrate

        db.drop_all()
        db.create_all()

        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()
        init_collections()

        migrate('./inspirehep/demosite/data/demo-records-acceptance.xml.gz', wait_for_results=True)
        es.indices.refresh('records-hep')

        yield app
示例#9
0
def small_app():
    """Flask application fixture."""
    app = create_app()
    app.config.update({'DEBUG': True})

    with app.app_context():
        # Imports must be local, otherwise tasks default to pickle serializer.
        from inspirehep.modules.migrator.tasks.records import migrate
        from inspirehep.modules.fixtures.collections import init_collections
        from inspirehep.modules.fixtures.files import init_all_storage_paths
        from inspirehep.modules.fixtures.users import init_users_and_permissions

        db.drop_all()
        db.create_all()

        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()
        init_collections()

        migrate('./inspirehep/demosite/data/demo-records-small.xml',
                wait_for_results=True)
        es.indices.refresh('records-hep')

        yield app
示例#10
0
def app():
    """
    Deprecated: do not use this fixture for new tests, unless for very
    specific use cases. Use `isolated_app` instead.

    Flask application with demosite data and without any database isolation:
    any db transaction performed during the tests are persisted into the db.

    Creates a Flask application with a simple testing configuration,
    then creates an application context and inside of it recreates
    all databases and indices from the fixtures. Finally it yields,
    so that all tests that explicitly use the ``app`` fixture have
    access to an application context.

    See: http://flask.pocoo.org/docs/0.12/appcontext/.
    """
    app = create_app(
        DEBUG=False,
        # Tests may fail when turned on because of Flask bug (A setup function was called after the first request was handled. when initializing - when Alembic initialization)
        WTF_CSRF_ENABLED=False,
        CELERY_TASK_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_TASK_EAGER_PROPAGATES=True,
        SECRET_KEY='secret!',
        RECORD_EDITOR_FILE_UPLOAD_FOLDER='tests/integration/editor/temp',
        TESTING=True,
    )

    with app.app_context():
        # Celery task imports must be local, otherwise their
        # configuration would use the default pickle serializer.
        from inspirehep.modules.migrator.tasks import add_citation_counts
        from inspirehep.modules.migrator.tasks import migrate_from_file

        db.session.close()
        db.drop_all()
        drop_alembic_version_table()

        alembic = Alembic(app=current_app)
        alembic.upgrade()

        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()

        migrate_from_file('./inspirehep/demosite/data/demo-records.xml.gz',
                          wait_for_results=True)
        es.indices.refresh(
            'records-hep')  # Makes sure that all HEP records were migrated.

        add_citation_counts()
        es.indices.refresh(
            'records-hep')  # Makes sure that all citation counts were added.

        yield app
示例#11
0
def app():
    """
    Deprecated: do not use this fixtures for new tests, unless for very
    specific use cases. Use `isolated_app` instead.

    Flask application with demosite data and without any database isolation:
    any db transaction performed during the tests are persisted into the db.

    Creates a Flask application with a simple testing configuration,
    then creates an application context and inside of it recreates
    all databases and indices from the fixtures. Finally it yields,
    so that all tests that explicitly use the ``app`` fixtures have
    access to an application context.

    See: http://flask.pocoo.org/docs/0.12/appcontext/.
    """
    app = create_app(
        DEBUG=False,
        # Tests may fail when turned on because of Flask bug (A setup function was called after the first request was handled. when initializing - when Alembic initialization)
        WTF_CSRF_ENABLED=False,
        CELERY_TASK_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_TASK_EAGER_PROPAGATES=True,
        SECRET_KEY='secret!',
        RECORD_EDITOR_FILE_UPLOAD_FOLDER='tests/integration/editor/temp',
        TESTING=True,
    )

    with app.app_context(), mock.patch(
            'inspirehep.modules.records.receivers.index_modified_citations_from_record.delay'
    ):
        # Celery task imports must be local, otherwise their
        # configuration would use the default pickle serializer.
        from inspirehep.modules.migrator.tasks import migrate_from_file

        db.session.close()
        db.drop_all()
        drop_alembic_version_table()

        alembic = Alembic(app=current_app)
        alembic.upgrade()

        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()
        init_authentication_token()

        migrate_from_file('./inspirehep/demosite/data/demo-records.xml.gz', wait_for_results=True)

        es.indices.refresh('records-hep')  # Makes sure that all HEP records were migrated.

        yield app
示例#12
0
def alembic_app():
    """Flask application for Alembic tests."""
    app = create_app(
        DEBUG=True,
        SQLALCHEMY_DATABASE_URI='postgresql+psycopg2://inspirehep:dbpass123@localhost:5432/inspirehep_alembic',
    )

    with app.app_context():
        db.create_all()
        yield app
        db.drop_all()
        drop_alembic_version_table()
示例#13
0
def app():
    app = create_app(
        DEBUG=True,
        WTF_CSRF_ENABLED=False,
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        TESTING=True,
    )

    with app.app_context():
        yield app
示例#14
0
def app():
    app = create_app(
        DEBUG=True,
        WTF_CSRF_ENABLED=False,
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        TESTING=True,
    )

    with app.app_context():
        yield app
示例#15
0
def alembic_app():
    """Flask application with no records and module scope."""
    app = create_app(
        SQLALCHEMY_DATABASE_URI='postgresql+psycopg2://inspirehep:dbpass123@localhost:5432/inspirehep_alembic'
    )
    app.config.update({
        'DEBUG': True,
    })

    with app.app_context():
        db.create_all()
        yield app
        db.drop_all()
示例#16
0
def app():
    """Flask application.

    Creates a Flask application with a simple testing configuration,
    then creates an application context and inside of it recreates
    all databases and indices from the fixtures. Finally it yields,
    so that all tests that explicitly use the ``app`` fixture have
    access to an application context.

    See: http://flask.pocoo.org/docs/0.12/appcontext/.
    """
    app = create_app(
        DEBUG=True,
        WTF_CSRF_ENABLED=False,
        CELERY_TASK_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_TASK_EAGER_PROPAGATES=True,
        SECRET_KEY='secret!',
        RECORD_EDITOR_FILE_UPLOAD_FOLDER='tests/integration/editor/temp',
        TESTING=True,
    )

    with app.app_context():
        # Celery task imports must be local, otherwise their
        # configuration would use the default pickle serializer.
        from inspirehep.modules.migrator.tasks import add_citation_counts, migrate_from_file

        db.drop_all()
        db.create_all()

        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()
        init_collections()

        migrate_from_file('./inspirehep/demosite/data/demo-records.xml.gz',
                          wait_for_results=True)
        es.indices.refresh(
            'records-hep')  # Makes sure that all HEP records were migrated.

        add_citation_counts()
        es.indices.refresh(
            'records-hep')  # Makes sure that all citation counts were added.

        yield app
示例#17
0
def workflow_app():
    app = create_app(
        BEARD_API_URL="http://example.com/beard",
        DEBUG=True,
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        PRODUCTION_MODE=True,
        LEGACY_ROBOTUPLOAD_URL=('http://localhost:1234'),
        MAGPIE_API_URL="http://example.com/magpie",
        WTF_CSRF_ENABLED=False,
    )

    with app.app_context():
        yield app
示例#18
0
def email_app(request):
    """Email-aware Flask application fixture."""
    app = create_app(
        CFG_SITE_SUPPORT_EMAIL='*****@*****.**',
        INSPIRELABS_FEEDBACK_EMAIL='*****@*****.**',
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        MAIL_SUPPRESS_SEND=True,
    )
    FlaskCeleryExt(app)

    InvenioMail(app, StringIO())

    with app.app_context():
        yield app
示例#19
0
def email_app(request):
    """Email-aware Flask application fixture."""
    app = create_app(
        CFG_SITE_SUPPORT_EMAIL='*****@*****.**',
        INSPIRELABS_FEEDBACK_EMAIL='*****@*****.**',
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        MAIL_SUPPRESS_SEND=True,
    )
    FlaskCeleryExt(app)

    InvenioMail(app, StringIO())

    with app.app_context():
        yield app
def workflow_app():
    app = create_app(
        BEARD_API_URL="http://example.com/beard",
        DEBUG=True,
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        PRODUCTION_MODE=True,
        LEGACY_ROBOTUPLOAD_URL=(
            'http://localhost:1234'
        ),
        MAGPIE_API_URL="http://example.com/magpie",
        WTF_CSRF_ENABLED=False,
    )

    with app.app_context():
        yield app
示例#21
0
def app(request):
    """Flask application fixture."""
    instance_path = tempfile.mkdtemp()

    os.environ.update(APP_INSTANCE_PATH=os.environ.get("INSTANCE_PATH", instance_path))

    app = create_app(
        DEBUG_TB_ENABLED=False,
        SQLALCHEMY_DATABASE_URI=os.environ.get("SQLALCHEMY_DATABASE_URI", "sqlite:///test.db"),
        TESTING=True,
    )

    def teardown():
        shutil.rmtree(instance_path)

    request.addfinalizer(teardown)

    with app.app_context():
        yield app
示例#22
0
def app():
    """Flask application fixture."""
    instance_path = tempfile.mkdtemp()

    os.environ.update(
        APP_INSTANCE_PATH=os.environ.get(
            'INSTANCE_PATH', instance_path),
    )

    app = create_app(
        DEBUG_TB_ENABLED=False,
        SQLALCHEMY_DATABASE_URI=os.environ.get(
            'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'),
        TESTING=True,
    )

    with app.app_context():
        yield app

    shutil.rmtree(instance_path)
示例#23
0
def app():
    """Flask application fixture."""
    app = create_app(
        DEBUG=True,
        WTF_CSRF_ENABLED=False,
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        SECRET_KEY='secret!',
        TESTING=True,
    )

    with app.app_context():
        # Imports must be local, otherwise tasks default to pickle serializer.
        from inspirehep.modules.migrator.tasks import add_citation_counts, migrate
        from inspirehep.modules.fixtures.collections import init_collections
        from inspirehep.modules.fixtures.files import init_all_storage_paths
        from inspirehep.modules.fixtures.users import init_users_and_permissions

        db.drop_all()
        db.create_all()

        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()
        init_collections()

        migrate('./inspirehep/demosite/data/demo-records.xml.gz',
                wait_for_results=True)
        es.indices.refresh(
            'records-hep')  # Makes sure that all HEP records were migrated.

        add_citation_counts()
        es.indices.refresh(
            'records-hep')  # Makes sure that all citation counts were added.

        yield app
示例#24
0
def workflow_app():
    """Flask application with no records and function scope.

    .. deprecated:: 2017-09-18
       Use ``app`` instead.
    """
    app = create_app(
        BEARD_API_URL="http://example.com/beard",
        DEBUG=True,
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        PRODUCTION_MODE=True,
        LEGACY_ROBOTUPLOAD_URL=('http://localhost:1234'),
        MAGPIE_API_URL="http://example.com/magpie",
        WTF_CSRF_ENABLED=False,
    )

    with app.app_context():
        yield app
示例#25
0
def app(request):
    """Flask application fixture."""
    instance_path = tempfile.mkdtemp()

    os.environ.update(APP_INSTANCE_PATH=os.environ.get('INSTANCE_PATH',
                                                       instance_path), )

    app = create_app(
        DEBUG_TB_ENABLED=False,
        SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI',
                                               'sqlite:///test.db'),
        TESTING=True,
    )

    def teardown():
        shutil.rmtree(instance_path)

    request.addfinalizer(teardown)

    with app.app_context():
        yield app
示例#26
0
def workflow_app(higgs_ontology):
    """Flask application with no records and function scope.

    .. deprecated:: 2017-09-18
       Use ``app`` instead.
    """
    RT_URL = "http://rt.inspire"

    with requests_mock.Mocker() as m:
        m.register_uri(
            requests_mock.ANY,
            re.compile('.*' + RT_URL + '.*'),
            status_code=200,
            text='Status 200'
        )

        app = create_app(
            BEARD_API_URL="http://example.com/beard",
            CELERY_TASK_ALWAYS_EAGER=True,
            CELERY_CACHE_BACKEND='memory',
            CELERY_TASK_EAGER_PROPAGATES=True,
            CELERY_RESULT_BACKEND='cache',
            CFG_BIBCATALOG_SYSTEM_RT_URL=RT_URL,
            DEBUG=False,
            # Tests may fail when turned on because of Flask bug (A setup function was called after the first request was handled. when initializing - when Alembic initialization)
            HEP_ONTOLOGY_FILE=higgs_ontology,
            PRODUCTION_MODE=True,
            LEGACY_ROBOTUPLOAD_URL=(
                'http://localhost:1234'
            ),
            MAGPIE_API_URL="http://example.com/magpie",
            WORKFLOWS_FILE_LOCATION="/",
            WORKFLOWS_MATCH_REMOTE_SERVER_URL="http://legacy_search.endpoint/",
            WTF_CSRF_ENABLED=False,
        )

    with app.app_context():
        with mock.patch('inspirehep.modules.records.receivers.index_modified_citations_from_record.apply_async'):

            yield app
示例#27
0
def app():
    """
    Flask application without demosite data and without database isolation:
    any db transaction performed during the tests are persisted into the db,
    as well as any operation to Elasticsearch.
    Isolation is provided by `empty_environment`, which runs before every tests
    and initializes DB and ES.
    The Flask app is configured in such a way to use Celery and RabbitMQ in the
    test environment, to achieve async tasks testability.
    """
    app = create_app()
    config = dict(
        DEBUG=True,
        CELERY_BROKER_URL='pyamqp://*****:*****@test-rabbitmq:5672',
        CELERY_RESULT_BACKEND='redis://test-redis:6379/1',
        CELERY_CACHE_BACKEND='redis://test-redis:6379/1',
        TESTING=True,
    )
    app.config.update(config)

    with app.app_context():
        yield app
示例#28
0
def app():
    """
    Flask application without demosite data and without database isolation:
    any db transaction performed during the tests are persisted into the db,
    as well as any operation to Elasticsearch.
    Isolation is provided by `empty_environment`, which runs before every tests
    and initializes DB and ES.
    The Flask app is configured in such a way to use Celery and RabbitMQ in the
    test environment, to achieve async tasks testability.
    """
    app = create_app()
    config = dict(
        DEBUG=True,
        CELERY_BROKER_URL='pyamqp://*****:*****@test-rabbitmq:5672',
        CELERY_RESULT_BACKEND='redis://test-redis:6379/1',
        CELERY_CACHE_BACKEND='redis://test-redis:6379/1',
        TESTING=True,
    )
    app.config.update(config)

    with app.app_context():
        yield app
示例#29
0
def app():
    """Flask application.

    Creates a Flask application with a simple testing configuration,
    then creates an application context and yields, so that all tests
    have access to one.

    See: http://flask.pocoo.org/docs/0.12/appcontext/.
    """
    app = create_app(
        DEBUG=True,
        WTF_CSRF_ENABLED=False,
        CELERY_TASK_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_TASK_EAGER_PROPAGATES=True,
        TESTING=True,
        PRODUCTION_MODE=True,
    )

    with app.app_context():
        yield app
示例#30
0
def app():
    """Flask application fixture."""
    app = create_app(
        DEBUG=True,
        WTF_CSRF_ENABLED=False,
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        TESTING=True,
    )

    with app.app_context():
        # Imports must be local, otherwise tasks default to pickle serializer.
        from inspirehep.modules.migrator.tasks.records import add_citation_counts, migrate
        from inspirehep.modules.fixtures.collections import init_collections
        from inspirehep.modules.fixtures.files import init_all_storage_paths
        from inspirehep.modules.fixtures.users import init_users_and_permissions

        db.drop_all()
        db.create_all()

        sleep(10)  # Makes sure that ES is up.
        _es = app.extensions['invenio-search']
        list(_es.delete(ignore=[404]))
        list(_es.create(ignore=[400]))

        init_all_storage_paths()
        init_users_and_permissions()
        init_collections()

        migrate('./inspirehep/demosite/data/demo-records.xml.gz', wait_for_results=True)
        es.indices.refresh('records-hep')  # Makes sure that all HEP records were migrated.

        add_citation_counts()
        es.indices.refresh('records-hep')  # Makes sure that all citation counts were added.

        yield app
示例#31
0
def app():
    """Flask application.

    Creates a Flask application with a simple testing configuration,
    then creates an application context and yields, so that all tests
    have access to one.

    See: http://flask.pocoo.org/docs/0.12/appcontext/.
    """
    app = create_app(
        DEBUG=False,
        # Tests may fail when turned on because of Flask bug (A setup function was called after the first request was handled. when initializing - when Alembic initialization)
        WTF_CSRF_ENABLED=False,
        CELERY_TASK_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_TASK_EAGER_PROPAGATES=True,
        TESTING=True,
        PRODUCTION_MODE=True,
    )

    with app.app_context():
        yield app
示例#32
0
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
# inspirehep is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.


from flask_celeryext import create_celery_app

from inspirehep.factory import create_app

celery = create_celery_app(create_app(LOGGING_SENTRY_CELERY=True))
示例#33
0
#
# This file is part of INSPIRE.
# Copyright (C) 2016 CERN.
#
# INSPIRE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# INSPIRE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with INSPIRE. If not, see <http://www.gnu.org/licenses/>.
#
# In applying this licence, CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.
"""INSPIREHEP WSGI app instantiation."""

from __future__ import absolute_import, division, print_function

from inspirehep.factory import create_app

application = create_app()
if application.debug:
    from werkzeug.debug import DebuggedApplication
    application = DebuggedApplication(application, evalex=True)
示例#34
0
# -*- coding: utf-8 -*-

"""inspirehep Invenio WSGI application."""

from __future__ import absolute_import, print_function

from inspirehep.factory import create_app

application = create_app()

if application.debug:
    # apply Werkzeug WSGI middleware
    from werkzeug.debug import DebuggedApplication
    application = DebuggedApplication(application, evalex=True)