From 304be5221e731227af4852d7d3125273bd5b7b5a Mon Sep 17 00:00:00 2001 From: "Zeller, Christina" Date: Mon, 16 May 2022 18:01:39 +0200 Subject: [PATCH] Removes es6. --- .github/workflows/tests.yml | 11 +---------- invenio_indexer/api.py | 7 +------ invenio_indexer/utils.py | 7 ++----- tests/test_api.py | 18 +++++------------- tests/test_invenio_indexer.py | 15 ++++++--------- tests/test_utils.py | 5 ++--- 6 files changed, 17 insertions(+), 46 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index acea1aa..7157f5c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,7 +32,7 @@ jobs: requirements-level: [min, pypi] cache-service: [redis] mq-service: [rabbitmq, redis] - search-service: [elasticsearch6, elasticsearch7] + search-service: [elasticsearch7] exclude: - python-version: 3.7 requirements-level: pypi @@ -46,16 +46,7 @@ jobs: - python-version: 3.7 search-service: elasticsearch7 - - python-version: 3.8 - search-service: elasticsearch6 - - - python-version: 3.9 - search-service: elasticsearch6 - include: - - search-service: elasticsearch6 - SEARCH_EXTRAS: "elasticsearch6" - - search-service: elasticsearch7 SEARCH_EXTRAS: "elasticsearch7" diff --git a/invenio_indexer/api.py b/invenio_indexer/api.py index 97966ad..5d0503a 100644 --- a/invenio_indexer/api.py +++ b/invenio_indexer/api.py @@ -13,9 +13,7 @@ import pytz from celery import current_app as current_celery_app -from elasticsearch import VERSION as ES_VERSION from elasticsearch.helpers import bulk -from elasticsearch.helpers import expand_action as default_expand_action from elasticsearch_dsl import Index from flask import current_app from invenio_records.api import Record @@ -250,10 +248,7 @@ def process_bulk_queue(self, es_bulk_kwargs=None): self._actionsiter(consumer.iterqueue()), stats_only=True, request_timeout=req_timeout, - expand_action_callback=( - _es7_expand_action if ES_VERSION[0] >= 7 - else default_expand_action - ), + expand_action_callback=_es7_expand_action, **es_bulk_kwargs ) diff --git a/invenio_indexer/utils.py b/invenio_indexer/utils.py index eaa3c23..4f69a4a 100644 --- a/invenio_indexer/utils.py +++ b/invenio_indexer/utils.py @@ -11,7 +11,6 @@ import os from functools import wraps -from elasticsearch import VERSION as ES_VERSION from flask import current_app from invenio_search import current_search from invenio_search.utils import build_index_from_parts @@ -27,8 +26,7 @@ def schema_to_index(schema, index_names=None): parts = schema.split('/') doc_type, ext = os.path.splitext(parts[-1]) parts[-1] = doc_type - if ES_VERSION[0] >= 7: - doc_type = '_doc' + doc_type = '_doc' if ext not in {'.json', }: return (None, None) @@ -67,8 +65,7 @@ def default_record_to_index(record): current_app.config['INDEXER_DEFAULT_DOC_TYPE'], ) - if ES_VERSION[0] >= 7: - doc_type = '_doc' + doc_type = '_doc' return index, doc_type diff --git a/tests/test_api.py b/tests/test_api.py index e5a291e..1a1b53c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -14,7 +14,6 @@ import pytz from celery.messaging import establish_connection -from elasticsearch import VERSION as ES_VERSION from elasticsearch_dsl import Index from invenio_db import db from invenio_records.api import Record @@ -25,8 +24,6 @@ from invenio_indexer.api import BulkRecordIndexer, RecordIndexer from invenio_indexer.signals import before_record_index -lt_es7 = ES_VERSION[0] < 7 - def test_indexer_bulk_index(app, queue): """Test delay indexing.""" @@ -79,7 +76,7 @@ def test_delete_action(app): dict(id=str(record.id), op='delete', index=None, doc_type=None)) assert action['_op_type'] == 'delete' assert action['_index'] == 'records-authorities-authority-v1.0.0' - assert action['_type'] == 'authority-v1.0.0' if lt_es7 else '_doc' + assert action['_type'] == '_doc' assert action['_id'] == str(record.id) record.delete() @@ -90,8 +87,7 @@ def test_delete_action(app): # Deleted record doesn't have '$schema', so index and doc type cannot # be determined, resulting to the defaults from config assert action['_index'] == app.config['INDEXER_DEFAULT_INDEX'] - assert action['_type'] == \ - app.config['INDEXER_DEFAULT_DOC_TYPE'] if lt_es7 else '_doc' + assert action['_type'] == '_doc' assert action['_id'] == str(record.id) @@ -113,11 +109,7 @@ def receiver(sender, json=None, record=None, arguments=None, **kwargs): assert action['_op_type'] == 'index' assert action['_index'] == app.config['INDEXER_DEFAULT_INDEX'] assert action['_id'] == str(record.id) - if lt_es7: - assert action['_type'] == \ - app.config['INDEXER_DEFAULT_DOC_TYPE'] - else: - assert action['_type'] == '_doc' + assert action['_type'] == '_doc' assert action['_version'] == record.revision_id assert action['_version_type'] == 'external_gte' assert action['pipeline'] == 'foobar' @@ -185,7 +177,7 @@ def test_index(app): RecordIndexer(search_client=client_mock, version_type='force').index( record, arguments={'pipeline': 'foobar'}) - doc_type = app.config['INDEXER_DEFAULT_DOC_TYPE'] if lt_es7 else '_doc' + doc_type = '_doc' client_mock.index.assert_called_with( id=str(recid), version=0, @@ -281,7 +273,7 @@ def test_delete(app): client_mock = MagicMock() RecordIndexer(search_client=client_mock).delete(record) - doc_type = app.config['INDEXER_DEFAULT_DOC_TYPE'] if lt_es7 else '_doc' + doc_type = '_doc' client_mock.delete.assert_called_with( id=str(recid), index=app.config['INDEXER_DEFAULT_INDEX'], diff --git a/tests/test_invenio_indexer.py b/tests/test_invenio_indexer.py index bd09bd9..b3e2f10 100644 --- a/tests/test_invenio_indexer.py +++ b/tests/test_invenio_indexer.py @@ -12,7 +12,6 @@ from unittest.mock import MagicMock, patch import pytz -from elasticsearch import VERSION as ES_VERSION from flask import Flask from invenio_db import db from invenio_records import Record @@ -24,8 +23,6 @@ _global_magic_hook = MagicMock() """Iternal importable magic hook instance.""" -lt_es7 = ES_VERSION[0] < 7 - def test_version(): """Test version import.""" @@ -64,7 +61,7 @@ def test_hook_initialization(base_app): RecordIndexer(search_client=client_mock, version_type='force').index( record) args = (app, ) - doc_type = app.config['INDEXER_DEFAULT_DOC_TYPE'] if lt_es7 else '_doc' + doc_type = '_doc' kwargs = dict( index=app.config['INDEXER_DEFAULT_INDEX'], doc_type=doc_type, @@ -122,7 +119,7 @@ def test_index_prefixing(base_app): version=0, version_type='external_gte', index='test-' + default_index, - doc_type=default_doc_type if lt_es7 else '_doc', + doc_type='_doc', body={ 'title': 'Test', '_created': pytz.utc.localize(record.created).isoformat(), @@ -138,7 +135,7 @@ def test_index_prefixing(base_app): }, record=record, index=default_index, # non-prefixed index passed to receiver - doc_type=default_doc_type if lt_es7 else '_doc', + doc_type='_doc', arguments={}, ) @@ -148,7 +145,7 @@ def test_index_prefixing(base_app): version=0, version_type='external_gte', index='test-records-authorities-authority-v1.0.0', - doc_type='authority-v1.0.0' if lt_es7 else '_doc', + doc_type='_doc', body={ '$schema': '/records/authorities/authority-v1.0.0.json', 'title': 'Test with schema', @@ -166,14 +163,14 @@ def test_index_prefixing(base_app): }, record=record2, index='records-authorities-authority-v1.0.0', # no prefix - doc_type='authority-v1.0.0' if lt_es7 else '_doc', + doc_type='_doc', arguments={}, ) RecordIndexer(search_client=client_mock).delete(record3) client_mock.delete.assert_called_with( id=str(record3.id), index='test-' + default_index, - doc_type=default_doc_type if lt_es7 else '_doc', + doc_type='_doc', version=record3.revision_id, version_type='external_gte', ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 8b78e43..dc7a4db 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -11,7 +11,6 @@ from unittest.mock import patch import pytest -from elasticsearch import VERSION as ES_VERSION from invenio_indexer.utils import schema_to_index @@ -21,7 +20,7 @@ def test_schema_to_index_with_names(app): result = schema_to_index('default.json', index_names=['default']) assert result == ( 'default', - '_doc' if ES_VERSION[0] >= 7 else 'default' + '_doc' ) @@ -58,6 +57,6 @@ def test_schema_to_index_with_names(app): def test_schema_to_index(schema, expected, index_names, app): """Test the expected value of schema to index.""" result = schema_to_index(schema, index_names=index_names) - if ES_VERSION[0] >= 7 and expected[0]: + if expected[0]: expected = (expected[0], '_doc') assert result == expected