From 48253f3f858eae39a240b5301a32cc8a572df672 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 2 Apr 2019 02:35:33 -0400 Subject: [PATCH] Update index test case to be order agnostic Use sets and remove explicit index node ordering to allow tests to work regardless of the node creation order. GitLab issue #559. Signed-off-by: Roberto Rosario --- .../document_indexing/tests/test_models.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mayan/apps/document_indexing/tests/test_models.py b/mayan/apps/document_indexing/tests/test_models.py index 29a4af73f7..6a508ab45b 100644 --- a/mayan/apps/document_indexing/tests/test_models.py +++ b/mayan/apps/document_indexing/tests/test_models.py @@ -92,15 +92,15 @@ class IndexTestCase(DocumentIndexingTestMixin, DocumentTestMixin, BaseTestCase): document = self.upload_document() self.assertEqual( - [instance.value for instance in IndexInstanceNode.objects.all().order_by('pk')], + list(IndexInstanceNode.objects.values_list('value', flat=True)), [ '', force_text(document.date_added.year), - force_text(document.date_added.month).zfill(2) + '{:02}'.format(document.date_added.month) ] ) self.assertTrue( - document in list(IndexInstanceNode.objects.order_by('pk').last().documents.all()) + document in IndexInstanceNode.objects.last().documents.all() ) def test_dual_level_dual_document_index(self): @@ -130,12 +130,15 @@ class IndexTestCase(DocumentIndexingTestMixin, DocumentTestMixin, BaseTestCase): Index.objects.rebuild() + # Typecast to sets to make sorting irrelevant in the comparison. self.assertEqual( - [instance.value for instance in IndexInstanceNode.objects.all().order_by('pk')], - [ - '', force_text(self.document_2.uuid), self.document_2.label, - force_text(self.document.uuid), self.document.label - ] + set(IndexInstanceNode.objects.values_list('value', flat=True)), + set( + [ + '', force_text(self.document_2.uuid), self.document_2.label, + force_text(self.document.uuid), self.document.label + ] + ) ) def test_metadata_indexing(self):