@@ -79,43 +79,30 @@ def test_define_field_twice(self):
7979 )
8080
8181
82- class SchemaAssertionMixin :
83- def assertAddRemoveIndex (self , editor , model , index ):
84- with self .assertNumQueries (1 ):
85- editor .add_index (index = index , model = model )
86- self .assertIn (
87- index .name ,
88- connection .introspection .get_constraints (
89- cursor = None ,
90- table_name = model ._meta .db_table ,
91- ),
92- )
93- editor .remove_index (index = index , model = model )
94- self .assertNotIn (
95- index .name ,
96- connection .introspection .get_constraints (
97- cursor = None ,
98- table_name = model ._meta .db_table ,
99- ),
100- )
101-
102-
10382@skipUnlessDBFeature ("supports_atlas_search" )
104- class SearchIndexSchemaTests (SchemaAssertionMixin , TestCase ):
83+ class SearchIndexSchemaTests (TestCase ):
10584 def test_simple (self ):
10685 with connection .schema_editor () as editor :
10786 index = SearchIndex (
10887 name = "recent_article_idx" ,
10988 fields = ["number" ],
11089 )
11190 editor .add_index (index = index , model = Article )
112- self . assertAddRemoveIndex ( editor , Article , index )
91+ editor . remove_index ( index = index , model = Article )
11392
11493 def test_multiple_fields (self ):
11594 with connection .schema_editor () as editor :
11695 index = SearchIndex (
11796 name = "recent_article_idx" ,
118- fields = ["headline" , "number" , "body" , "data" , "embedded" , "created_at" ],
97+ fields = [
98+ "headline" ,
99+ "number" ,
100+ "body" ,
101+ "data" ,
102+ "embedded" ,
103+ "created_at" ,
104+ "object_id" ,
105+ ],
119106 )
120107 editor .add_index (index = index , model = Article )
121108 index_info = connection .introspection .get_constraints (
@@ -146,20 +133,21 @@ def test_multiple_fields(self):
146133 "representation" : "double" ,
147134 "type" : "number" ,
148135 },
136+ "object_id" : {"type" : "objectId" },
149137 },
150138 }
151139 self .assertCountEqual (index_info [index .name ]["columns" ], index .fields )
152140 self .assertEqual (index_info [index .name ]["options" ], expected_options )
153- self . assertAddRemoveIndex ( editor , Article , index )
141+ editor . remove_index ( index = index , model = Article )
154142
155143
156144@skipUnlessDBFeature ("supports_atlas_search" )
157- class VectorSearchIndexSchemaTests (SchemaAssertionMixin , TestCase ):
145+ class VectorSearchIndexSchemaTests (TestCase ):
158146 def test_simple_vector_search (self ):
159147 with connection .schema_editor () as editor :
160148 index = VectorSearchIndex (name = "recent_article_idx" , fields = ["number" ])
161149 editor .add_index (index = index , model = Article )
162- self . assertAddRemoveIndex ( editor , Article , index )
150+ editor . remove_index ( index = index , model = Article )
163151
164152 def test_multiple_fields (self ):
165153 with connection .schema_editor () as editor :
@@ -195,4 +183,4 @@ def test_multiple_fields(self):
195183 index_info [index .name ]["options" ].pop ("id" )
196184 index_info [index .name ]["options" ].pop ("status" )
197185 self .assertEqual (index_info [index .name ]["options" ], expected_options )
198- self . assertAddRemoveIndex ( editor , Article , index )
186+ editor . remove_index ( index = index , model = Article )
0 commit comments