Beispiel #1
0
def test_identifiers(app):
    return get_identifiers()
Beispiel #2
0
def app(request):
    """Flask application fixture for E2E/integration/selenium tests.
    Overrides the `app` fixture found in `../conftest.py`. Tests/files in this
    folder and subfolders will see this variant of the `app` fixture.
    """
    app = create_app()
    test_db_host = app.config.get('TEST_DB_HOST', 'localhost')
    # Note that in GitHub Actions we add "TESTING=True" and
    # "APP_ENABLE_SECURE_HEADERS=False" to config_local.py as well,
    # to ensure that they're set before the app is initialised,
    # as changing them later doesn't have the desired effect.
    app.config.update(
        dict(TESTING=True,
             TEST_RUNNER="celery.contrib.test_runner.CeleryTestSuiteRunner",
             CELERY_TASK_ALWAYS_EAGER=True,
             CELERY_RESULT_BACKEND="cache",
             CELERY_CACHE_BACKEND="memory",
             CELERY_TASK_EAGER_PROPAGATES=True,
             ELASTICSEARCH_INDEX="hepdata-main-test",
             SUBMISSION_INDEX='hepdata-submission-test',
             AUTHOR_INDEX='hepdata-authors-test',
             SQLALCHEMY_DATABASE_URI=os.environ.get(
                 'SQLALCHEMY_DATABASE_URI',
                 'postgresql+psycopg2://hepdata:hepdata@' + test_db_host +
                 '/hepdata_test'),
             APP_ENABLE_SECURE_HEADERS=False))

    with app.app_context():
        if not database_exists(str(db.engine.url)):
            create_database(str(db.engine.url))
        db.create_all()

    with app.app_context():
        db.drop_all()
        db.create_all()
        reindex_all(recreate=True, synchronous=True)

        ctx = app.test_request_context()
        ctx.push()

        user_count = User.query.filter_by(email='*****@*****.**').count()
        if user_count == 0:
            user = User(email='*****@*****.**',
                        password='******',
                        active=True)
            admin_role = Role(name='admin')
            coordinator_role = Role(name='coordinator')

            user.roles.append(admin_role)
            user.roles.append(coordinator_role)

            db.session.add(admin_role)
            db.session.add(coordinator_role)
            db.session.add(user)
            db.session.commit()

        import_default_data(app, get_identifiers())

    def teardown():
        with app.app_context():
            db.engine.dispose()
            db.drop_all()
            ctx.pop()

    request.addfinalizer(teardown)

    return app
Beispiel #3
0
def load_default_data(app):
    with app.app_context():
        to_load = [x["hepdata_id"] for x in get_identifiers()]
        load_files(to_load, synchronous=True)