Skip to content

Commit fbb9c6c

Browse files
committed
Refactor unit test
1 parent 60e57b3 commit fbb9c6c

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tests/indexes_/test_atlas_indexes.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.core.exceptions import FieldDoesNotExist
12
from django.db import connection
23
from django.test import TestCase
34

@@ -21,6 +22,13 @@ def assertAddRemoveIndex(self, editor, model, index):
2122
),
2223
)
2324
editor.remove_index(index=index, model=model)
25+
self.assertNotIn(
26+
index.name,
27+
connection.introspection.get_constraints(
28+
cursor=None,
29+
table_name=model._meta.db_table,
30+
),
31+
)
2432

2533
def test_simple_atlas_index(self):
2634
with connection.schema_editor() as editor:
@@ -37,7 +45,6 @@ def test_multiple_fields_atlas_index(self):
3745
name="recent_article_idx",
3846
fields=["headline", "number", "body", "data", "embedded", "auto_now"],
3947
)
40-
# editor.remove_index(index=index, model=Article)
4148
editor.add_index(index=index, model=Article)
4249
index_info = connection.introspection.get_constraints(
4350
cursor=None,
@@ -71,6 +78,16 @@ def test_multiple_fields_atlas_index(self):
7178
}
7279
self.assertCountEqual(index_info[index.name]["columns"], index.fields)
7380
self.assertEqual(index_info[index.name]["options"], expected_options)
74-
75-
self.assertEqual(index_info, {})
7681
self.assertAddRemoveIndex(editor, Article, index)
82+
83+
def test_field_not_exists(self):
84+
index = AtlasSearchIndex(
85+
name="recent_article_idx",
86+
fields=["headline", "number1"],
87+
)
88+
with connection.schema_editor() as editor:
89+
msg = "Article has no field named 'number1'"
90+
with self.assertRaisesMessage(
91+
FieldDoesNotExist, msg
92+
), connection.schema_editor() as editor:
93+
editor.add_index(index=index, model=Article)

0 commit comments

Comments
 (0)