예제 #1
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_from_file
        db.drop_all()
        drop_alembic_version_table()

        alembic = Alembic(app=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-acceptance.xml.gz', wait_for_results=True)
        es.indices.refresh('records-hep')

        yield app
예제 #2
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
예제 #3
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
예제 #4
0
def test_migrate_from_mirror_doesnt_index_deleted_records(isolated_app):
    record_fixture_path = pkg_resources.resource_filename(
        __name__, os.path.join('fixtures', 'dummy.xml'))
    record_fixture_path_deleted = pkg_resources.resource_filename(
        __name__, os.path.join('fixtures', 'deleted_record.xml'))
    migrate_from_file(record_fixture_path, wait_for_results=True)
    migrate_from_file(record_fixture_path_deleted, wait_for_results=True)
    get_es_record('lit', 12345)
    with pytest.raises(RecordGetterError):
        get_es_record('lit', 1234)
def test_migrate_from_mirror_doesnt_index_deleted_records(isolated_app):
    record_fixture_path = pkg_resources.resource_filename(
        __name__,
        os.path.join('fixtures', 'dummy.xml')
    )
    record_fixture_path_deleted = pkg_resources.resource_filename(
        __name__,
        os.path.join('fixtures', 'deleted_record.xml')
    )
    migrate_from_file(record_fixture_path, wait_for_results=True)
    migrate_from_file(record_fixture_path_deleted, wait_for_results=True)
    get_es_record('lit', 12345)
    with pytest.raises(RecordGetterError):
        get_es_record('lit', 1234)
예제 #6
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
예제 #7
0
def test_orcid_push_disabled_on_migrate_from_mirror(app, cleanup, enable_orcid_push_feature):
    record_fixture_path = pkg_resources.resource_filename(
        __name__,
        os.path.join('fixtures', 'dummy.xml')
    )

    with patch('inspirehep.modules.orcid.api.push_record_with_orcid') as mock_push_record_with_orcid, \
            patch('inspirehep.modules.records.receivers.get_push_access_tokens') as mock_get_push_access_tokens:
        mock_get_push_access_tokens.return_value.remote_account.extra_data['orcid'] = '0000-0002-1825-0097'
        mock_get_push_access_tokens.return_value.access_token = 'mytoken'

        migrate_from_file(record_fixture_path, wait_for_results=True)
        mock_push_record_with_orcid.assert_not_called()

    prod_record = LegacyRecordsMirror.query.filter(LegacyRecordsMirror.recid == 12345).one()
    assert prod_record.valid

    assert app.config['FEATURE_FLAG_ENABLE_ORCID_PUSH']
def test_orcid_push_disabled_on_migrate_from_mirror(app, cleanup, enable_orcid_push_feature):
    record_fixture_path = pkg_resources.resource_filename(
        __name__,
        os.path.join('fixtures', 'dummy.xml')
    )

    with patch('inspirehep.modules.orcid.domain_models.OrcidPusher') as mock_orcid_pusher, \
            patch('inspirehep.modules.records.receivers.push_access_tokens') as mock_push_access_tokens:
        mock_push_access_tokens.get_access_tokens.return_value.remote_account.extra_data['orcid'] = '0000-0002-1825-0097'
        mock_push_access_tokens.get_access_tokens.return_value.access_token = 'mytoken'

        migrate_from_file(record_fixture_path, wait_for_results=True)
        mock_orcid_pusher.assert_not_called()

    prod_record = LegacyRecordsMirror.query.filter(LegacyRecordsMirror.recid == 12345).one()
    assert prod_record.valid

    assert app.config['FEATURE_FLAG_ENABLE_ORCID_PUSH']
예제 #9
0
def app(request):
    """Flask application fixtures.

    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()
    # 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_from_file
        db.drop_all()
        drop_alembic_version_table()

        alembic = Alembic(app=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-acceptance.xml.gz',
            wait_for_results=True)
        es.indices.refresh('records-hep')

        yield app