Skip to content

Commit 5d5f225

Browse files
committed
Add unit tests
1 parent 67c7cf1 commit 5d5f225

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

tests/indexes_/test_atlas_indexes.py

+40-6
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,43 @@ def test_field_not_exists(self):
165165
name="recent_article_idx",
166166
fields=["headline", "non_existing_name", "title_embedded"],
167167
)
168-
with connection.schema_editor() as editor:
169-
msg = "Article has no field named 'non_existing_name'"
170-
with self.assertRaisesMessage(
171-
FieldDoesNotExist, msg
172-
), connection.schema_editor() as editor:
173-
editor.add_index(index=index, model=Article)
168+
msg = "Article has no field named 'non_existing_name'"
169+
with self.assertRaisesMessage(FieldDoesNotExist, msg), connection.schema_editor() as editor:
170+
editor.add_index(index=index, model=Article)
171+
172+
def test_field_size_required(self):
173+
index = VectorSearchIndex(
174+
name="recent_article_idx",
175+
fields=["number_list"],
176+
)
177+
msg = "Atlas vector search requires size."
178+
with self.assertRaisesMessage(ValueError, msg), connection.schema_editor() as editor:
179+
editor.add_index(index=index, model=Article)
180+
181+
def test_field_type_mismatch(self):
182+
index = VectorSearchIndex(
183+
name="recent_article_idx",
184+
fields=["name_list"],
185+
)
186+
msg = "Base type must be Float or Decimal."
187+
with self.assertRaisesMessage(ValueError, msg), connection.schema_editor() as editor:
188+
editor.add_index(index=index, model=Article)
189+
190+
def test_field_unsuported_type(self):
191+
index = VectorSearchIndex(
192+
name="recent_article_idx",
193+
fields=["data"],
194+
)
195+
msg = "Unsupported filter of type JSONField."
196+
with self.assertRaisesMessage(ValueError, msg), connection.schema_editor() as editor:
197+
editor.add_index(index=index, model=Article)
198+
199+
def test_field_unsuported_similarity_function(self):
200+
msg = (
201+
"cross_product isn't a valid similarity function, options"
202+
f" 'are {','.join(VectorSearchIndex.ALLOWED_SIMILARITY_FUNCTIONS)}"
203+
)
204+
with self.assertRaisesMessage(ValueError, msg):
205+
VectorSearchIndex(
206+
name="recent_article_idx", fields=["data"], similarities="cross_product"
207+
)

0 commit comments

Comments
 (0)