Skip to content

Commit 90629b7

Browse files
committed
Add simple index operation tests.
1 parent 113df00 commit 90629b7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/indexes_/test_mql.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,35 @@ def test_composite_op_index(self):
116116
),
117117
)
118118
editor.remove_index(index=index, model=Article)
119+
120+
def test_simple_operations(self):
121+
mongo_operators_idx = (
122+
("gt", "$gt"),
123+
("gte", "$gte"),
124+
("lt", "$lt"),
125+
("lte", "$lte"),
126+
)
127+
128+
for op, mongo_operator in mongo_operators_idx:
129+
with self.subTest(operator=op), connection.schema_editor() as editor:
130+
index = Index(
131+
name="composite_proposition",
132+
fields=["headline"],
133+
condition=Q(**{f"number__{op}": 3}),
134+
)
135+
index._get_condition_mql(Article, schema_editor=editor)
136+
target = {"number": {mongo_operator: 3}}
137+
self.assertEqual(
138+
target,
139+
index._get_condition_mql(Article, schema_editor=editor),
140+
)
141+
editor.add_index(index=index, model=Article)
142+
with connection.cursor() as cursor:
143+
self.assertIn(
144+
index.name,
145+
connection.introspection.get_constraints(
146+
cursor=cursor,
147+
table_name=Article._meta.db_table,
148+
),
149+
)
150+
editor.remove_index(index=index, model=Article)

0 commit comments

Comments
 (0)