Skip to content

Commit 1f35400

Browse files
committed
Edits.
1 parent e28cf7e commit 1f35400

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

django_mongodb/indexes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def where_node_idx(self, compiler, connection):
3333
if self.connector == AND:
3434
operator = "$and"
3535
elif self.connector == XOR:
36-
raise NotSupportedError("Xor in indexes is not supported")
36+
raise NotSupportedError("Xor in indexes is not supported.")
3737
else:
3838
operator = "$or"
3939
if self.negated:
40-
raise NotSupportedError("Negated field in indexes is not supported")
40+
raise NotSupportedError("Negated field in indexes is not supported.")
4141
children_mql = []
4242
for child in self.children:
4343
try:

tests/indexes_/test_mql.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def test_not_supported(self):
1515
with connection.schema_editor() as editor:
1616
index = Index(
1717
name="not_supported",
18-
# This is changed
1918
fields=["headline"],
2019
condition=Q(pk__isnull=True) & Q(pk__contains="test1"),
2120
)
@@ -35,13 +34,28 @@ def test_not_supported(self):
3534
editor.remove_index(index=index, model=Article)
3635

3736
def test_raises_on_negated(self):
38-
with self.assertRaises(NotSupportedError), connection.schema_editor() as editor:
37+
with self.assertRaises(
38+
NotSupportedError
39+
) as context_manager, connection.schema_editor() as editor:
3940
Index(
4041
name="raises_on_negated",
41-
# This is changed
4242
fields=["headline"],
4343
condition=~Q(pk=True),
4444
)._get_condition_mql(Article, schema_editor=editor)
45+
self.assertEqual(
46+
context_manager.exception.args[0], "Negated field in indexes is not supported."
47+
)
48+
49+
def test_raises_on_xor(self):
50+
with self.assertRaises(
51+
NotSupportedError
52+
) as context_manager, connection.schema_editor() as editor:
53+
Index(
54+
name="raises_on_negated",
55+
fields=["headline"],
56+
condition=Q(pk=True) ^ Q(pk=False),
57+
)._get_condition_mql(Article, schema_editor=editor)
58+
self.assertEqual(context_manager.exception.args[0], "Xor in indexes is not supported.")
4559

4660
def test_composite_index(self):
4761
with connection.schema_editor() as editor:
@@ -52,10 +66,15 @@ def test_composite_index(self):
5266
condition=Q(number__gte=3) & (Q(text__gt="test1") | Q(text__in=["A", "B"])),
5367
)
5468
index._get_condition_mql(Article, schema_editor=editor)
69+
target = {
70+
"$and": [
71+
{"number": {"$gte": 3}},
72+
{"$or": [{"text": {"$gt": "test1"}}, {"text": {"$in": ["A", "B"]}}]},
73+
]
74+
}
5575
self.assertEqual(
56-
"{'$and': [{'number': {'$gte': 3}}, {'$or': [{'text': {'$gt': 'test1'}}, "
57-
"{'text': {'$in': ['A', 'B']}}]}]}",
58-
str(index._get_condition_mql(Article, schema_editor=editor)),
76+
target,
77+
index._get_condition_mql(Article, schema_editor=editor),
5978
)
6079
editor.add_index(index=index, model=Article)
6180
with connection.cursor() as cursor:

0 commit comments

Comments
 (0)