1
1
from django .db import connection
2
- from django .test import TestCase , skipUnlessDBFeature
2
+ from django .test import TestCase , skipIfDBFeature , skipUnlessDBFeature
3
3
4
4
from django_mongodb_backend .indexes import SearchIndex , VectorSearchIndex
5
5
6
6
from .models import Article
7
7
8
8
9
- @skipUnlessDBFeature ("supports_atlas_search" )
10
9
class SearchIndexTests (TestCase ):
11
10
# Tests for creating, validating, and removing search indexes using Django's schema editor.
12
11
available_apps = None
@@ -29,6 +28,7 @@ def assertAddRemoveIndex(self, editor, model, index):
29
28
),
30
29
)
31
30
31
+ @skipUnlessDBFeature ("supports_atlas_search" )
32
32
def test_simple (self ):
33
33
with connection .schema_editor () as editor :
34
34
index = SearchIndex (
@@ -38,6 +38,23 @@ def test_simple(self):
38
38
editor .add_index (index = index , model = Article )
39
39
self .assertAddRemoveIndex (editor , Article , index )
40
40
41
+ @skipIfDBFeature ("supports_atlas_search" )
42
+ def test_index_not_created (self ):
43
+ with connection .schema_editor () as editor :
44
+ index = SearchIndex (
45
+ name = "recent_article_idx" ,
46
+ fields = ["number" ],
47
+ )
48
+ editor .add_index (index = index , model = Article )
49
+ self .assertNotIn (
50
+ index .name ,
51
+ connection .introspection .get_constraints (
52
+ cursor = None ,
53
+ table_name = Article ._meta .db_table ,
54
+ ),
55
+ )
56
+
57
+ @skipUnlessDBFeature ("supports_atlas_search" )
41
58
def test_multiple_fields (self ):
42
59
with connection .schema_editor () as editor :
43
60
index = SearchIndex (
@@ -80,7 +97,6 @@ def test_multiple_fields(self):
80
97
self .assertAddRemoveIndex (editor , Article , index )
81
98
82
99
83
- @skipUnlessDBFeature ("supports_atlas_search" )
84
100
class VectorSearchIndexTests (TestCase ):
85
101
# Tests for creating, validating, and removing vector search indexes
86
102
# using Django's schema editor.
@@ -104,6 +120,7 @@ def assertAddRemoveIndex(self, editor, model, index):
104
120
),
105
121
)
106
122
123
+ @skipUnlessDBFeature ("supports_atlas_search" )
107
124
def test_deconstruct_default_similarity (self ):
108
125
index = VectorSearchIndex (
109
126
name = "recent_article_idx" ,
@@ -113,6 +130,23 @@ def test_deconstruct_default_similarity(self):
113
130
new = VectorSearchIndex (* args , ** kwargs )
114
131
self .assertEqual (new .similarities , index .similarities )
115
132
133
+ @skipIfDBFeature ("supports_atlas_search" )
134
+ def test_index_not_created (self ):
135
+ with connection .schema_editor () as editor :
136
+ index = VectorSearchIndex (
137
+ name = "recent_article_idx" ,
138
+ fields = ["number" ],
139
+ )
140
+ editor .add_index (index = index , model = Article )
141
+ self .assertNotIn (
142
+ index .name ,
143
+ connection .introspection .get_constraints (
144
+ cursor = None ,
145
+ table_name = Article ._meta .db_table ,
146
+ ),
147
+ )
148
+
149
+ @skipUnlessDBFeature ("supports_atlas_search" )
116
150
def test_deconstruct_with_similarities (self ):
117
151
index = VectorSearchIndex (
118
152
name = "recent_article_idx" ,
@@ -123,6 +157,7 @@ def test_deconstruct_with_similarities(self):
123
157
new = VectorSearchIndex (* args , ** kwargs )
124
158
self .assertEqual (new .similarities , index .similarities )
125
159
160
+ @skipUnlessDBFeature ("supports_atlas_search" )
126
161
def test_simple_vector_search (self ):
127
162
with connection .schema_editor () as editor :
128
163
index = VectorSearchIndex (
@@ -132,6 +167,7 @@ def test_simple_vector_search(self):
132
167
editor .add_index (index = index , model = Article )
133
168
self .assertAddRemoveIndex (editor , Article , index )
134
169
170
+ @skipUnlessDBFeature ("supports_atlas_search" )
135
171
def test_multiple_fields (self ):
136
172
with connection .schema_editor () as editor :
137
173
index = VectorSearchIndex (
0 commit comments