@@ -79,43 +79,30 @@ def test_define_field_twice(self):
79
79
)
80
80
81
81
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
-
103
82
@skipUnlessDBFeature ("supports_atlas_search" )
104
- class SearchIndexSchemaTests (SchemaAssertionMixin , TestCase ):
83
+ class SearchIndexSchemaTests (TestCase ):
105
84
def test_simple (self ):
106
85
with connection .schema_editor () as editor :
107
86
index = SearchIndex (
108
87
name = "recent_article_idx" ,
109
88
fields = ["number" ],
110
89
)
111
90
editor .add_index (index = index , model = Article )
112
- self . assertAddRemoveIndex ( editor , Article , index )
91
+ editor . remove_index ( index = index , model = Article )
113
92
114
93
def test_multiple_fields (self ):
115
94
with connection .schema_editor () as editor :
116
95
index = SearchIndex (
117
96
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
+ ],
119
106
)
120
107
editor .add_index (index = index , model = Article )
121
108
index_info = connection .introspection .get_constraints (
@@ -146,20 +133,21 @@ def test_multiple_fields(self):
146
133
"representation" : "double" ,
147
134
"type" : "number" ,
148
135
},
136
+ "object_id" : {"type" : "objectId" },
149
137
},
150
138
}
151
139
self .assertCountEqual (index_info [index .name ]["columns" ], index .fields )
152
140
self .assertEqual (index_info [index .name ]["options" ], expected_options )
153
- self . assertAddRemoveIndex ( editor , Article , index )
141
+ editor . remove_index ( index = index , model = Article )
154
142
155
143
156
144
@skipUnlessDBFeature ("supports_atlas_search" )
157
- class VectorSearchIndexSchemaTests (SchemaAssertionMixin , TestCase ):
145
+ class VectorSearchIndexSchemaTests (TestCase ):
158
146
def test_simple_vector_search (self ):
159
147
with connection .schema_editor () as editor :
160
148
index = VectorSearchIndex (name = "recent_article_idx" , fields = ["number" ])
161
149
editor .add_index (index = index , model = Article )
162
- self . assertAddRemoveIndex ( editor , Article , index )
150
+ editor . remove_index ( index = index , model = Article )
163
151
164
152
def test_multiple_fields (self ):
165
153
with connection .schema_editor () as editor :
@@ -195,4 +183,4 @@ def test_multiple_fields(self):
195
183
index_info [index .name ]["options" ].pop ("id" )
196
184
index_info [index .name ]["options" ].pop ("status" )
197
185
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