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() app.config.update( dict(TESTING=True, TEST_RUNNER="celery.contrib.test_runner.CeleryTestSuiteRunner", CELERY_ALWAYS_EAGER=True, CELERY_RESULT_BACKEND="cache", CELERY_CACHE_BACKEND="memory", MAIL_SUPPRESS_SEND=True, CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'postgresql+psycopg2://hepdata:hepdata@localhost/hepdata_test' ))) 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) 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() load_default_data(app) def teardown(): with app.app_context(): db.drop_all() ctx.pop() request.addfinalizer(teardown) return app
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() app.config.update(dict( TESTING=True, TEST_RUNNER="celery.contrib.test_runner.CeleryTestSuiteRunner", CELERY_ALWAYS_EAGER=True, CELERY_RESULT_BACKEND="cache", CELERY_CACHE_BACKEND="memory", MAIL_SUPPRESS_SEND=True, CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'postgresql+psycopg2://localhost/hepdata_test') )) 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) 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() load_default_data(app) def teardown(): with app.app_context(): db.drop_all() ctx.pop() request.addfinalizer(teardown) return app
def create_basic_app(): app = create_app() 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", MAIL_SUPPRESS_SEND=True, CELERY_TASK_EAGER_PROPAGATES=True, ELASTICSEARCH_INDEX="hepdata_test", SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'postgresql+psycopg2://hepdata:hepdata@localhost/hepdata_test' ))) return app
def create_basic_app(): app = create_app() test_db_host = app.config.get('TEST_DB_HOST', 'localhost') 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", MAIL_SUPPRESS_SEND=True, 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') )) return app
def app(request): """Flask app fixture.""" app = create_app() app.config.update( dict(TESTING=True, TEST_RUNNER="celery.contrib.test_runner.CeleryTestSuiteRunner", CELERY_ALWAYS_EAGER=True, CELERY_RESULT_BACKEND="cache", CELERY_CACHE_BACKEND="memory", MAIL_SUPPRESS_SEND=True, CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'postgresql+psycopg2://hepdata:hepdata@localhost/hepdata_test' ))) with app.app_context(): db.drop_all() db.create_all() reindex_all(recreate=True) ctx = app.test_request_context() ctx.push() user_count = User.query.filter_by(email='*****@*****.**').count() if user_count == 0: user = User(email=TEST_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() yield app ctx.pop()
def app(request): """Flask app fixture.""" app = create_app() app.config.update(dict( TESTING=True, TEST_RUNNER="celery.contrib.test_runner.CeleryTestSuiteRunner", CELERY_ALWAYS_EAGER=True, CELERY_RESULT_BACKEND="cache", CELERY_CACHE_BACKEND="memory", MAIL_SUPPRESS_SEND=True, CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'postgresql+psycopg2://localhost/hepdata_test') )) with app.app_context(): db.drop_all() db.create_all() reindex_all(recreate=True) ctx = app.test_request_context() ctx.push() user_count = User.query.filter_by(email='*****@*****.**').count() if user_count == 0: user = User(email=TEST_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() ctx.pop() return app
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