@@ -45,20 +45,82 @@ def mocked_command(command):
45
45
with patch ("pymongo.synchronous.database.Database.command" , wraps = mocked_command ):
46
46
self .assertIs (connection .features ._supports_transactions , False )
47
47
48
- # FIXME: On evergreen (again).
49
- # class SupportsQueryableEncryptionTests(TestCase):
50
- # def setUp(self):
51
- # # Clear the cached property.
52
- # connection.features.__dict__.pop("supports_queryable_encryption", None)
53
- #
54
- # def tearDown(self):
55
- # del connection.features.supports_queryable_encryption
56
- #
57
- # def test_supports_queryable_encryption(self):
58
- # def mocked_command(command):
59
- # if command == "buildInfo":
60
- # return {"modules": ["enterprise"]}
61
- # raise Exception("Unexpected command")
62
- #
63
- # with patch("pymongo.synchronous.database.Database.command", wraps=mocked_command):
64
- # self.assertIs(connection.features.supports_queryable_encryption, True)
48
+
49
+ class SupportsQueryableEncryptionTests (TestCase ):
50
+ def setUp (self ):
51
+ # Clear the cached property.
52
+ connection .features .__dict__ .pop ("supports_queryable_encryption" , None )
53
+ # Must initialize the feature before patching it.
54
+ connection .features ._supports_transactions # noqa: B018
55
+
56
+ def tearDown (self ):
57
+ del connection .features .supports_queryable_encryption
58
+
59
+ @staticmethod
60
+ def enterprise_response (command ):
61
+ if command == "buildInfo" :
62
+ return {"modules" : ["enterprise" ]}
63
+ raise Exception ("Unexpected command" )
64
+
65
+ @staticmethod
66
+ def non_enterprise_response (command ):
67
+ if command == "buildInfo" :
68
+ return {"modules" : []}
69
+ raise Exception ("Unexpected command" )
70
+
71
+ def test_supported_on_atlas (self ):
72
+ """Supported on MongoDB 7.0+ Atlas replica set or sharded cluster."""
73
+ with (
74
+ patch (
75
+ "pymongo.synchronous.database.Database.command" , wraps = self .non_enterprise_response
76
+ ),
77
+ patch ("django.db.connection.features.supports_atlas_search" , True ),
78
+ patch ("django.db.connection.features._supports_transactions" , True ),
79
+ patch ("django.db.connection.features.is_mongodb_7_0" , True ),
80
+ ):
81
+ self .assertIs (connection .features .supports_queryable_encryption , True )
82
+
83
+ def test_supported_on_enterprise (self ):
84
+ """Supported on MongoDB 7.0+ Enterprise replica set or sharded cluster."""
85
+ with (
86
+ patch ("pymongo.synchronous.database.Database.command" , wraps = self .enterprise_response ),
87
+ patch ("django.db.connection.features.supports_atlas_search" , False ),
88
+ patch ("django.db.connection.features._supports_transactions" , True ),
89
+ patch ("django.db.connection.features.is_mongodb_7_0" , True ),
90
+ ):
91
+ self .assertIs (connection .features .supports_queryable_encryption , True )
92
+
93
+ def test_atlas_or_enterprise_required (self ):
94
+ """Not supported on MongoDB Community Edition."""
95
+ with (
96
+ patch (
97
+ "pymongo.synchronous.database.Database.command" , wraps = self .non_enterprise_response
98
+ ),
99
+ patch ("django.db.connection.features.supports_atlas_search" , False ),
100
+ patch ("django.db.connection.features._supports_transactions" , True ),
101
+ patch ("django.db.connection.features.is_mongodb_7_0" , True ),
102
+ ):
103
+ self .assertIs (connection .features .supports_queryable_encryption , True )
104
+
105
+ def test_transactions_required (self ):
106
+ """
107
+ Not supported if database isn't a replica set or sharded cluster
108
+ (i.e. DatabaseFeatures._supports_transactions = False).
109
+ """
110
+ with (
111
+ patch ("pymongo.synchronous.database.Database.command" , wraps = self .enterprise_response ),
112
+ patch ("django.db.connection.features.supports_atlas_search" , False ),
113
+ patch ("django.db.connection.features._supports_transactions" , False ),
114
+ patch ("django.db.connection.features.is_mongodb_7_0" , True ),
115
+ ):
116
+ self .assertIs (connection .features .supports_queryable_encryption , False )
117
+
118
+ def test_mongodb_7_0_required (self ):
119
+ """Not supported on MongoDB < 7.0"""
120
+ with (
121
+ patch ("pymongo.synchronous.database.Database.command" , wraps = self .enterprise_response ),
122
+ patch ("django.db.connection.features.supports_atlas_search" , False ),
123
+ patch ("django.db.connection.features._supports_transactions" , True ),
124
+ patch ("django.db.connection.features.is_mongodb_7_0" , False ),
125
+ ):
126
+ self .assertIs (connection .features .supports_queryable_encryption , False )
0 commit comments