11from django .db import connection
2- from django .test import TestCase , skipIfDBFeature , skipUnlessDBFeature
2+ from django .test import SimpleTestCase , TestCase , skipIfDBFeature , skipUnlessDBFeature
33
44from django_mongodb_backend .indexes import SearchIndex , VectorSearchIndex
55
@@ -26,20 +26,8 @@ def assertAddRemoveIndex(self, editor, model, index):
2626 )
2727
2828
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 ):
4331 def test_index_not_created (self ):
4432 with connection .schema_editor () as editor :
4533 index = SearchIndex (
@@ -55,7 +43,20 @@ def test_index_not_created(self):
5543 ),
5644 )
5745
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+
5960 def test_multiple_fields (self ):
6061 with connection .schema_editor () as editor :
6162 index = SearchIndex (
@@ -98,11 +99,12 @@ def test_multiple_fields(self):
9899 self .assertAddRemoveIndex (editor , Article , index )
99100
100101
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 )
106108
107109 def test_invalid_similarity_function (self ):
108110 msg = (
@@ -123,14 +125,9 @@ def test_define_field_twice(self):
123125 similarities = "dotProduct" ,
124126 )
125127
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 )
132128
133- @skipIfDBFeature ("supports_atlas_search" )
129+ @skipIfDBFeature ("supports_atlas_search" )
130+ class UnsupportedVectorSearchIndexesTests (TestCase ):
134131 def test_index_not_created (self ):
135132 with connection .schema_editor () as editor :
136133 index = VectorSearchIndex (
@@ -146,7 +143,14 @@ def test_index_not_created(self):
146143 ),
147144 )
148145
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+
150154 def test_deconstruct_with_similarities (self ):
151155 index = VectorSearchIndex (
152156 name = "recent_article_idx" ,
@@ -157,7 +161,6 @@ def test_deconstruct_with_similarities(self):
157161 new = VectorSearchIndex (* args , ** kwargs )
158162 self .assertEqual (new .similarities , index .similarities )
159163
160- @skipUnlessDBFeature ("supports_atlas_search" )
161164 def test_simple_vector_search (self ):
162165 with connection .schema_editor () as editor :
163166 index = VectorSearchIndex (
@@ -167,7 +170,6 @@ def test_simple_vector_search(self):
167170 editor .add_index (index = index , model = Article )
168171 self .assertAddRemoveIndex (editor , Article , index )
169172
170- @skipUnlessDBFeature ("supports_atlas_search" )
171173 def test_multiple_fields (self ):
172174 with connection .schema_editor () as editor :
173175 index = VectorSearchIndex (
0 commit comments