6
6
7
7
from .routers import TestEncryptedRouter
8
8
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 = {
11
18
"fields" : [
12
19
{
13
20
"bsonType" : "string" ,
35
42
"queries" : {"queryType" : "range" },
36
43
},
37
44
]
38
- },
39
- }
40
-
45
+ }
41
46
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 ):
51
48
# Remove keyIds since they are different for each run.
52
49
for field in json2 ["fields" ]:
53
50
del field ["keyId" ]
@@ -63,10 +60,10 @@ def test_show_encrypted_fields_map(self):
63
60
verbosity = 0 ,
64
61
stdout = out ,
65
62
)
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" ],
70
67
)
71
68
72
69
def test_create_new_keys (self ):
@@ -80,8 +77,11 @@ def test_create_new_keys(self):
80
77
verbosity = 0 ,
81
78
stdout = out ,
82
79
)
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" ],
87
84
)
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