コード例 #1
0
def test_alembic_revision_34b150f80576(app, db):
    ext = app.extensions['invenio-db']

    if db.engine.name == 'sqlite':
        raise pytest.skip('Upgrades are not supported on SQLite.')

    db.drop_all()
    drop_alembic_version_table()

    with app.app_context():
        inspector = inspect(db.engine)
        assert 'crawler_job' not in inspector.get_table_names()
        assert 'crawler_workflows_object' not in inspector.get_table_names()

    ext.alembic.upgrade(target='34b150f80576')
    with app.app_context():
        inspector = inspect(db.engine)
        assert 'crawler_job' in inspector.get_table_names()
        assert 'crawler_workflows_object' in inspector.get_table_names()

    ext.alembic.downgrade(target='df8d1c51b820')
    with app.app_context():
        inspector = inspect(db.engine)
        assert 'crawler_job' not in inspector.get_table_names()
        assert 'crawler_workflows_object' not in inspector.get_table_names()

    drop_alembic_version_table()
コード例 #2
0
def test_alembic_revision_fddb3cfe7a9c(alembic_app):
    ext = alembic_app.extensions['invenio-db']

    if db.engine.name == 'sqlite':
        raise pytest.skip('Upgrades are not supported on SQLite.')

    db.drop_all()
    drop_alembic_version_table()

    inspector = inspect(db.engine)
    assert 'inspire_prod_records' not in inspector.get_table_names()
    assert 'workflows_audit_logging' not in inspector.get_table_names()
    assert 'workflows_pending_record' not in inspector.get_table_names()

    ext.alembic.upgrade(target='fddb3cfe7a9c')
    inspector = inspect(db.engine)
    assert 'inspire_prod_records' in inspector.get_table_names()
    assert 'workflows_audit_logging' in inspector.get_table_names()
    assert 'workflows_pending_record' in inspector.get_table_names()

    ext.alembic.downgrade(target='a82a46d12408')
    inspector = inspect(db.engine)
    assert 'inspire_prod_records' not in inspector.get_table_names()
    assert 'workflows_audit_logging' not in inspector.get_table_names()
    assert 'workflows_pending_record' not in inspector.get_table_names()

    drop_alembic_version_table()
コード例 #3
0
def test_alembic_revision_a26f133d42a9(app, db):
    ext = app.extensions['invenio-db']

    if db.engine.name == 'sqlite':
        raise pytest.skip('Upgrades are not supported on SQLite.')

    db.drop_all()
    drop_alembic_version_table()

    with app.app_context():
        inspector = inspect(db.engine)
        assert 'workflows_workflow' not in inspector.get_table_names()
        assert 'workflows_object' not in inspector.get_table_names()

    ext.alembic.upgrade(target='a26f133d42a9')
    with app.app_context():
        inspector = inspect(db.engine)
        assert 'workflows_workflow' in inspector.get_table_names()
        assert 'workflows_object' in inspector.get_table_names()

    ext.alembic.downgrade(target='720ddf51e24b')
    with app.app_context():
        inspector = inspect(db.engine)
        assert 'workflows_workflow' not in inspector.get_table_names()
        assert 'workflows_object' not in inspector.get_table_names()

    drop_alembic_version_table()
コード例 #4
0
def test_alembic_revision_cb9f81e8251c(alembic_app):
    def get_indexes(tablename):
        index_names = db.session.execute("select indexname from pg_indexes where tablename='{}'".format(tablename)).fetchall()
        return [index[0] for index in index_names]

    ext = alembic_app.extensions['invenio-db']

    if db.engine.name == 'sqlite':
        raise pytest.skip('Upgrades are not supported on SQLite.')

    ext.alembic.stamp()

    ext.alembic.downgrade(target='fddb3cfe7a9c')

    index_names = get_indexes('records_metadata')
    assert 'idxgindoctype' not in index_names
    assert 'idxgintitles' not in index_names
    assert 'idxginjournaltitle' not in index_names
    assert 'idxgincollections' not in index_names

    ext.alembic.upgrade(target='cb9f81e8251c')

    index_names = get_indexes('records_metadata')
    assert 'idxgindoctype' in index_names
    assert 'idxgintitles' in index_names
    assert 'idxginjournaltitle' in index_names
    assert 'idxgincollections' in index_names

    drop_alembic_version_table()
コード例 #5
0
def test_alembic(base_app, database):
    """Test alembic recipes."""
    db = database
    ext = base_app.extensions['invenio-db']

    if db.engine.name == 'sqlite':
        raise pytest.skip('Upgrades are not supported on SQLite.')

    # Check that this package's SQLAlchemy models have been properly registered
    tables = [x.name for x in db.get_tables_for_bind()]
    assert 'communities_metadata' in tables
    assert 'communities_files' in tables
    assert 'communities_metadata_version' in tables

    # Check that Alembic agrees that there's no further tables to create.
    assert not ext.alembic.compare_metadata()

    # Drop everything and recreate tables all with Alembic
    db.drop_all()
    drop_alembic_version_table()
    ext.alembic.upgrade()
    assert not ext.alembic.compare_metadata()

    # Try to upgrade and downgrade
    ext.alembic.stamp()
    ext.alembic.downgrade(target='96e796392533')
    ext.alembic.upgrade()
    assert not ext.alembic.compare_metadata()

    drop_alembic_version_table()
コード例 #6
0
ファイル: conftest.py プロジェクト: harunurhan/inspire-next
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
コード例 #7
0
def test_alembic(app, database):
    """Test alembic recipes."""
    db = database
    ext = app.extensions['invenio-db']

    if db.engine.name == 'sqlite':
        raise pytest.skip('Upgrades are not supported on SQLite.')

    # Check that this package's SQLAlchemy models have been properly registered
    tables = [x.name for x in db.get_tables_for_bind()]
    assert 'vocabularies_metadata' in tables
    assert 'vocabularies_types' in tables
    assert 'vocabularies_schemes' in tables

    # Specific vocabularies models
    assert 'subject_metadata' in tables
    assert 'affiliation_metadata' in tables

    # Check that Alembic agrees that there's no further tables to create.
    assert_alembic(ext.alembic, ['mock_metadata'])

    # Drop everything and recreate tables all with Alembic
    db.drop_all()
    drop_alembic_version_table()
    ext.alembic.upgrade()
    assert_alembic(ext.alembic, ['mock_metadata'])

    # Try to upgrade and downgrade
    ext.alembic.stamp()
    ext.alembic.downgrade(target='96e796392533')
    ext.alembic.upgrade()
    assert_alembic(ext.alembic, ['mock_metadata'])

    # Cleanup
    drop_alembic_version_table()
コード例 #8
0
ファイル: conftest.py プロジェクト: reve99/inspire-next
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
コード例 #9
0
def db(app):
    """Get setup database."""
    if not database_exists(str(db_.engine.url)):
        create_database(str(db_.engine.url))
    db_.create_all()
    yield db_
    db_.session.remove()
    db_.drop_all()
    drop_alembic_version_table()
コード例 #10
0
ファイル: conftest.py プロジェクト: inspirehep/inspire-next
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
コード例 #11
0
def init_db():
    LOGGER.info('Recreating the DB')
    db.session.close()
    db.drop_all()
    drop_alembic_version_table()

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

    db.session.commit()
    LOGGER.info('Recreating the DB: done')
    return jsonify("Db recreated")
コード例 #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 init_db():
    LOGGER.info('Recreating the DB')
    db.session.close()
    db.drop_all()
    drop_alembic_version_table()

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

    db.session.commit()
    LOGGER.info('Recreating the DB: done')
    return jsonify("Db recreated")
コード例 #14
0
def test_db_create_alembic_upgrade(app, db):
    """Test that 'db create/drop' and 'alembic create' are compatible.

    It also checks that "alembic_version" table is processed properly
    as it is normally created by alembic and not by sqlalchemy.
    """
    app.config['DB_VERSIONING'] = True
    ext = InvenioDB(app,
                    entry_point_group=None,
                    db=db,
                    versioning_manager=VersioningManager())
    with app.app_context():
        try:
            if db.engine.name == 'sqlite':
                raise pytest.skip('Upgrades are not supported on SQLite.')
            db.drop_all()
            runner = CliRunner()
            script_info = ScriptInfo(create_app=lambda info: app)
            # Check that 'db create' creates the same schema as
            # 'alembic upgrade'.
            result = runner.invoke(db_cmd, ['create', '-v'], obj=script_info)
            assert result.exit_code == 0
            assert db.engine.has_table('transaction')
            assert ext.alembic.migration_context._has_version_table()
            # Note that compare_metadata does not detect additional sequences
            # and constraints.
            assert not ext.alembic.compare_metadata()
            ext.alembic.upgrade()
            assert db.engine.has_table('transaction')

            ext.alembic.downgrade(target='96e796392533')
            assert db.engine.table_names() == ['alembic_version']

            # Check that 'db drop' removes all tables, including
            # 'alembic_version'.
            ext.alembic.upgrade()
            result = runner.invoke(db_cmd, ['drop', '-v', '--yes-i-know'],
                                   obj=script_info)
            assert result.exit_code == 0
            assert len(db.engine.table_names()) == 0

            ext.alembic.upgrade()
            db.drop_all()
            drop_alembic_version_table()
            assert len(db.engine.table_names()) == 0

        finally:
            drop_database(str(db.engine.url))
            remove_versioning(manager=ext.versioning_manager)
            create_database(str(db.engine.url))
コード例 #15
0
ファイル: conftest.py プロジェクト: theleestarr/inspire-next
def clear_environment(app):
    with app.app_context():
        db.session.close()
        db.drop_all()
        drop_alembic_version_table()

        alembic = Alembic(app=app)
        alembic.upgrade()
        list(current_search.delete(ignore=[404]))
        list(current_search.create(ignore=[400]))
        current_search.flush_and_refresh('records-hep')

        init_all_storage_paths()
        init_users_and_permissions()
コード例 #16
0
ファイル: conftest.py プロジェクト: turtle321/inspire-next
def clear_environment(app):
    with app.app_context():
        db.session.close()
        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]))
        es.indices.refresh('records-hep')

        init_all_storage_paths()
        init_users_and_permissions()
コード例 #17
0
ファイル: conftest.py プロジェクト: inspirehep/inspire-next
def clear_environment(app):
    with app.app_context():
        db.session.close()
        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]))
        es.indices.refresh('records-hep')

        init_all_storage_paths()
        init_users_and_permissions()
コード例 #18
0
ファイル: test_db.py プロジェクト: inveniosoftware/invenio-db
def test_db_create_alembic_upgrade(app, db):
    """Test that 'db create/drop' and 'alembic create' are compatible.

    It also checks that "alembic_version" table is processed properly
    as it is normally created by alembic and not by sqlalchemy.
    """
    app.config["DB_VERSIONING"] = True
    ext = InvenioDB(
        app, entry_point_group=None, db=db, versioning_manager=VersioningManager()
    )
    with app.app_context():
        try:
            if db.engine.name == "sqlite":
                raise pytest.skip("Upgrades are not supported on SQLite.")
            db.drop_all()
            runner = app.test_cli_runner()
            # Check that 'db create' creates the same schema as
            # 'alembic upgrade'.
            result = runner.invoke(db_cmd, ["create", "-v"])
            assert result.exit_code == 0
            assert has_table(db.engine, "transaction")
            assert ext.alembic.migration_context._has_version_table()
            # Note that compare_metadata does not detect additional sequences
            # and constraints.
            assert not ext.alembic.compare_metadata()
            ext.alembic.upgrade()
            assert has_table(db.engine, "transaction")

            ext.alembic.downgrade(target="96e796392533")
            assert inspect(db.engine).get_table_names() == ["alembic_version"]

            # Check that 'db drop' removes all tables, including
            # 'alembic_version'.
            ext.alembic.upgrade()
            result = runner.invoke(db_cmd, ["drop", "-v", "--yes-i-know"])
            assert result.exit_code == 0
            assert len(inspect(db.engine).get_table_names()) == 0

            ext.alembic.upgrade()
            db.drop_all()
            drop_alembic_version_table()
            assert len(inspect(db.engine).get_table_names()) == 0

        finally:
            drop_database(str(db.engine.url))
            remove_versioning(manager=ext.versioning_manager)
            create_database(str(db.engine.url))
コード例 #19
0
def test_alembic(app):
    """Test alembic recipes."""
    ext = app.extensions['invenio-db']

    with app.app_context():
        if db.engine.name == 'sqlite':
            raise pytest.skip('Upgrades are not supported on SQLite.')

        assert not ext.alembic.compare_metadata()
        db.drop_all()
        drop_alembic_version_table()
        ext.alembic.upgrade()

        assert not ext.alembic.compare_metadata()
        ext.alembic.downgrade(target='96e796392533')
        ext.alembic.upgrade()

        assert not ext.alembic.compare_metadata()
コード例 #20
0
def test_alembic(app, db):
    """Test alembic recipes."""
    ext = app.extensions['invenio-db']

    if db.engine.name == 'sqlite':
        raise pytest.skip('Upgrades are not supported on SQLite.')

    assert not ext.alembic.compare_metadata()
    db.drop_all()
    drop_alembic_version_table()
    ext.alembic.upgrade()

    assert not ext.alembic.compare_metadata()
    ext.alembic.stamp()
    ext.alembic.downgrade(target='96e796392533')
    ext.alembic.upgrade()

    assert not ext.alembic.compare_metadata()
    drop_alembic_version_table()
コード例 #21
0
def test_alembic_revision_cb5153afd839(alembic_app):
    ext = alembic_app.extensions['invenio-db']

    if db.engine.name == 'sqlite':
        raise pytest.skip('Upgrades are not supported on SQLite.')

    db.drop_all()
    drop_alembic_version_table()

    inspector = inspect(db.engine)
    assert 'workflows_record_sources' not in inspector.get_table_names()

    ext.alembic.upgrade(target='cb5153afd839')
    inspector = inspect(db.engine)
    assert 'workflows_record_sources' in inspector.get_table_names()

    ext.alembic.downgrade(target='fddb3cfe7a9c')
    inspector = inspect(db.engine)
    assert 'workflows_record_sources' not in inspector.get_table_names()

    drop_alembic_version_table()
コード例 #22
0
ファイル: conftest.py プロジェクト: drjova/inspire-next
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
コード例 #23
0
ファイル: conftest.py プロジェクト: inspirehep/inspire-next
def drop_all(app):
    db.drop_all()
    drop_alembic_version_table()
    _es = app.extensions['invenio-search']
    list(_es.delete(ignore=[404]))
コード例 #24
0
def drop_all(app):
    db.drop_all()
    drop_alembic_version_table()
    list(current_search.delete(ignore=[404]))
コード例 #25
0
def drop_all(app):
    db.drop_all()
    drop_alembic_version_table()
    _es = app.extensions['invenio-search']
    list(_es.delete(ignore=[404]))