def app(): """Flask application fixture.""" instance_path = tempfile.mkdtemp() app = Flask('testapp', instance_path=instance_path) app.config.update( CELERY_ALWAYS_EAGER=True, CELERY_TASK_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND='memory', CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_TASK_EAGER_PROPAGATES=True, CELERY_RESULT_BACKEND='cache', JSONSCHEMAS_HOST='inveniosoftware.org', TESTING=True, SECRET_KEY='CHANGE_ME', SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'), SQLALCHEMY_TRACK_MODIFICATIONS=True, SERVER_NAME='app', OAISERVER_ID_PREFIX='oai:inveniosoftware.org:recid/', OAISERVER_QUERY_PARSER_FIELDS=["title_statement"], OAISERVER_RECORD_INDEX='_all', OAISERVER_REGISTER_SET_SIGNALS=True, ) if not hasattr(app, 'cli'): from flask_cli import FlaskCLI FlaskCLI(app) InvenioDB(app) FlaskCeleryExt(app) InvenioJSONSchemas(app) InvenioRecords(app) InvenioPIDStore(app) InvenioMARC21(app) client = Elasticsearch(hosts=[os.environ.get('ES_HOST', 'localhost')]) search = InvenioSearch(app, client=client) search.register_mappings('records', 'data') InvenioIndexer(app) InvenioOAIServer(app) app.register_blueprint(blueprint) with app.app_context(): if str(db.engine.url) != 'sqlite://' and \ not database_exists(str(db.engine.url)): create_database(str(db.engine.url)) db.create_all() list(search.delete(ignore=[404])) list(search.create()) search.flush_and_refresh('_all') with app.app_context(): yield app with app.app_context(): db.session.close() if str(db.engine.url) != 'sqlite://': drop_database(str(db.engine.url)) list(search.delete(ignore=[404])) search.client.indices.delete("*-percolators") shutil.rmtree(instance_path)
def app(): """Flask application fixture.""" instance_path = tempfile.mkdtemp() app = Flask('testapp', instance_path=instance_path) app.config.update( CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND='memory', CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND='cache', JSONSCHEMAS_HOST='inveniosoftware.org', TESTING=True, SECRET_KEY='CHANGE_ME', SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite://'), SQLALCHEMY_TRACK_MODIFICATIONS=True, SERVER_NAME='app', OAISERVER_RECORD_INDEX='_all', # Disable set signals because the celery tasks cannot be run # synchronously OAISERVER_REGISTER_SET_SIGNALS=False, SEARCH_ELASTIC_KEYWORD_MAPPING={None: ['_all']}, ) if not hasattr(app, 'cli'): from flask_cli import FlaskCLI FlaskCLI(app) InvenioDB(app) FlaskCeleryExt(app) InvenioJSONSchemas(app) InvenioRecords(app) InvenioPIDStore(app) InvenioMARC21(app) client = Elasticsearch(hosts=[os.environ.get('ES_HOST', 'localhost')]) search = InvenioSearch(app, client=client) search.register_mappings('records', 'data') InvenioIndexer(app) InvenioOAIServer(app) app.register_blueprint(blueprint) with app.app_context(): if str(db.engine.url) != 'sqlite://' and \ not database_exists(str(db.engine.url)): create_database(str(db.engine.url)) db.create_all() list(search.create(ignore=[400])) sleep(5) with app.app_context(): yield app with app.app_context(): db.session.close() if str(db.engine.url) != 'sqlite://': drop_database(str(db.engine.url)) list(search.delete(ignore=[404])) shutil.rmtree(instance_path)
def test_bibliographic_data(es_app): """Test indexation using bibliographic data.""" search = InvenioSearch(es_app) search.create() indexer = RecordIndexer() with es_app.test_request_context(): data_filename = pkg_resources.resource_filename( 'invenio_records', 'data/marc21/bibliographic.xml') records_data = load(data_filename) records = [] for item in records_data: record = Record.create(item) record['$schema'] = "mappings/marc21_holdings.json" es_record = indexer.index(record) records.append(es_record) for record in records: search.client.get(index=record['_index'], doc_type=record['_type'], id=record['_id']) search.delete()
def test_bibliographic_data(es_app): """Test indexation using bibliographic data.""" search = InvenioSearch(es_app) search.create() indexer = RecordIndexer() with es_app.test_request_context(): data_filename = pkg_resources.resource_filename( 'invenio_records', 'data/marc21/bibliographic.xml') records_data = load(data_filename) records = [] for item in records_data: record = Record.create(item) record['$schema'] = "mappings/marc21_holdings.json" es_record = indexer.index(record) records.append(es_record) for record in records: search.client.get(index=record['_index'], doc_type=record['_type'], id=record['_id']) search.delete()