@@ -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