Skip to content

Commit a6aa8da

Browse files
committed
Code review fixes (7/7)
1 parent 6afce5a commit a6aa8da

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

tests/encryption_/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class PatientRecord(models.Model):
5252
ssn = EncryptedCharField(max_length=11, queries=EQUALITY_QUERY)
5353
birth_date = EncryptedDateField(queries=RANGE_QUERY)
5454
profile_picture = EncryptedBinaryField(queries=EQUALITY_QUERY)
55-
patient_age = EncryptedIntegerField(
55+
patient_age = EncryptedSmallIntegerField(
5656
"patient_age", queries={**RANGE_QUERY, "min": 0, "max": 100}
5757
)
5858
weight = EncryptedFloatField(queries=RANGE_QUERY)

tests/encryption_/test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22

3-
from django.test import TransactionTestCase, override_settings
3+
from django.test import TransactionTestCase, override_settings, skipUnlessDBFeature
44

55
from .models import (
66
Appointment,
@@ -12,6 +12,7 @@
1212
from .routers import TestEncryptedRouter
1313

1414

15+
@skipUnlessDBFeature("supports_queryable_encryption")
1516
@override_settings(DATABASE_ROUTERS=[TestEncryptedRouter()])
1617
class QueryableEncryptionTestCase(TransactionTestCase):
1718
databases = {"default", "encrypted"}

tests/encryption_/test_fields.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from bson.binary import Binary
55
from django.conf import settings
66
from django.db import connections
7-
from django.test import override_settings
7+
from django.test import override_settings, skipUnlessDBFeature
88

99
from .models import (
1010
Appointment,
@@ -18,6 +18,7 @@
1818
from .test_base import QueryableEncryptionTestCase
1919

2020

21+
@skipUnlessDBFeature("supports_queryable_encryption")
2122
@override_settings(DATABASE_ROUTERS=[TestEncryptedRouter()])
2223
class QueryableEncryptionFieldTests(QueryableEncryptionTestCase):
2324
databases = {"default", "encrypted"}

tests/encryption_/test_management.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
from bson import json_util
66
from django.core.management import call_command
77
from django.db import connections
8-
from django.test import modify_settings, override_settings
8+
from django.test import modify_settings, override_settings, skipUnlessDBFeature
99
from pymongo.encryption import AutoEncryptionOpts
1010

1111
from .routers import TestEncryptedRouter
1212
from .test_base import QueryableEncryptionTestCase
1313

1414

15+
@skipUnlessDBFeature("supports_queryable_encryption")
1516
@modify_settings(
1617
INSTALLED_APPS={"prepend": "django_mongodb_backend"},
1718
)
@@ -82,6 +83,13 @@ def test_create_new_keys(self):
8283
stdout=out,
8384
)
8485
command_output = json_util.loads(out.getvalue())
86+
87+
# TODO: Until the todo below is fixed, you can test this feature
88+
# manually by uncommenting the following line and pasting the output
89+
# into your client-side `encrypted_fields_map` configuration. You also
90+
# need to temporarily configure server-side encryption for this to
91+
# procedure to work.
92+
# print(command_output).
8593
self._compare_output(
8694
self.expected_patient_record,
8795
command_output["encryption__patientrecord"],

tests/encryption_/test_schema.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from django.db import connections
2-
from django.test import override_settings
2+
from django.test import override_settings, skipUnlessDBFeature
33

44
from .routers import TestEncryptedRouter
55
from .test_base import QueryableEncryptionTestCase
66

77

8+
@skipUnlessDBFeature("supports_queryable_encryption")
89
@override_settings(DATABASE_ROUTERS=[TestEncryptedRouter()])
910
class QueryableEncryptionSchemaTests(QueryableEncryptionTestCase):
1011
databases = {"default", "encrypted"}
1112
available_apps = ["encryption_"]
13+
maxDiff = None
1214

1315
def test_get_encrypted_fields_map(self):
1416
"""
@@ -24,7 +26,7 @@ def test_get_encrypted_fields_map(self):
2426
expected_encrypted_fields_map = {
2527
"fields": [
2628
{
27-
"bsonType": "int",
29+
"bsonType": "long",
2830
"path": "patient_id",
2931
"queries": {"queryType": "equality"},
3032
},

0 commit comments

Comments
 (0)