@@ -15,7 +15,6 @@ def test_not_supported(self):
15
15
with connection .schema_editor () as editor :
16
16
index = Index (
17
17
name = "not_supported" ,
18
- # This is changed
19
18
fields = ["headline" ],
20
19
condition = Q (pk__isnull = True ) & Q (pk__contains = "test1" ),
21
20
)
@@ -35,13 +34,28 @@ def test_not_supported(self):
35
34
editor .remove_index (index = index , model = Article )
36
35
37
36
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 :
39
40
Index (
40
41
name = "raises_on_negated" ,
41
- # This is changed
42
42
fields = ["headline" ],
43
43
condition = ~ Q (pk = True ),
44
44
)._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." )
45
59
46
60
def test_composite_index (self ):
47
61
with connection .schema_editor () as editor :
@@ -52,10 +66,15 @@ def test_composite_index(self):
52
66
condition = Q (number__gte = 3 ) & (Q (text__gt = "test1" ) | Q (text__in = ["A" , "B" ])),
53
67
)
54
68
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
+ }
55
75
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 ),
59
78
)
60
79
editor .add_index (index = index , model = Article )
61
80
with connection .cursor () as cursor :
0 commit comments