1
+ from unittest import mock
2
+
1
3
from django .db import connection
2
- from django .test import SimpleTestCase , TestCase , skipIfDBFeature , skipUnlessDBFeature
4
+ from django .test import SimpleTestCase , TestCase , skipUnlessDBFeature
3
5
4
6
from django_mongodb_backend .indexes import SearchIndex , VectorSearchIndex
5
7
6
8
from .models import SearchIndexTestModel
7
9
from .test_base import SchemaAssertionMixin
8
10
9
11
10
- @skipIfDBFeature ( "supports_atlas_search" )
12
+ @mock . patch . object ( connection . features , "supports_atlas_search" , False )
11
13
class UnsupportedSearchIndexesTests (TestCase ):
12
14
def test_search_index_not_created (self ):
13
15
with connection .schema_editor () as editor :
@@ -37,7 +39,7 @@ def test_vector_index_not_created(self):
37
39
38
40
39
41
class VectorSearchIndexTests (SimpleTestCase ):
40
- def test_deconstruct_default_similarity (self ):
42
+ def test_deconstruct (self ):
41
43
index = VectorSearchIndex (name = "recent_test_idx" , fields = ["number" ])
42
44
name , args , kwargs = index .deconstruct ()
43
45
new = VectorSearchIndex (* args , ** kwargs )
@@ -87,21 +89,23 @@ def test_simple(self):
87
89
name = "recent_test_idx" ,
88
90
fields = ["text" ],
89
91
)
90
- self .assertAddRemoveIndex (index = index , model = SearchIndexTestModel )
92
+ with connection .schema_editor () as editor :
93
+ self .assertAddRemoveIndex (editor , index = index , model = SearchIndexTestModel )
91
94
92
95
def test_all_fields (self ):
93
96
index = SearchIndex (
94
97
name = "recent_test_idx" ,
95
98
fields = [
96
- "text" ,
97
- "object_id" ,
98
- "number" ,
99
+ "boolean" ,
100
+ "date" ,
99
101
"embedded" ,
102
+ "float" ,
100
103
"json_data" ,
104
+ "number" ,
105
+ "object_id" ,
106
+ "text" ,
101
107
"vector_integer" ,
102
108
"vector_float" ,
103
- "boolean" ,
104
- "date" ,
105
109
],
106
110
)
107
111
with connection .schema_editor () as editor :
@@ -115,7 +119,14 @@ def test_all_fields(self):
115
119
"dynamic" : False ,
116
120
"fields" : {
117
121
"boolean" : {"type" : "boolean" },
122
+ "date" : {"type" : "date" },
118
123
"embedded" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
124
+ "float" : {
125
+ "indexDoubles" : True ,
126
+ "indexIntegers" : True ,
127
+ "representation" : "double" ,
128
+ "type" : "number" ,
129
+ },
119
130
"json_data" : {"dynamic" : False , "fields" : {}, "type" : "document" },
120
131
"number" : {
121
132
"indexDoubles" : True ,
@@ -130,7 +141,6 @@ def test_all_fields(self):
130
141
"store" : True ,
131
142
"type" : "string" ,
132
143
},
133
- "date" : {"type" : "date" },
134
144
"vector_float" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
135
145
"vector_integer" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
136
146
},
@@ -144,9 +154,10 @@ def test_all_fields(self):
144
154
145
155
@skipUnlessDBFeature ("supports_atlas_search" )
146
156
class VectorSearchIndexSchemaTests (SchemaAssertionMixin , TestCase ):
147
- def test_simple_vector_search (self ):
157
+ def test_simple (self ):
148
158
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 )
150
161
151
162
def test_multiple_fields (self ):
152
163
index = VectorSearchIndex (
0 commit comments