1
1
from django .db import connection
2
- from django .test import TestCase , skipIfDBFeature , skipUnlessDBFeature
2
+ from django .test import SimpleTestCase , TestCase , skipIfDBFeature , skipUnlessDBFeature
3
3
4
4
from django_mongodb_backend .indexes import SearchIndex , VectorSearchIndex
5
5
@@ -26,20 +26,8 @@ def assertAddRemoveIndex(self, editor, model, index):
26
26
)
27
27
28
28
29
- class SearchIndexTests (TestMixin , TestCase ):
30
- """Tests for creating, validating, and removing search indexes using Django's schema editor."""
31
-
32
- @skipUnlessDBFeature ("supports_atlas_search" )
33
- def test_simple (self ):
34
- with connection .schema_editor () as editor :
35
- index = SearchIndex (
36
- name = "recent_article_idx" ,
37
- fields = ["number" ],
38
- )
39
- editor .add_index (index = index , model = Article )
40
- self .assertAddRemoveIndex (editor , Article , index )
41
-
42
- @skipIfDBFeature ("supports_atlas_search" )
29
+ @skipIfDBFeature ("supports_atlas_search" )
30
+ class UnsupportedSearchIndexesTests (TestCase ):
43
31
def test_index_not_created (self ):
44
32
with connection .schema_editor () as editor :
45
33
index = SearchIndex (
@@ -55,7 +43,20 @@ def test_index_not_created(self):
55
43
),
56
44
)
57
45
58
- @skipUnlessDBFeature ("supports_atlas_search" )
46
+
47
+ @skipUnlessDBFeature ("supports_atlas_search" )
48
+ class SearchIndexTests (TestMixin , TestCase ):
49
+ """Tests for creating, validating, and removing search indexes using Django's schema editor."""
50
+
51
+ def test_simple (self ):
52
+ with connection .schema_editor () as editor :
53
+ index = SearchIndex (
54
+ name = "recent_article_idx" ,
55
+ fields = ["number" ],
56
+ )
57
+ editor .add_index (index = index , model = Article )
58
+ self .assertAddRemoveIndex (editor , Article , index )
59
+
59
60
def test_multiple_fields (self ):
60
61
with connection .schema_editor () as editor :
61
62
index = SearchIndex (
@@ -98,11 +99,12 @@ def test_multiple_fields(self):
98
99
self .assertAddRemoveIndex (editor , Article , index )
99
100
100
101
101
- class VectorSearchIndexTests (TestMixin , TestCase ):
102
- """
103
- Tests for creating, validating, and removing vector search indexes
104
- using Django's schema editor.
105
- """
102
+ class VectorSearchIndexesInvalidArgumentsTests (SimpleTestCase ): # TODO CHANGE NAME
103
+ def test_deconstruct_default_similarity (self ):
104
+ index = VectorSearchIndex (name = "recent_article_idx" , fields = ["number" ])
105
+ name , args , kwargs = index .deconstruct ()
106
+ new = VectorSearchIndex (* args , ** kwargs )
107
+ self .assertEqual (new .similarities , index .similarities )
106
108
107
109
def test_invalid_similarity_function (self ):
108
110
msg = (
@@ -123,14 +125,9 @@ def test_define_field_twice(self):
123
125
similarities = "dotProduct" ,
124
126
)
125
127
126
- @skipUnlessDBFeature ("supports_atlas_search" )
127
- def test_deconstruct_default_similarity (self ):
128
- index = VectorSearchIndex (name = "recent_article_idx" , fields = ["number" ])
129
- name , args , kwargs = index .deconstruct ()
130
- new = VectorSearchIndex (* args , ** kwargs )
131
- self .assertEqual (new .similarities , index .similarities )
132
128
133
- @skipIfDBFeature ("supports_atlas_search" )
129
+ @skipIfDBFeature ("supports_atlas_search" )
130
+ class UnsupportedVectorSearchIndexesTests (TestCase ):
134
131
def test_index_not_created (self ):
135
132
with connection .schema_editor () as editor :
136
133
index = VectorSearchIndex (
@@ -146,7 +143,14 @@ def test_index_not_created(self):
146
143
),
147
144
)
148
145
149
- @skipUnlessDBFeature ("supports_atlas_search" )
146
+
147
+ @skipUnlessDBFeature ("supports_atlas_search" )
148
+ class VectorSearchIndexTests (TestMixin , TestCase ):
149
+ """
150
+ Tests for creating, validating, and removing vector search indexes
151
+ using Django's schema editor.
152
+ """
153
+
150
154
def test_deconstruct_with_similarities (self ):
151
155
index = VectorSearchIndex (
152
156
name = "recent_article_idx" ,
@@ -157,7 +161,6 @@ def test_deconstruct_with_similarities(self):
157
161
new = VectorSearchIndex (* args , ** kwargs )
158
162
self .assertEqual (new .similarities , index .similarities )
159
163
160
- @skipUnlessDBFeature ("supports_atlas_search" )
161
164
def test_simple_vector_search (self ):
162
165
with connection .schema_editor () as editor :
163
166
index = VectorSearchIndex (
@@ -167,7 +170,6 @@ def test_simple_vector_search(self):
167
170
editor .add_index (index = index , model = Article )
168
171
self .assertAddRemoveIndex (editor , Article , index )
169
172
170
- @skipUnlessDBFeature ("supports_atlas_search" )
171
173
def test_multiple_fields (self ):
172
174
with connection .schema_editor () as editor :
173
175
index = VectorSearchIndex (
0 commit comments