1
1
import datetime
2
2
from decimal import Decimal
3
3
4
- import pymongo
5
- from bson .binary import Binary
6
- from django .conf import settings
7
- from django .db import connections
8
-
9
4
from django_mongodb_backend .fields import EncryptedCharField
10
5
11
6
from .models import (
36
31
)
37
32
from .test_base import EncryptionTestCase
38
33
39
-
40
- class EncryptedFieldTests ( EncryptionTestCase ):
41
- def assertEncrypted ( self , model , field ):
42
- # Unencrypted connection to encrypted database
43
- conn_params = connections [ "default" ]. get_connection_params ()
44
- db_name = settings . DATABASES [ "encrypted" ][ "NAME" ]
45
- with pymongo . MongoClient ( ** conn_params ) as new_connection :
46
- db = new_connection [ db_name ]
47
- collection_name = model . _meta . db_table
48
- data = db [ collection_name ]. find ()[ 0 ]
49
- self . assertIsInstance ( data [ field ], Binary )
34
+ # class EncryptedFieldTests(EncryptionTestCase):
35
+ # def assertEncrypted(self, model, field ):
36
+ # # Unencrypted connection to encrypted database
37
+ # conn_params = connections["default"].get_connection_params()
38
+ # db_name = settings.DATABASES["encrypted"]["NAME"]
39
+ # with pymongo.MongoClient(**conn_params) as new_connection:
40
+ # db = new_connection[db_name]
41
+ # collection_name = model._meta.db_table
42
+ # data = db[collection_name].find()[0]
43
+ # self.assertIsInstance(data[field], Binary)
44
+ #
50
45
51
46
52
- class EncryptedEmbeddedModelTests (EncryptedFieldTests ):
47
+ class EncryptedEmbeddedModelTests (EncryptionTestCase ):
53
48
def setUp (self ):
54
49
self .billing = Billing (cc_type = "Visa" , cc_number = "4111111111111111" )
55
50
self .patient_record = PatientRecord (ssn = "123-45-6789" , billing = self .billing )
@@ -65,7 +60,7 @@ def test_object(self):
65
60
# self.assertEncrypted(patient, ["patient_record", "ssn"])
66
61
67
62
68
- class EncryptedEmbeddedModelArrayTests (EncryptedFieldTests ):
63
+ class EncryptedEmbeddedModelArrayTests (EncryptionTestCase ):
69
64
def setUp (self ):
70
65
self .actor1 = Actor (name = "Actor One" )
71
66
self .actor2 = Actor (name = "Actor Two" )
@@ -81,7 +76,7 @@ def test_array(self):
81
76
# self.assertEncrypted(self.movie, "cast")
82
77
83
78
84
- class EncryptedFieldTests ( EncryptedFieldTests ):
79
+ class EncryptionTestCase ( EncryptionTestCase ):
85
80
def assertEquality (self , model_cls , val ):
86
81
model_cls .objects .create (value = val )
87
82
fetched = model_cls .objects .get (value = val )
@@ -200,7 +195,7 @@ def test_time(self):
200
195
# self.assertEncrypted(TimeModel, "value")
201
196
202
197
203
- class EncryptedFieldMixinTests (EncryptedFieldTests ):
198
+ class EncryptedFieldMixinTests (EncryptionTestCase ):
204
199
def test_null_true_raises_error (self ):
205
200
with self .assertRaisesMessage (
206
201
ValueError , "'null=True' is not supported for encrypted fields."
0 commit comments