Skip to content
Snippets Groups Projects
Commit d38ff32d authored by Valentin Rigal's avatar Valentin Rigal
Browse files

Succint ES test

parent 2cf28e16
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ from django.contrib.auth.models import AnonymousUser
from django.urls import reverse
from rest_framework import status
from elasticsearch_dsl.connections import connections
from arkindex_common.enums import EntityType
from arkindex_common.enums import EntityType, MetaType
from arkindex.project.tests import FixtureAPITestCase
from arkindex.project.elastic import ESTranscription
from arkindex.documents.models import Transcription, Element, Corpus, DataSource, MLToolType
......@@ -96,7 +96,7 @@ class TestSearchAPI(FixtureAPITestCase):
"_type": "entity",
}
def test_element_search(self):
def test_element_transcription_search(self):
elt = Element.objects.get(name="Volume 1, page 1r")
ts = Transcription.objects.filter(text="PARIS", zone__image__path='img1')
......@@ -135,7 +135,7 @@ class TestSearchAPI(FixtureAPITestCase):
map(str, Corpus.objects.readable(AnonymousUser()).values_list('id', flat=True)),
)
nested = kwargs['body']['query']['bool']['must'][0]['nested']
nested = kwargs['body']['query']['bool']['should'][0]['nested']
self.assertEqual(nested['score_mode'], 'sum')
self.assertEqual(nested['path'], 'transcriptions')
self.assertIn('inner_hits', nested)
......@@ -164,6 +164,29 @@ class TestSearchAPI(FixtureAPITestCase):
}},
])
def test_element_reference_search(self):
elt = Element.objects.get(name="Volume 1, page 1r")
ref = elt.metadatas.create(
type=MetaType.Reference,
name='reference',
value='reference1337'
)
self.es_mock.count.return_value = {'count': 1}
self.es_mock.search.return_value = self.build_es_response(
[self.make_element_hit(elt, []), ],
)
response = self.client.get(reverse('api:element-search'), {'q': ref.value[2:]})
self.assertEqual(response.status_code, status.HTTP_200_OK)
args, kwargs = self.es_mock.search.call_args
ref_query = kwargs['body']['query']['bool']['should'][1]
self.assertDictEqual(ref_query, {
"wildcard": {
"references": "*{}*".format(ref.value[2:])
}
})
def test_iiif_transcription_search(self):
# Filter to only get transcriptions from volume 1
unfiltered = Transcription.objects.filter(text="PARIS")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment