|
| 1 | +from unittest import mock |
| 2 | + |
1 | 3 | from django.db import connection
|
2 | 4 | from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
|
3 | 5 |
|
@@ -38,6 +40,17 @@ def test_simple(self):
|
38 | 40 | editor.add_index(index=index, model=Article)
|
39 | 41 | self.assertAddRemoveIndex(editor, Article, index)
|
40 | 42 |
|
| 43 | + def test_drop_non_existing_index(self): |
| 44 | + with connection.schema_editor() as editor: |
| 45 | + index = SearchIndex( |
| 46 | + name="recent_article_idx", |
| 47 | + fields=["number"], |
| 48 | + ) |
| 49 | + editor.get_collection = mock.MagicMock() |
| 50 | + editor.remove_index(index=index, model=Article) |
| 51 | + # Verify that the collection was not accessed |
| 52 | + editor.get_collection.assert_not_called() |
| 53 | + |
41 | 54 | @skipIfDBFeature("supports_atlas_search")
|
42 | 55 | def test_index_not_created(self):
|
43 | 56 | with connection.schema_editor() as editor:
|
@@ -120,6 +133,17 @@ def assertAddRemoveIndex(self, editor, model, index):
|
120 | 133 | ),
|
121 | 134 | )
|
122 | 135 |
|
| 136 | + def test_drop_non_existing_index(self): |
| 137 | + with connection.schema_editor() as editor: |
| 138 | + index = SearchIndex( |
| 139 | + name="recent_article_idx", |
| 140 | + fields=["number"], |
| 141 | + ) |
| 142 | + editor.get_collection = mock.MagicMock() |
| 143 | + editor.remove_index(index=index, model=Article) |
| 144 | + # Verify that the collection was not accessed |
| 145 | + editor.get_collection.assert_not_called() |
| 146 | + |
123 | 147 | @skipUnlessDBFeature("supports_atlas_search")
|
124 | 148 | def test_deconstruct_default_similarity(self):
|
125 | 149 | index = VectorSearchIndex(
|
|
0 commit comments