1
+ from django .core .exceptions import FieldDoesNotExist
1
2
from django .db import connection
2
3
from django .test import TestCase
3
4
@@ -21,6 +22,13 @@ def assertAddRemoveIndex(self, editor, model, index):
21
22
),
22
23
)
23
24
editor .remove_index (index = index , model = model )
25
+ self .assertNotIn (
26
+ index .name ,
27
+ connection .introspection .get_constraints (
28
+ cursor = None ,
29
+ table_name = model ._meta .db_table ,
30
+ ),
31
+ )
24
32
25
33
def test_simple_atlas_index (self ):
26
34
with connection .schema_editor () as editor :
@@ -37,7 +45,6 @@ def test_multiple_fields_atlas_index(self):
37
45
name = "recent_article_idx" ,
38
46
fields = ["headline" , "number" , "body" , "data" , "embedded" , "auto_now" ],
39
47
)
40
- # editor.remove_index(index=index, model=Article)
41
48
editor .add_index (index = index , model = Article )
42
49
index_info = connection .introspection .get_constraints (
43
50
cursor = None ,
@@ -71,6 +78,16 @@ def test_multiple_fields_atlas_index(self):
71
78
}
72
79
self .assertCountEqual (index_info [index .name ]["columns" ], index .fields )
73
80
self .assertEqual (index_info [index .name ]["options" ], expected_options )
74
-
75
- self .assertEqual (index_info , {})
76
81
self .assertAddRemoveIndex (editor , Article , index )
82
+
83
+ def test_field_not_exists (self ):
84
+ index = AtlasSearchIndex (
85
+ name = "recent_article_idx" ,
86
+ fields = ["headline" , "number1" ],
87
+ )
88
+ with connection .schema_editor () as editor :
89
+ msg = "Article has no field named 'number1'"
90
+ with self .assertRaisesMessage (
91
+ FieldDoesNotExist , msg
92
+ ), connection .schema_editor () as editor :
93
+ editor .add_index (index = index , model = Article )
0 commit comments