11import datetime
22from decimal import Decimal
33
4- import pymongo
5- from bson .binary import Binary
6- from django .conf import settings
7- from django .db import connections
8-
94from django_mongodb_backend .fields import EncryptedCharField
105
116from .models import (
3631)
3732from .test_base import EncryptionTestCase
3833
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+ #
5045
5146
52- class EncryptedEmbeddedModelTests (EncryptedFieldTests ):
47+ class EncryptedEmbeddedModelTests (EncryptionTestCase ):
5348 def setUp (self ):
5449 self .billing = Billing (cc_type = "Visa" , cc_number = "4111111111111111" )
5550 self .patient_record = PatientRecord (ssn = "123-45-6789" , billing = self .billing )
@@ -65,7 +60,7 @@ def test_object(self):
6560 # self.assertEncrypted(patient, ["patient_record", "ssn"])
6661
6762
68- class EncryptedEmbeddedModelArrayTests (EncryptedFieldTests ):
63+ class EncryptedEmbeddedModelArrayTests (EncryptionTestCase ):
6964 def setUp (self ):
7065 self .actor1 = Actor (name = "Actor One" )
7166 self .actor2 = Actor (name = "Actor Two" )
@@ -81,7 +76,7 @@ def test_array(self):
8176 # self.assertEncrypted(self.movie, "cast")
8277
8378
84- class EncryptedFieldTests ( EncryptedFieldTests ):
79+ class EncryptionTestCase ( EncryptionTestCase ):
8580 def assertEquality (self , model_cls , val ):
8681 model_cls .objects .create (value = val )
8782 fetched = model_cls .objects .get (value = val )
@@ -200,7 +195,7 @@ def test_time(self):
200195 # self.assertEncrypted(TimeModel, "value")
201196
202197
203- class EncryptedFieldMixinTests (EncryptedFieldTests ):
198+ class EncryptedFieldMixinTests (EncryptionTestCase ):
204199 def test_null_true_raises_error (self ):
205200 with self .assertRaisesMessage (
206201 ValueError , "'null=True' is not supported for encrypted fields."
0 commit comments