Skip to content

Commit 901db6f

Browse files
committed
Code review fixes
1 parent 416adff commit 901db6f

File tree

2 files changed

+12
-76
lines changed

2 files changed

+12
-76
lines changed

tests/encryption_/test_base.py

Lines changed: 2 additions & 5 deletions
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, models
7-
from django.test import TransactionTestCase, modify_settings, override_settings
7+
from django.test import TransactionTestCase, override_settings
88

99
from django_mongodb_backend.fields import EncryptedFieldMixin
1010

@@ -33,13 +33,10 @@ class EncryptedSlugField(EncryptedFieldMixin, models.SlugField):
3333
"""
3434

3535

36-
@modify_settings(
37-
INSTALLED_APPS={"prepend": "django_mongodb_backend"},
38-
)
3936
@override_settings(DATABASE_ROUTERS=[TestEncryptedRouter()])
4037
class EncryptedFieldTests(TransactionTestCase):
4138
databases = {"default", "encrypted"}
42-
available_apps = ["django_mongodb_backend", "encryption_"]
39+
available_apps = ["encryption_"]
4340

4441
def setUp(self):
4542
self.appointment = Appointment.objects.create(time="8:00")

tests/encryption_/test_management.py

Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,6 @@
77
from .routers import TestEncryptedRouter
88

99
EXPECTED_ENCRYPTED_FIELDS_MAP = {
10-
"encryption__billing": {
11-
"fields": [
12-
{
13-
"bsonType": "string",
14-
"path": "cc_type",
15-
"queries": {"queryType": "equality"},
16-
},
17-
{
18-
"bsonType": "long",
19-
"path": "cc_number",
20-
"queries": {"queryType": "equality"},
21-
},
22-
{
23-
"bsonType": "decimal",
24-
"path": "account_balance",
25-
"queries": {"queryType": "range"},
26-
},
27-
]
28-
},
2910
"encryption__patientrecord": {
3011
"fields": [
3112
{
@@ -55,51 +36,6 @@
5536
},
5637
]
5738
},
58-
"encryption__patient": {
59-
"fields": [
60-
{
61-
"bsonType": "int",
62-
"path": "patient_id",
63-
"queries": {"queryType": "equality"},
64-
},
65-
{
66-
"bsonType": "string",
67-
"path": "patient_name",
68-
},
69-
{
70-
"bsonType": "string",
71-
"path": "patient_notes",
72-
"queries": {"queryType": "equality"},
73-
},
74-
{
75-
"bsonType": "date",
76-
"path": "registration_date",
77-
"queries": {"queryType": "equality"},
78-
},
79-
{
80-
"bsonType": "bool",
81-
"path": "is_active",
82-
"queries": {"queryType": "equality"},
83-
},
84-
{"bsonType": "string", "path": "email", "queries": {"queryType": "equality"}},
85-
]
86-
},
87-
"encryption__patientportaluser": {
88-
"fields": [
89-
{"bsonType": "string", "path": "ip_address", "queries": {"queryType": "equality"}},
90-
{"bsonType": "string", "path": "url", "queries": {"queryType": "equality"}},
91-
]
92-
},
93-
"encryption__encryptednumbers": {
94-
"fields": [
95-
{"bsonType": "int", "path": "pos_bigint", "queries": {"queryType": "equality"}},
96-
{"bsonType": "int", "path": "pos_smallint", "queries": {"queryType": "equality"}},
97-
{"bsonType": "int", "path": "smallint", "queries": {"queryType": "equality"}},
98-
]
99-
},
100-
"encryption__appointment": {
101-
"fields": [{"bsonType": "date", "path": "time", "queries": {"queryType": "equality"}}]
102-
},
10339
}
10440

10541

@@ -113,11 +49,8 @@ class EncryptedFieldsManagementCommandTests(TransactionTestCase):
11349

11450
def _compare_json(self, json1, json2):
11551
# Remove keyIds since they are different for each run.
116-
for table in json2:
117-
for field in json2[table]["fields"]:
118-
del field["keyId"]
119-
# TODO: probably we don't need to test the entire mapping, otherwise it
120-
# requires updates every time a new model or field is added!
52+
for field in json2["fields"]:
53+
del field["keyId"]
12154
self.assertEqual(json1, json2)
12255

12356
def test_show_encrypted_fields_map(self):
@@ -131,7 +64,10 @@ def test_show_encrypted_fields_map(self):
13164
stdout=out,
13265
)
13366
output_json = json_util.loads(out.getvalue())
134-
self._compare_json(EXPECTED_ENCRYPTED_FIELDS_MAP, output_json)
67+
self._compare_json(
68+
EXPECTED_ENCRYPTED_FIELDS_MAP["encryption__patientrecord"],
69+
output_json["encryption__patientrecord"],
70+
)
13571

13672
def test_create_encrypted_fields_map(self):
13773
self.maxDiff = None
@@ -145,4 +81,7 @@ def test_create_encrypted_fields_map(self):
14581
stdout=out,
14682
)
14783
output_json = json_util.loads(out.getvalue())
148-
self._compare_json(EXPECTED_ENCRYPTED_FIELDS_MAP, output_json)
84+
self._compare_json(
85+
EXPECTED_ENCRYPTED_FIELDS_MAP["encryption__patientrecord"],
86+
output_json["encryption__patientrecord"],
87+
)

0 commit comments

Comments
 (0)