Skip to content

Commit 1aa6f67

Browse files
committed
Tests: Fix ElasticSearch index setup (see django-haystack#1093)
Previously when clear_elasticsearch_index() was called to reset the tests, this could produce confusing results because it cleared the mappings without resetting the backend’s setup_complete status and thus fields which were expected to have a specific type would end up being inferred With this changed test_regression_proper_start_offsets and test_more_like_this no longer fail
1 parent 2a958b9 commit 1aa6f67

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test_haystack/elasticsearch_tests/test_elasticsearch_backend.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def clear_elasticsearch_index():
4141
except elasticsearch.TransportError:
4242
pass
4343

44+
# Since we've just completely deleted the index, we'll reset setup_complete so the next access will
45+
# correctly define the mappings:
46+
connections['elasticsearch'].get_backend().setup_complete = False
47+
4448

4549
class ElasticsearchMockSearchIndex(indexes.SearchIndex, indexes.Indexable):
4650
text = indexes.CharField(document=True, use_template=True)
@@ -791,7 +795,6 @@ def test_auto_query(self):
791795

792796
# Regressions
793797

794-
@unittest.expectedFailure
795798
def test_regression_proper_start_offsets(self):
796799
sqs = self.sqs.filter(text='index')
797800
self.assertNotEqual(sqs.count(), 0)
@@ -1027,7 +1030,6 @@ def tearDown(self):
10271030
connections['elasticsearch']._index = self.old_ui
10281031
super(LiveElasticsearchMoreLikeThisTestCase, self).tearDown()
10291032

1030-
@unittest.expectedFailure
10311033
def test_more_like_this(self):
10321034
mlt = self.sqs.more_like_this(MockModel.objects.get(pk=1))
10331035
self.assertEqual(mlt.count(), 4)

0 commit comments

Comments
 (0)