Skip to content

Commit f5c34a2

Browse files
committed
Refactor management command tests
1 parent 2f23b79 commit f5c34a2

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

tests/encryption_/test_base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ def test_get_encrypted_fields_map(self):
115115
},
116116
]
117117
}
118-
self.maxDiff = None
119118
connection = connections["encrypted"]
120119
auto_encryption_opts = getattr(connection.connection._options, "auto_encryption_opts", None)
121120
with connection.schema_editor() as editor:
@@ -131,11 +130,6 @@ def test_get_encrypted_fields_map(self):
131130
expected_encrypted_fields_map,
132131
)
133132

134-
def test_set_encrypted_fields_map_in_client(self):
135-
# TODO: Create new client with and without schema map provided then
136-
# sync database to ensure encrypted collections are created in both
137-
pass
138-
139133
def test_appointment(self):
140134
self.assertEqual(Appointment.objects.get(time="8:00").time, time(8, 0))
141135

tests/encryption_/test_management.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
from .routers import TestEncryptedRouter
88

9-
EXPECTED_ENCRYPTED_FIELDS_MAP = {
10-
"encryption__patientrecord": {
9+
10+
@modify_settings(
11+
INSTALLED_APPS={"prepend": "django_mongodb_backend"},
12+
)
13+
@override_settings(DATABASE_ROUTERS=[TestEncryptedRouter()])
14+
class EncryptedFieldsManagementCommandTests(TransactionTestCase):
15+
databases = {"default", "encrypted"}
16+
available_apps = ["django_mongodb_backend", "encryption_"]
17+
expected_patient_record = {
1118
"fields": [
1219
{
1320
"bsonType": "string",
@@ -35,19 +42,9 @@
3542
"queries": {"queryType": "range"},
3643
},
3744
]
38-
},
39-
}
40-
45+
}
4146

42-
@modify_settings(
43-
INSTALLED_APPS={"prepend": "django_mongodb_backend"},
44-
)
45-
@override_settings(DATABASE_ROUTERS=[TestEncryptedRouter()])
46-
class EncryptedFieldsManagementCommandTests(TransactionTestCase):
47-
databases = {"default", "encrypted"}
48-
available_apps = ["django_mongodb_backend", "encryption_"]
49-
50-
def _compare_json(self, json1, json2):
47+
def _compare_output(self, json1, json2):
5148
# Remove keyIds since they are different for each run.
5249
for field in json2["fields"]:
5350
del field["keyId"]
@@ -63,10 +60,10 @@ def test_show_encrypted_fields_map(self):
6360
verbosity=0,
6461
stdout=out,
6562
)
66-
output_json = json_util.loads(out.getvalue())
67-
self._compare_json(
68-
EXPECTED_ENCRYPTED_FIELDS_MAP["encryption__patientrecord"],
69-
output_json["encryption__patientrecord"],
63+
command_output = json_util.loads(out.getvalue())
64+
self._compare_output(
65+
self.expected_patient_record,
66+
command_output["encryption__patientrecord"],
7067
)
7168

7269
def test_create_new_keys(self):
@@ -80,8 +77,11 @@ def test_create_new_keys(self):
8077
verbosity=0,
8178
stdout=out,
8279
)
83-
output_json = json_util.loads(out.getvalue())
84-
self._compare_json(
85-
EXPECTED_ENCRYPTED_FIELDS_MAP["encryption__patientrecord"],
86-
output_json["encryption__patientrecord"],
80+
command_output = json_util.loads(out.getvalue())
81+
self._compare_output(
82+
self.expected_patient_record,
83+
command_output["encryption__patientrecord"],
8784
)
85+
86+
# TODO: Create a new connection to verify that the keys can be used
87+
# in a client-side configuration to migrate the encrypted fields.

0 commit comments

Comments
 (0)