Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes es6. #138

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down
7 changes: 1 addition & 6 deletions invenio_indexer/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand Down
7 changes: 2 additions & 5 deletions invenio_indexer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
18 changes: 5 additions & 13 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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()
Expand All @@ -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)


Expand All @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'],
Expand Down
15 changes: 6 additions & 9 deletions tests/test_invenio_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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={},
)

Expand All @@ -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',
Expand All @@ -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',
)
5 changes: 2 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'
)


Expand Down Expand Up @@ -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