Skip to content

Commit f1ef561

Browse files
author
Alexey Kotlyarov
committed
Test ensuring recreating the index does not remove the mapping
1 parent 6e62bf1 commit f1ef561

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/elasticsearch_tests/tests/elasticsearch_backend.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,3 +1202,28 @@ def test__to_python(self):
12021202
self.assertEqual(self.sb._to_python('2009-05-09T16:14:00'), datetime.datetime(2009, 5, 9, 16, 14))
12031203
self.assertEqual(self.sb._to_python('2009-05-09T00:00:00'), datetime.datetime(2009, 5, 9, 0, 0))
12041204
self.assertEqual(self.sb._to_python(None), None)
1205+
1206+
1207+
class RecreateIndexTestCase(TestCase):
1208+
def setUp(self):
1209+
self.raw_es = pyelasticsearch.ElasticSearch(
1210+
settings.HAYSTACK_CONNECTIONS['default']['URL'])
1211+
1212+
def test_recreate_index(self):
1213+
clear_elasticsearch_index()
1214+
1215+
sb = connections['default'].get_backend()
1216+
sb.silently_fail = True
1217+
sb.setup()
1218+
1219+
original_mapping = self.raw_es.get_mapping(sb.index_name)
1220+
1221+
sb.clear()
1222+
sb.setup()
1223+
1224+
try:
1225+
updated_mapping = self.raw_es.get_mapping(sb.index_name)
1226+
except pyelasticsearch.ElasticHttpNotFoundError:
1227+
self.fail("There is no mapping after recreating the index")
1228+
self.assertEqual(original_mapping, updated_mapping,
1229+
"Mapping after recreating the index differs from the original one")

0 commit comments

Comments
 (0)