Skip to content

Commit

Permalink
global: compatibility fixes for suggesters
Browse files Browse the repository at this point in the history
  • Loading branch information
Glignos authored and slint committed Aug 12, 2019
1 parent 6d59e56 commit 50378d8
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 19 deletions.
4 changes: 2 additions & 2 deletions invenio_openaire/mappings/v5/funders/funder-v1.0.0.json
Expand Up @@ -46,8 +46,8 @@
},
"suggest": {
"type": "completion",
"analyzer" : "snowball",
"search_analyzer" : "snowball"
"analyzer" : "standard",
"search_analyzer" : "standard"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions invenio_openaire/mappings/v5/grants/grant-v1.0.0.json
Expand Up @@ -90,8 +90,8 @@
},
"suggest": {
"type": "completion",
"analyzer": "snowball",
"search_analyzer": "snowball",
"analyzer": "standard",
"search_analyzer": "standard",
"contexts": [
{
"name": "funder",
Expand Down
4 changes: 2 additions & 2 deletions invenio_openaire/mappings/v6/funders/funder-v1.0.0.json
Expand Up @@ -46,8 +46,8 @@
},
"suggest": {
"type": "completion",
"analyzer": "snowball",
"search_analyzer": "snowball"
"analyzer": "standard",
"search_analyzer": "standard"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions invenio_openaire/mappings/v6/grants/grant-v1.0.0.json
Expand Up @@ -90,8 +90,8 @@
},
"suggest": {
"type": "completion",
"analyzer": "snowball",
"search_analyzer": "snowball",
"analyzer": "standard",
"search_analyzer": "standard",
"contexts": [
{
"name": "funder",
Expand Down
4 changes: 2 additions & 2 deletions invenio_openaire/mappings/v7/funders/funder-v1.0.0.json
Expand Up @@ -45,8 +45,8 @@
},
"suggest": {
"type": "completion",
"analyzer" : "snowball",
"search_analyzer" : "snowball"
"analyzer" : "standard",
"search_analyzer" : "standard"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions invenio_openaire/mappings/v7/grants/grant-v1.0.0.json
Expand Up @@ -89,8 +89,8 @@
},
"suggest": {
"type": "completion",
"analyzer" : "snowball",
"search_analyzer" : "snowball",
"analyzer" : "standard",
"search_analyzer" : "standard",
"contexts": [{
"name" : "funder",
"type": "category",
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Expand Up @@ -48,6 +48,7 @@
from invenio_records.models import RecordMetadata
from invenio_records_rest.utils import PIDConverter, PIDPathConverter
from invenio_search import InvenioSearch, current_search
from invenio_search.errors import IndexAlreadyExistsError
from sqlalchemy_utils.functions import create_database, database_exists

from invenio_openaire import InvenioOpenAIRE
Expand Down Expand Up @@ -96,7 +97,6 @@ def app(request):
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
JSONSCHEMAS_HOST='inveniosoftware.org',
OPENAIRE_OAI_LOCAL_SOURCE='invenio_openaire/data/oaire_local.sqlite',
SEARCH_AUTOINDEX=[],
TESTING=True,
)

Expand Down Expand Up @@ -142,7 +142,7 @@ def es(app):
"""Provide elasticsearch access."""
try:
list(current_search.create())
except RequestError:
except (IndexAlreadyExistsError, RequestError):
list(current_search.delete(ignore=[404]))
list(current_search.create(ignore=[400]))
yield current_search
Expand Down
30 changes: 25 additions & 5 deletions tests/test_rest.py
Expand Up @@ -26,12 +26,22 @@

from __future__ import absolute_import, print_function

import json

from invenio_records_rest import InvenioRecordsREST
from invenio_records_rest.views import create_blueprint

from invenio_openaire.config import OPENAIRE_REST_ENDPOINTS


def _get_json(response, code=None):
"""Decode JSON from response."""
data = response.get_data(as_text=True)
if code is not None:
assert response.status_code == code, data
return json.loads(data)


def test_records_rest(app, db, es, grants):
"""Test Records REST."""
app.config['RECORDS_REST_ENDPOINTS'] = OPENAIRE_REST_ENDPOINTS
Expand All @@ -51,15 +61,25 @@ def test_records_rest(app, db, es, grants):
print(res.get_data(as_text=True))
# Suggest
res = client.get("/funders/_suggest?text=Uni")
assert res.status_code == 200

# Item
data = _get_json(res, 200)
options = data['text'][0]['options']
assert len(options) == 2
assert [option['_source']['doi'] for option in options].sort() == [
'0.13039/501100000923', '10.13039/001'].sort()
res = client.get("/grants/10.13039/501100000923::LP0667725")
assert res.status_code == 200
# List
res = client.get("/grants/")
assert res.status_code == 200
# Suggest
funder = '10.13039/501100000923'
res = client.get(
"/grants/_suggest?text=open&funder=10.13039/501100000923")
assert res.status_code == 200
"/grants/_suggest?text=LP&funder={}".format(funder))
data = _get_json(res, 200)
options = data['text'][0]['options']
assert len(options) == 3
assert [(option['_source']['code'],
option['_source']['funder']['doi']) for option in options
].sort() == [
('LP0989479', funder), ('LP0667725', funder),
('LP0215942', funder)].sort()

0 comments on commit 50378d8

Please sign in to comment.