1+ from unittest import mock
2+
13from django .db import connection
2- from django .test import SimpleTestCase , TestCase , skipIfDBFeature , skipUnlessDBFeature
4+ from django .test import SimpleTestCase , TestCase , skipUnlessDBFeature
35
46from django_mongodb_backend .indexes import SearchIndex , VectorSearchIndex
57
68from .models import SearchIndexTestModel
79from .test_base import SchemaAssertionMixin
810
911
10- @skipIfDBFeature ( "supports_atlas_search" )
12+ @mock . patch . object ( connection . features , "supports_atlas_search" , False )
1113class UnsupportedSearchIndexesTests (TestCase ):
1214 def test_search_index_not_created (self ):
1315 with connection .schema_editor () as editor :
@@ -37,7 +39,7 @@ def test_vector_index_not_created(self):
3739
3840
3941class VectorSearchIndexTests (SimpleTestCase ):
40- def test_deconstruct_default_similarity (self ):
42+ def test_deconstruct (self ):
4143 index = VectorSearchIndex (name = "recent_test_idx" , fields = ["number" ])
4244 name , args , kwargs = index .deconstruct ()
4345 new = VectorSearchIndex (* args , ** kwargs )
@@ -87,21 +89,23 @@ def test_simple(self):
8789 name = "recent_test_idx" ,
8890 fields = ["text" ],
8991 )
90- self .assertAddRemoveIndex (index = index , model = SearchIndexTestModel )
92+ with connection .schema_editor () as editor :
93+ self .assertAddRemoveIndex (editor , index = index , model = SearchIndexTestModel )
9194
9295 def test_all_fields (self ):
9396 index = SearchIndex (
9497 name = "recent_test_idx" ,
9598 fields = [
96- "text" ,
97- "object_id" ,
98- "number" ,
99+ "boolean" ,
100+ "date" ,
99101 "embedded" ,
102+ "float" ,
100103 "json_data" ,
104+ "number" ,
105+ "object_id" ,
106+ "text" ,
101107 "vector_integer" ,
102108 "vector_float" ,
103- "boolean" ,
104- "date" ,
105109 ],
106110 )
107111 with connection .schema_editor () as editor :
@@ -115,7 +119,14 @@ def test_all_fields(self):
115119 "dynamic" : False ,
116120 "fields" : {
117121 "boolean" : {"type" : "boolean" },
122+ "date" : {"type" : "date" },
118123 "embedded" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
124+ "float" : {
125+ "indexDoubles" : True ,
126+ "indexIntegers" : True ,
127+ "representation" : "double" ,
128+ "type" : "number" ,
129+ },
119130 "json_data" : {"dynamic" : False , "fields" : {}, "type" : "document" },
120131 "number" : {
121132 "indexDoubles" : True ,
@@ -130,7 +141,6 @@ def test_all_fields(self):
130141 "store" : True ,
131142 "type" : "string" ,
132143 },
133- "date" : {"type" : "date" },
134144 "vector_float" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
135145 "vector_integer" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
136146 },
@@ -144,9 +154,10 @@ def test_all_fields(self):
144154
145155@skipUnlessDBFeature ("supports_atlas_search" )
146156class VectorSearchIndexSchemaTests (SchemaAssertionMixin , TestCase ):
147- def test_simple_vector_search (self ):
157+ def test_simple (self ):
148158 index = VectorSearchIndex (name = "recent_test_idx" , fields = ["number" ])
149- self .assertAddRemoveIndex (index = index , model = SearchIndexTestModel )
159+ with connection .schema_editor () as editor :
160+ self .assertAddRemoveIndex (editor , index = index , model = SearchIndexTestModel )
150161
151162 def test_multiple_fields (self ):
152163 index = VectorSearchIndex (
0 commit comments