Skip to content
Snippets Groups Projects
Commit abdb4a52 authored by Valentin Rigal's avatar Valentin Rigal Committed by Erwan Rouchet
Browse files

Prevent transcriptions without a zone to be added to transcriptions ElasticSearch index

parent 9f576700
No related branches found
No related tags found
No related merge requests found
......@@ -81,13 +81,16 @@ class ReindexConsumer(SyncConsumer):
# Pick all elements in the corpus
elements_queryset = Element.objects.filter(corpus_id=corpus_id)
transcriptions_queryset = Transcription.objects.filter(element__in=elements_queryset)
transcriptions_queryset = Transcription.objects.filter(
element__in=elements_queryset,
zone__isnull=False
)
entities_queryset = Entity.objects.filter(
Q(metadatas__element__in=elements_queryset)
| Q(transcriptions__element__in=elements_queryset)
)
else:
transcriptions_queryset = Transcription.objects.all()
transcriptions_queryset = Transcription.objects.filter(zone__isnull=False)
elements_queryset = Element.objects.all()
entities_queryset = Entity.objects.all()
......
......@@ -71,7 +71,11 @@ class TestReindexConsumer(FixtureTestCase):
def _assert_all_transcriptions(self, call_args):
(queryset, ), kwargs = call_args
self.assertQuerysetEqual(queryset, Transcription.objects.all())
self.assertQuerysetEqual(
queryset,
# Only transcriptions with a zone may be added to transcriptions index
Transcription.objects.filter(zone__isnull=False)
)
self.assertDictEqual(kwargs, {'bulk_size': 400})
def _assert_all(self, mock):
......@@ -143,7 +147,10 @@ class TestReindexConsumer(FixtureTestCase):
self.assertDictEqual(kwargs, {'bulk_size': 400})
(queryset, ), kwargs = ts_call
self.assertQuerysetEqual(queryset, Transcription.objects.filter(element__corpus_id=self.corpus.id))
self.assertQuerysetEqual(
queryset,
Transcription.objects.filter(element__corpus_id=self.corpus.id, zone__isnull=False)
)
self.assertDictEqual(kwargs, {'bulk_size': 400})
def test_reindex_element(self, mock):
......@@ -172,5 +179,23 @@ class TestReindexConsumer(FixtureTestCase):
self.assertDictEqual(kwargs, {'bulk_size': 400})
(queryset, ), kwargs = ts_call
self.assertQuerysetEqual(queryset, Transcription.objects.filter(element__in=elements_list))
self.assertQuerysetEqual(
queryset,
Transcription.objects.filter(element__in=elements_list, zone__isnull=False)
)
self.assertDictEqual(kwargs, {'bulk_size': 400})
def test_reindex_transcriptions_without_zone(self, mock):
"""
Transcriptions with no zone may not be indexed in transcriptions index
"""
ReindexConsumer({}).reindex_start({
'transcriptions': True,
'entities': False,
'elements': False,
})
transcription = Transcription.objects.filter(zone__isnull=True).first()
self.assertNotEqual(transcription, None)
self.assertEqual(mock().run_index.call_count, 1)
(queryset, ), kwargs = mock().run_index.call_args
self.assertFalse(queryset.filter(id=transcription.id).exists())
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