Skip to content

Commit 09fd8ec

Browse files
committed
Update test
1 parent a58edbc commit 09fd8ec

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

django_mongodb_backend/features.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,17 @@ def supports_atlas_search(self):
581581
@cached_property
582582
def supports_queryable_encryption(self):
583583
"""
584-
Queryable Encryption is supported if the server is Atlas or Enterprise.
584+
Queryable Encryption is supported if the server is Atlas or Enterprise
585+
and if pymongocrypt is installed.
585586
"""
586587
self.connection.ensure_connection()
587588
client = self.connection.connection.admin
588589
build_info = client.command("buildInfo")
589-
return "enterprise" in build_info.get("modules")
590+
is_enterprise = "enterprise" in build_info.get("modules")
591+
try:
592+
import pymongocrypt # noqa: F401
593+
594+
has_pymongocrypt = True
595+
except ImportError:
596+
has_pymongocrypt = False
597+
return is_enterprise and has_pymongocrypt

tests/backend_/utils/test_parse_uri.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pymongo
44
from django.core.exceptions import ImproperlyConfigured
5-
from django.test import SimpleTestCase
5+
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
66

77
from django_mongodb_backend import get_auto_encryption_options, parse_uri
88

@@ -95,5 +95,10 @@ def test_no_scheme(self):
9595
with self.assertRaisesMessage(pymongo.errors.InvalidURI, "Invalid URI scheme"):
9696
parse_uri("cluster0.example.mongodb.net")
9797

98+
99+
# TODO: This can go in `test_features` once transaction support is added.
100+
class ParseUriOptionsTests(TestCase):
101+
@skipUnlessDBFeature("supports_queryable_encryption")
98102
def test_queryable_encryption_config(self):
99-
get_auto_encryption_options()
103+
auto_encryption_options = get_auto_encryption_options()
104+
self.assertEqual(auto_encryption_options._key_vault_namespace, "encryption.__keyVault")

0 commit comments

Comments
 (0)