Skip to content

Commit 61047a3

Browse files
committed
Fixed ordering issues in the ElasticSearch tests.
1 parent ebfb47c commit 61047a3

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

tests/elasticsearch_tests/tests/elasticsearch_backend.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,10 @@ def tearDown(self):
604604
super(LiveElasticsearchSearchQuerySetTestCase, self).tearDown()
605605

606606
def test_load_all(self):
607-
sqs = self.sqs.load_all()
607+
sqs = self.sqs.order_by('pub_date').load_all()
608608
self.assertTrue(isinstance(sqs, SearchQuerySet))
609609
self.assertTrue(len(sqs) > 0)
610-
self.assertEqual(sqs[0].object.foo, u'In addition, you may specify other fields to be populated along with the document. In this case, we also index the user who authored the document as well as the date the document was published. The variable you assign the SearchField to should directly map to the field your search backend is expecting. You instantiate most search fields with a parameter that points to the attribute of the object to populate that field with.')
610+
self.assertEqual(sqs[2].object.foo, u'In addition, you may specify other fields to be populated along with the document. In this case, we also index the user who authored the document as well as the date the document was published. The variable you assign the SearchField to should directly map to the field your search backend is expecting. You instantiate most search fields with a parameter that points to the attribute of the object to populate that field with.')
611611

612612
def test_iter(self):
613613
reset_search_queries()
@@ -620,8 +620,8 @@ def test_iter(self):
620620
def test_slice(self):
621621
reset_search_queries()
622622
self.assertEqual(len(connections['default'].queries), 0)
623-
results = self.sqs.all()
624-
self.assertEqual([int(result.pk) for result in results[1:11]], [7, 12, 17, 1, 6, 11, 16, 23, 5, 10])
623+
results = self.sqs.all().order_by('pub_date')
624+
self.assertEqual([int(result.pk) for result in results[1:11]], [3, 2, 4, 5, 6, 7, 8, 9, 10, 11])
625625
self.assertEqual(len(connections['default'].queries), 1)
626626

627627
reset_search_queries()
@@ -646,8 +646,8 @@ def test_manual_iter(self):
646646

647647
reset_search_queries()
648648
self.assertEqual(len(connections['default'].queries), 0)
649-
results = [int(result.pk) for result in results._manual_iter()]
650-
self.assertEqual(results, [2, 7, 12, 17, 1, 6, 11, 16, 23, 5, 10, 15, 22, 4, 9, 14, 19, 21, 3, 8, 13, 18, 20])
649+
results = set([int(result.pk) for result in results._manual_iter()])
650+
self.assertEqual(results, set([2, 7, 12, 17, 1, 6, 11, 16, 23, 5, 10, 15, 22, 4, 9, 14, 19, 21, 3, 8, 13, 18, 20]))
651651
self.assertEqual(len(connections['default'].queries), 3)
652652

653653
def test_fill_cache(self):
@@ -748,10 +748,10 @@ def test_regression_raw_search_breaks_slicing(self):
748748
# RelatedSearchQuerySet Tests
749749

750750
def test_related_load_all(self):
751-
sqs = self.rsqs.load_all()
751+
sqs = self.rsqs.order_by('pub_date').load_all()
752752
self.assertTrue(isinstance(sqs, SearchQuerySet))
753753
self.assertTrue(len(sqs) > 0)
754-
self.assertEqual(sqs[0].object.foo, u'In addition, you may specify other fields to be populated along with the document. In this case, we also index the user who authored the document as well as the date the document was published. The variable you assign the SearchField to should directly map to the field your search backend is expecting. You instantiate most search fields with a parameter that points to the attribute of the object to populate that field with.')
754+
self.assertEqual(sqs[2].object.foo, u'In addition, you may specify other fields to be populated along with the document. In this case, we also index the user who authored the document as well as the date the document was published. The variable you assign the SearchField to should directly map to the field your search backend is expecting. You instantiate most search fields with a parameter that points to the attribute of the object to populate that field with.')
755755

756756
def test_related_load_all_queryset(self):
757757
sqs = self.rsqs.load_all()
@@ -765,22 +765,22 @@ def test_related_load_all_queryset(self):
765765
sqs = sqs.load_all_queryset(MockModel, MockModel.objects.filter(id__gt=10))
766766
self.assertTrue(isinstance(sqs, SearchQuerySet))
767767
self.assertEqual(len(sqs._load_all_querysets), 1)
768-
self.assertEqual([obj.object.id for obj in sqs], [12, 17, 11, 16, 23, 15, 22, 14, 19, 21, 13, 18, 20])
769-
self.assertEqual([obj.object.id for obj in sqs[10:20]], [13, 18, 20])
768+
self.assertEqual(set([obj.object.id for obj in sqs]), set([12, 17, 11, 16, 23, 15, 22, 14, 19, 21, 13, 18, 20]))
769+
self.assertEqual(set([obj.object.id for obj in sqs[10:20]]), set([13, 18, 20]))
770770

771771
def test_related_iter(self):
772772
reset_search_queries()
773773
self.assertEqual(len(connections['default'].queries), 0)
774774
sqs = self.rsqs.all()
775-
results = [int(result.pk) for result in sqs]
776-
self.assertEqual(results, [2, 7, 12, 17, 1, 6, 11, 16, 23, 5, 10, 15, 22, 4, 9, 14, 19, 21, 3, 8, 13, 18, 20])
775+
results = set([int(result.pk) for result in sqs])
776+
self.assertEqual(results, set([2, 7, 12, 17, 1, 6, 11, 16, 23, 5, 10, 15, 22, 4, 9, 14, 19, 21, 3, 8, 13, 18, 20]))
777777
self.assertEqual(len(connections['default'].queries), 4)
778778

779779
def test_related_slice(self):
780780
reset_search_queries()
781781
self.assertEqual(len(connections['default'].queries), 0)
782-
results = self.rsqs.all()
783-
self.assertEqual([int(result.pk) for result in results[1:11]], [7, 12, 17, 1, 6, 11, 16, 23, 5, 10])
782+
results = self.rsqs.all().order_by('pub_date')
783+
self.assertEqual([int(result.pk) for result in results[1:11]], [3, 2, 4, 5, 6, 7, 8, 9, 10, 11])
784784
self.assertEqual(len(connections['default'].queries), 3)
785785

786786
reset_search_queries()
@@ -792,7 +792,7 @@ def test_related_slice(self):
792792
reset_search_queries()
793793
self.assertEqual(len(connections['default'].queries), 0)
794794
results = self.rsqs.all()
795-
self.assertEqual([int(result.pk) for result in results[20:30]], [13, 18, 20])
795+
self.assertEqual(set([int(result.pk) for result in results[20:30]]), set([13, 18, 20]))
796796
self.assertEqual(len(connections['default'].queries), 4)
797797

798798
def test_related_manual_iter(self):
@@ -922,17 +922,17 @@ def tearDown(self):
922922
def test_more_like_this(self):
923923
mlt = self.sqs.more_like_this(MockModel.objects.get(pk=1))
924924
self.assertEqual(mlt.count(), 4)
925-
self.assertEqual([result.pk for result in mlt], [u'2', u'6', u'16', u'23'])
925+
self.assertEqual(set([result.pk for result in mlt]), set([u'2', u'6', u'16', u'23']))
926926
self.assertEqual(len([result.pk for result in mlt]), 4)
927927

928928
alt_mlt = self.sqs.filter(name='daniel3').more_like_this(MockModel.objects.get(pk=2))
929929
self.assertEqual(alt_mlt.count(), 6)
930-
self.assertEqual([result.pk for result in alt_mlt], [u'2', u'6', u'16', u'23', u'1', u'11'])
930+
self.assertEqual(set([result.pk for result in alt_mlt]), set([u'2', u'6', u'16', u'23', u'1', u'11']))
931931
self.assertEqual(len([result.pk for result in alt_mlt]), 6)
932932

933933
alt_mlt_with_models = self.sqs.models(MockModel).more_like_this(MockModel.objects.get(pk=1))
934934
self.assertEqual(alt_mlt_with_models.count(), 4)
935-
self.assertEqual([result.pk for result in alt_mlt_with_models], [u'2', u'6', u'16', u'23'])
935+
self.assertEqual(set([result.pk for result in alt_mlt_with_models]), set([u'2', u'6', u'16', u'23']))
936936
self.assertEqual(len([result.pk for result in alt_mlt_with_models]), 4)
937937

938938
if hasattr(MockModel.objects, 'defer'):
@@ -1025,7 +1025,7 @@ def test_build_schema(self):
10251025
def test_autocomplete(self):
10261026
autocomplete = self.sqs.autocomplete(text_auto='mod')
10271027
self.assertEqual(autocomplete.count(), 16)
1028-
self.assertEqual([result.pk for result in autocomplete], ['1', '12', '6', '14', '7', '4', '23', '17', '13', '18', '20', '22', '19', '15', '10', '2'])
1028+
self.assertEqual(set([result.pk for result in autocomplete]), set(['1', '12', '6', '14', '7', '4', '23', '17', '13', '18', '20', '22', '19', '15', '10', '2']))
10291029
self.assertTrue('mod' in autocomplete[0].text.lower())
10301030
self.assertTrue('mod' in autocomplete[1].text.lower())
10311031
self.assertTrue('mod' in autocomplete[2].text.lower())
@@ -1036,7 +1036,7 @@ def test_autocomplete(self):
10361036
# Test multiple words.
10371037
autocomplete_2 = self.sqs.autocomplete(text_auto='your mod')
10381038
self.assertEqual(autocomplete_2.count(), 13)
1039-
self.assertEqual([result.pk for result in autocomplete_2], ['1', '6', '2', '14', '12', '13', '10', '19', '4', '20', '23', '22', '15'])
1039+
self.assertEqual(set([result.pk for result in autocomplete_2]), set(['1', '6', '2', '14', '12', '13', '10', '19', '4', '20', '23', '22', '15']))
10401040
self.assertTrue('your' in autocomplete_2[0].text.lower())
10411041
self.assertTrue('mod' in autocomplete_2[0].text.lower())
10421042
self.assertTrue('your' in autocomplete_2[1].text.lower())
@@ -1047,7 +1047,7 @@ def test_autocomplete(self):
10471047
# Test multiple fields.
10481048
autocomplete_3 = self.sqs.autocomplete(text_auto='Django', name_auto='dan')
10491049
self.assertEqual(autocomplete_3.count(), 4)
1050-
self.assertEqual([result.pk for result in autocomplete_3], ['12', '1', '22', '14'])
1050+
self.assertEqual(set([result.pk for result in autocomplete_3]), set(['12', '1', '22', '14']))
10511051
self.assertEqual(len([result.pk for result in autocomplete_3]), 4)
10521052

10531053

@@ -1185,12 +1185,12 @@ def test_boost(self):
11851185

11861186
results = SearchQuerySet().filter(SQ(author='daniel') | SQ(editor='daniel'))
11871187

1188-
self.assertEqual([result.id for result in results], [
1188+
self.assertEqual(set([result.id for result in results]), set([
11891189
'core.afourthmockmodel.4',
11901190
'core.afourthmockmodel.3',
11911191
'core.afourthmockmodel.1',
11921192
'core.afourthmockmodel.2'
1193-
])
1193+
]))
11941194

11951195
def test__to_python(self):
11961196
self.assertEqual(self.sb._to_python('abc'), 'abc')

0 commit comments

Comments
 (0)