@@ -18,7 +18,7 @@ def test_not_supported(self):
18
18
)._get_condition_mql (Article , schema_editor = editor )
19
19
20
20
def test_negated_not_supported (self ):
21
- msg = "MongoDB does not support negated field in indexes."
21
+ msg = "MongoDB does not support the '~' operator in indexes."
22
22
with self .assertRaisesMessage (NotSupportedError , msg ), connection .schema_editor () as editor :
23
23
Index (
24
24
name = "test" ,
@@ -27,15 +27,15 @@ def test_negated_not_supported(self):
27
27
)._get_condition_mql (Article , schema_editor = editor )
28
28
29
29
def test_xor_not_supported (self ):
30
- msg = "MongoDB does not support the 'Xor' lookup in indexes."
30
+ msg = "MongoDB does not support the '^' operator lookup in indexes."
31
31
with self .assertRaisesMessage (NotSupportedError , msg ), connection .schema_editor () as editor :
32
32
Index (
33
33
name = "test" ,
34
34
fields = ["headline" ],
35
35
condition = Q (pk = True ) ^ Q (pk = False ),
36
36
)._get_condition_mql (Article , schema_editor = editor )
37
37
38
- @skipIfDBFeature ("is_mongodb_6_0 " )
38
+ @skipIfDBFeature ("supports_in_index_operator " )
39
39
def test_or_not_supported (self ):
40
40
msg = "MongoDB does not support the 'Or' lookup in indexes."
41
41
with self .assertRaisesMessage (NotSupportedError , msg ), connection .schema_editor () as editor :
@@ -45,7 +45,7 @@ def test_or_not_supported(self):
45
45
condition = Q (pk = True ) | Q (pk = False ),
46
46
)._get_condition_mql (Article , schema_editor = editor )
47
47
48
- @skipIfDBFeature ("is_mongodb_6_0 " )
48
+ @skipIfDBFeature ("supports_in_index_operator " )
49
49
def test_in_not_supported (self ):
50
50
msg = "MongoDB does not support the 'in' lookup in indexes."
51
51
with self .assertRaisesMessage (NotSupportedError , msg ), connection .schema_editor () as editor :
@@ -55,21 +55,21 @@ def test_in_not_supported(self):
55
55
condition = Q (pk__in = [True ]),
56
56
)._get_condition_mql (Article , schema_editor = editor )
57
57
58
- @skipUnlessDBFeature ("is_mongodb_6_0 " )
58
+ @skipUnlessDBFeature ("supports_in_index_operator " )
59
59
def test_composite_index (self ):
60
60
with connection .schema_editor () as editor :
61
61
index = Index (
62
62
name = "composite_proposition" ,
63
63
fields = ["headline" ],
64
- condition = Q (number__gte = 3 ) & (Q (text__gt = "test1" ) | Q (text__in = ["A" , "B" ])),
64
+ condition = Q (number__gte = 3 ) & (Q (body__gt = "test1" ) | Q (body__in = ["A" , "B" ])),
65
65
)
66
66
index ._get_condition_mql (Article , schema_editor = editor )
67
67
self .assertEqual (
68
68
index ._get_condition_mql (Article , schema_editor = editor ),
69
69
{
70
70
"$and" : [
71
71
{"number" : {"$gte" : 3 }},
72
- {"$or" : [{"text " : {"$gt" : "test1" }}, {"text " : {"$in" : ["A" , "B" ]}}]},
72
+ {"$or" : [{"body " : {"$gt" : "test1" }}, {"body " : {"$in" : ["A" , "B" ]}}]},
73
73
]
74
74
},
75
75
)
@@ -85,18 +85,23 @@ def test_composite_index(self):
85
85
editor .remove_index (index = index , model = Article )
86
86
87
87
def test_composite_op_index (self ):
88
- for op in (
89
- [operator .or_ , operator .and_ ] if connection .features .is_mongodb_6_0 else [operator .and_ ]
90
- ):
88
+ operators = (
89
+ (
90
+ (operator .or_ , "$or" ),
91
+ (operator .and_ , "$and" ),
92
+ )
93
+ if connection .features .supports_in_index_operator
94
+ else ((operator .and_ , "$and" ),)
95
+ )
96
+ for op , mongo_operator in operators :
91
97
with self .subTest (operator = op ), connection .schema_editor () as editor :
92
98
index = Index (
93
99
name = "composite_proposition" ,
94
100
fields = ["headline" ],
95
- condition = op (Q (number__gte = 3 ), Q (text__gt = "test1" )),
101
+ condition = op (Q (number__gte = 3 ), Q (body__gt = "test1" )),
96
102
)
97
103
index ._get_condition_mql (Article , schema_editor = editor )
98
- mongo_operator = "$and" if op == operator .and_ else "$or"
99
- target = {mongo_operator : [{"number" : {"$gte" : 3 }}, {"text" : {"$gt" : "test1" }}]}
104
+ target = {mongo_operator : [{"number" : {"$gte" : 3 }}, {"body" : {"$gt" : "test1" }}]}
100
105
self .assertEqual (
101
106
target ,
102
107
index ._get_condition_mql (Article , schema_editor = editor ),
0 commit comments