1
- from datetime import datetime , time
1
+ from datetime import date , datetime , time
2
2
3
3
import pymongo
4
4
from bson .binary import Binary
8
8
from .models import (
9
9
Appointment ,
10
10
Billing ,
11
- EncryptedNumbers ,
11
+ CreditCard ,
12
12
Patient ,
13
13
PatientPortalUser ,
14
14
PatientRecord ,
15
15
)
16
- from .test_base import QueryableEncryptionTests
16
+ from .test_base import QueryableEncryptionTestCase
17
17
18
18
19
- class FieldTests (QueryableEncryptionTests ):
20
- def test_appointment (self ):
21
- self .assertEqual (Appointment .objects .get (time = "8:00" ).time , time (8 , 0 ))
19
+ class FieldTests (QueryableEncryptionTestCase ):
20
+ def setUp (self ):
21
+ Patient .objects .create (
22
+ patient_id = 1 ,
23
+ patient_name = "John Doe" ,
24
+ patient_notes = "patient notes " * 25 ,
25
+ registration_date = datetime (2023 , 10 , 1 , 12 , 0 , 0 ),
26
+ is_active = True ,
27
+
28
+ )
29
+ PatientRecord .objects .create (
30
+ ssn = "123-45-6789" ,
31
+ birth_date = "1969-01-01" ,
32
+ profile_picture = b"image data" ,
33
+ patient_age = 50 ,
34
+ weight = 180.0 ,
35
+ )
36
+
37
+ def test_binaryfield (self ):
38
+ self .assertEqual (
39
+ PatientRecord .objects .get (profile_picture = b"image data" ).profile_picture , b"image data"
40
+ )
41
+
42
+ def test_booleanfield (self ):
43
+ self .assertTrue (Patient .objects .get (patient_id = 1 ).is_active )
44
+
45
+ def test_charfield (self ):
46
+ CreditCard .objects .create (cc_type = "Visa" , cc_number = "1234567890123456" )
47
+ self .assertEqual (CreditCard .objects .get (cc_type = "Visa" ).cc_type , "Visa" )
48
+ self .assertEqual (PatientRecord .objects .get (ssn = "123-45-6789" ).ssn , "123-45-6789" )
22
49
23
- def test_billing (self ):
50
+ def test_datefield (self ):
24
51
self .assertEqual (
25
- Billing .objects .get (cc_number = 1234567890123456 ). cc_number , 1234567890123456
52
+ PatientRecord .objects .get (birth_date = "1969-1-1" ). birth_date , date ( 1969 , 1 , 1 )
26
53
)
27
- self .assertEqual (Billing .objects .get (cc_type = "Visa" ).cc_type , "Visa" )
54
+
55
+ def test_datetimefield (self ):
56
+ self .assertEqual (
57
+ Patient .objects .get (
58
+ registration_date = datetime (2023 , 10 , 1 , 12 , 0 , 0 )
59
+ ).registration_date ,
60
+ datetime (2023 , 10 , 1 , 12 , 0 , 0 ),
61
+ )
62
+
63
+ def test_decimalfield (self ):
64
+ Billing .objects .create (account_balance = 100.50 )
28
65
self .assertTrue (Billing .objects .filter (account_balance__gte = 100.0 ).exists ())
29
66
30
- def test_patientportaluser (self ):
67
+ def test_emailfield (self ):
31
68
self .assertEqual (
32
- PatientPortalUser .objects .get (ip_address = "127.0.0.1 " ).ip_address , "127.0.0.1 "
69
+ Patient .
objects .
get (
email = "[email protected] ").
email ,
"[email protected] "
33
70
)
34
71
35
- def test_patientrecord (self ):
36
- self .assertEqual (PatientRecord .objects .get (ssn = "123-45-6789" ).ssn , "123-45-6789" )
37
- with self .assertRaises (PatientRecord .DoesNotExist ):
38
- PatientRecord .objects .get (ssn = "000-00-0000" )
39
- self .assertTrue (PatientRecord .objects .filter (birth_date__gte = "1969-01-01" ).exists ())
72
+ def test_floatfield (self ):
73
+ self .assertTrue (PatientRecord .objects .filter (weight__gte = 175.0 ).exists ())
74
+
75
+ def test_integerfield (self ):
76
+ CreditCard .objects .create (cc_type = "Visa" , cc_number = "1234567890123456" )
77
+ self .assertEqual (
78
+ CreditCard .objects .get (cc_number = 1234567890123456 ).cc_number , 1234567890123456
79
+ )
80
+
81
+ def test_ipaddressfield (self ):
82
+ PatientPortalUser .objects .create (ip_address = "127.0.0.1" , url = "https://example.com" )
40
83
self .assertEqual (
41
- PatientRecord .objects .get (ssn = "123-45-6789 " ).profile_picture , b"image data "
84
+ PatientPortalUser .objects .get (ip_address = "127.0.0.1 " ).ip_address , "127.0.0.1 "
42
85
)
86
+
87
+ def test_smallintegerfield (self ):
43
88
self .assertTrue (PatientRecord .objects .filter (patient_age__gte = 40 ).exists ())
44
89
self .assertFalse (PatientRecord .objects .filter (patient_age__gte = 80 ).exists ())
45
- self .assertTrue (PatientRecord .objects .filter (weight__gte = 175.0 ).exists ())
46
90
47
- # Test encrypted patient record in unencrypted database.
91
+ def test_timefield (self ):
92
+ Appointment .objects .create (time = "8:00" )
93
+ self .assertEqual (Appointment .objects .get (time = "8:00" ).time , time (8 , 0 ))
94
+
95
+ def test_encrypted_patient_record_in_encrypted_database (self ):
96
+ patients = connections ["encrypted" ].database .encryption__patient .find ()
97
+ self .assertEqual (len (list (patients )), 1 )
98
+ records = connections ["encrypted" ].database .encryption__patientrecord .find ()
99
+ self .assertTrue ("__safeContent__" in records [0 ])
100
+
101
+ def test_encrypted_patient_record_in_unencrypted_database (self ):
48
102
conn_params = connections ["encrypted" ].get_connection_params ()
49
103
db_name = settings .DATABASES ["encrypted" ]["NAME" ]
50
104
if conn_params .pop ("auto_encryption_opts" , False ):
@@ -56,32 +110,8 @@ def test_patientrecord(self):
56
110
ssn = patientrecords [0 ]["ssn" ]
57
111
self .assertTrue (isinstance (ssn , Binary ))
58
112
59
- def test_patient (self ):
113
+ def test_textfield (self ):
60
114
self .assertEqual (
61
115
Patient .objects .get (patient_notes = "patient notes " * 25 ).patient_notes ,
62
116
"patient notes " * 25 ,
63
117
)
64
- self .assertEqual (
65
- Patient .objects .get (
66
- registration_date = datetime (2023 , 10 , 1 , 12 , 0 , 0 )
67
- ).registration_date ,
68
- datetime (2023 , 10 , 1 , 12 , 0 , 0 ),
69
- )
70
- self .assertTrue (Patient .objects .get (patient_id = 1 ).is_active )
71
- self .assertEqual (
72
- Patient .
objects .
get (
email = "[email protected] " ).
email ,
"[email protected] "
73
- )
74
-
75
- # Test decrypted patient record in encrypted database.
76
- patients = connections ["encrypted" ].database .encryption__patient .find ()
77
- self .assertEqual (len (list (patients )), 1 )
78
- records = connections ["encrypted" ].database .encryption__patientrecord .find ()
79
- self .assertTrue ("__safeContent__" in records [0 ])
80
-
81
- def test_pos_small_int (self ):
82
- obj = EncryptedNumbers .objects .get (pos_smallint = 12345 )
83
- self .assertEqual (obj .pos_smallint , 12345 )
84
-
85
- def test_small_int (self ):
86
- obj = EncryptedNumbers .objects .get (smallint = - 12345 )
87
- self .assertEqual (obj .smallint , - 12345 )
0 commit comments