def test_percolator(app, request): """Test percolator.""" def teardown(): with app.app_context(): current_collections.unregister_signals() list(current_search.delete()) request.addfinalizer(teardown) with app.test_request_context(): app.config.update( COLLECTIONS_USE_PERCOLATOR=True, SEARCH_ELASTIC_KEYWORD_MAPPING={None: ['_all']}, ) search = InvenioSearch(app) search.register_mappings('records', 'data') InvenioIndexer(app) current_collections.unregister_signals() current_collections.register_signals() list(current_search.create()) _try_populate_collections()
def test_view(app): """Test view.""" with app.app_context(): current_collections.unregister_signals() view_url = url_for('invenio_collections.collection') view_test_url = url_for('invenio_collections.collection', name='Test') with app.test_client() as client: res = client.get(view_url) assert res.status_code == 404 with app.app_context(): with db.session.begin_nested(): collection = Collection(name='Test') db.session.add(collection) db.session.commit() assert 1 == collection.id assert 'Collection <id: 1, name: Test, dbquery: None>' == repr( collection) with app.test_client() as client: res = client.get(view_url) assert res.status_code == 200 res = client.get(view_test_url) assert res.status_code == 200 with app.app_context(): current_collections.unregister_signals()
def test_view(app): """Test view.""" with app.app_context(): current_collections.unregister_signals() view_url = url_for('invenio_collections.collection') view_test_url = url_for('invenio_collections.collection', name='Test') with app.test_client() as client: res = client.get(view_url) assert res.status_code == 404 with app.app_context(): with db.session.begin_nested(): collection = Collection(name='Test') db.session.add(collection) db.session.commit() assert 1 == collection.id assert 'Collection <id: 1, name: Test, dbquery: None>' == repr( collection) with app.test_client() as client: res = client.get(view_url) assert res.status_code == 200 res = client.get(view_test_url) assert res.status_code == 200 with app.app_context(): current_collections.unregister_signals()
def migrate_chunk(chunk): models_committed.disconnect(receive_after_model_commit) current_collections.unregister_signals() index_queue = [] try: for raw_record in chunk: with db.session.begin_nested(): record = migrate_and_insert_record(raw_record) if record: index_queue.append(create_index_op(record)) db.session.commit() finally: db.session.close() req_timeout = current_app.config['INDEXER_BULK_REQUEST_TIMEOUT'] es_bulk( es, index_queue, stats_only=True, request_timeout=req_timeout, ) models_committed.connect(receive_after_model_commit) current_collections.register_signals()
def test_percolator(app, request): """Test percolator.""" def teardown(): with app.app_context(): current_collections.unregister_signals() list(current_search.delete()) request.addfinalizer(teardown) with app.test_request_context(): app.config.update( COLLECTIONS_USE_PERCOLATOR=True, SEARCH_ELASTIC_KEYWORD_MAPPING={None: ['_all']}, ) search = InvenioSearch(app) search.register_mappings('records', 'data') InvenioIndexer(app) current_collections.unregister_signals() current_collections.register_signals() list(current_search.create()) _try_populate_collections()
def test_without_percolator(app, request): """Test percolator.""" with app.test_request_context(): app.config.update(COLLECTIONS_USE_PERCOLATOR=False, ) current_collections.unregister_signals() current_collections.register_signals() _try_populate_collections()
def test_without_percolator(app, request): """Test percolator.""" with app.test_request_context(): app.config.update( COLLECTIONS_USE_PERCOLATOR=False, ) current_collections.unregister_signals() current_collections.register_signals() _try_populate_collections()
def test_init(): """Test extension initialization.""" app = Flask('testapp') ext = InvenioCollections(app) assert 'invenio-collections' in app.extensions ext.unregister_signals() app = Flask('testapp') ext = InvenioCollections() assert 'invenio-collections' not in app.extensions ext.init_app(app) assert 'invenio-collections' in app.extensions with app.app_context(): current_collections.unregister_signals()
def test_init(): """Test extension initialization.""" app = Flask('testapp') ext = InvenioCollections(app) assert 'invenio-collections' in app.extensions ext.unregister_signals() app = Flask('testapp') ext = InvenioCollections() assert 'invenio-collections' not in app.extensions ext.init_app(app) assert 'invenio-collections' in app.extensions with app.app_context(): current_collections.unregister_signals()
def teardown(): with app.app_context(): current_collections.unregister_signals() list(current_search.delete())
def teardown(): with app.app_context(): db.drop_all() current_collections.unregister_signals()
def teardown(): with app.app_context(): current_collections.unregister_signals() list(current_search.delete())