Skip to content

Commit 0793b9e

Browse files
committed
included a simple schema test for field_mapping
1 parent e122374 commit 0793b9e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/indexes_/test_search_indexes.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,46 @@ def test_valid_fields(self):
207207
with connection.schema_editor() as editor:
208208
editor.remove_index(index=index, model=SearchIndexTestModel)
209209

210+
def test_field_mappings(self):
211+
index = SearchIndex(
212+
name="recent_test_idx",
213+
field_mappings={
214+
"custom_field": {
215+
"type": "string",
216+
"analyzer": "lucene.standard",
217+
"searchAnalyzer": "lucene.standard",
218+
"norms": "include",
219+
"store": True,
220+
"indexOptions": "offsets",
221+
}
222+
},
223+
)
224+
with connection.schema_editor() as editor:
225+
editor.add_index(index=index, model=SearchIndexTestModel)
226+
try:
227+
index_info = connection.introspection.get_constraints(
228+
cursor=None,
229+
table_name=SearchIndexTestModel._meta.db_table,
230+
)
231+
expected_options = {
232+
"dynamic": False,
233+
"fields": {
234+
"custom_field": {
235+
"type": "string",
236+
"analyzer": "lucene.standard",
237+
"searchAnalyzer": "lucene.standard",
238+
"norms": "include",
239+
"store": True,
240+
"indexOptions": "offsets",
241+
}
242+
},
243+
}
244+
self.assertCountEqual(index_info[index.name]["columns"], index.fields)
245+
self.assertEqual(index_info[index.name]["options"], expected_options)
246+
finally:
247+
with connection.schema_editor() as editor:
248+
editor.remove_index(index=index, model=SearchIndexTestModel)
249+
210250
def test_analyzer_inclusion(self):
211251
index = SearchIndex(
212252
name="recent_test_idx",

0 commit comments

Comments
 (0)