1
- from datetime import date , datetime , time
1
+ from datetime import date , datetime , time , timedelta
2
2
3
3
import pymongo
4
4
from bson .binary import Binary
@@ -20,31 +20,47 @@ class FieldTests(QueryableEncryptionTestCase):
20
20
def setUp (self ):
21
21
Patient .objects .create (
22
22
patient_id = 1 ,
23
- patient_name = "John Doe" ,
24
- patient_notes = "patient notes " * 25 ,
23
+ full_name = "John Doe" ,
24
+ notes = "patient notes " * 25 ,
25
25
registration_date = datetime (2023 , 10 , 1 , 12 , 0 , 0 ),
26
26
is_active = True ,
27
-
27
+ contact_email = "[email protected] " ,
28
28
)
29
29
PatientRecord .objects .create (
30
30
ssn = "123-45-6789" ,
31
31
birth_date = "1969-01-01" ,
32
- profile_picture = b"image data" ,
33
- patient_age = 50 ,
32
+ profile_picture_data = b"image data" ,
33
+ age = 50 ,
34
34
weight = 180.0 ,
35
+ insurance_policy_number = 98765432101234 ,
36
+ emergency_contacts_count = 2 ,
37
+ completed_visits = 3 ,
38
+ )
39
+ Billing .objects .create (
40
+ account_balance = 100.50 ,
41
+ payment_duration = timedelta (days = 30 ),
42
+ )
43
+ CreditCard .objects .create (
44
+ card_type = "Visa" ,
45
+ card_number = 1234567890123456 ,
46
+ transaction_reference = 98765432101234 ,
47
+ )
48
+ Appointment .objects .create (start_time = "8:00" )
49
+ PatientPortalUser .objects .create (
50
+ last_login_ip = "127.0.0.1" , profile_url = "https://example.com"
35
51
)
36
52
37
53
def test_binaryfield (self ):
38
54
self .assertEqual (
39
- PatientRecord .objects .get (profile_picture = b"image data" ).profile_picture , b"image data"
55
+ PatientRecord .objects .get (profile_picture_data = b"image data" ).profile_picture_data ,
56
+ b"image data" ,
40
57
)
41
58
42
59
def test_booleanfield (self ):
43
60
self .assertTrue (Patient .objects .get (patient_id = 1 ).is_active )
44
61
45
62
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" )
63
+ self .assertEqual (CreditCard .objects .get (card_type = "Visa" ).card_type , "Visa" )
48
64
self .assertEqual (PatientRecord .objects .get (ssn = "123-45-6789" ).ssn , "123-45-6789" )
49
65
50
66
def test_datefield (self ):
@@ -61,36 +77,67 @@ def test_datetimefield(self):
61
77
)
62
78
63
79
def test_decimalfield (self ):
64
- Billing .objects .create (account_balance = 100.50 )
65
80
self .assertTrue (Billing .objects .filter (account_balance__gte = 100.0 ).exists ())
66
81
82
+ def test_durationfield (self ):
83
+ self .assertTrue (Billing .objects .filter (payment_duration__gte = timedelta (days = 15 )).exists ())
84
+
67
85
def test_emailfield (self ):
68
86
self .assertEqual (
69
- Patient .
objects .
get (
email = "[email protected] " ).
email ,
"[email protected] "
87
+ Patient .
objects .
get (
contact_email = "[email protected] " ).
contact_email ,
88
+
70
89
)
71
90
72
91
def test_floatfield (self ):
73
92
self .assertTrue (PatientRecord .objects .filter (weight__gte = 175.0 ).exists ())
74
93
75
94
def test_integerfield (self ):
76
- CreditCard .objects .create (cc_type = "Visa" , cc_number = "1234567890123456" )
77
95
self .assertEqual (
78
- CreditCard .objects .get (cc_number = 1234567890123456 ).cc_number , 1234567890123456
96
+ CreditCard .objects .get (card_number = 1234567890123456 ).card_number , 1234567890123456
97
+ )
98
+ self .assertEqual (
99
+ PatientRecord .objects .get (emergency_contacts_count = 2 ).emergency_contacts_count , 2
100
+ )
101
+
102
+ def test_positive_bigintegerfield (self ):
103
+ self .assertEqual (
104
+ PatientRecord .objects .get (
105
+ insurance_policy_number = 98765432101234
106
+ ).insurance_policy_number ,
107
+ 98765432101234 ,
108
+ )
109
+
110
+ def test_positive_integerfield (self ):
111
+ self .assertEqual (
112
+ PatientRecord .objects .get (emergency_contacts_count = 2 ).emergency_contacts_count , 2
113
+ )
114
+
115
+ def test_positive_smallintegerfield (self ):
116
+ self .assertEqual (PatientRecord .objects .get (completed_visits = 3 ).completed_visits , 3 )
117
+
118
+ def test_bigintegerfield (self ):
119
+ self .assertEqual (
120
+ CreditCard .objects .get (transaction_reference = 98765432101234 ).transaction_reference ,
121
+ 98765432101234 ,
79
122
)
80
123
81
124
def test_ipaddressfield (self ):
82
- PatientPortalUser .objects .create (ip_address = "127.0.0.1" , url = "https://example.com" )
83
125
self .assertEqual (
84
- PatientPortalUser .objects .get (ip_address = "127.0.0.1" ).ip_address , "127.0.0.1"
126
+ PatientPortalUser .objects .get (last_login_ip = "127.0.0.1" ).last_login_ip , "127.0.0.1"
85
127
)
86
128
87
129
def test_smallintegerfield (self ):
88
- self .assertTrue (PatientRecord .objects .filter (patient_age__gte = 40 ).exists ())
89
- self .assertFalse (PatientRecord .objects .filter (patient_age__gte = 80 ).exists ())
130
+ self .assertTrue (PatientRecord .objects .filter (age__gte = 40 ).exists ())
131
+ self .assertFalse (PatientRecord .objects .filter (age__gte = 80 ).exists ())
132
+
133
+ def test_textfield (self ):
134
+ self .assertEqual (
135
+ Patient .objects .get (notes = "patient notes " * 25 ).notes ,
136
+ "patient notes " * 25 ,
137
+ )
90
138
91
139
def test_timefield (self ):
92
- Appointment .objects .create (time = "8:00" )
93
- self .assertEqual (Appointment .objects .get (time = "8:00" ).time , time (8 , 0 ))
140
+ self .assertEqual (Appointment .objects .get (start_time = "8:00" ).start_time , time (8 , 0 ))
94
141
95
142
def test_encrypted_patient_record_in_encrypted_database (self ):
96
143
patients = connections ["encrypted" ].database .encryption__patient .find ()
@@ -102,16 +149,7 @@ def test_encrypted_patient_record_in_unencrypted_database(self):
102
149
conn_params = connections ["encrypted" ].get_connection_params ()
103
150
db_name = settings .DATABASES ["encrypted" ]["NAME" ]
104
151
if conn_params .pop ("auto_encryption_opts" , False ):
105
- # Call MongoClient instead of get_new_connection because
106
- # get_new_connection will return the encrypted connection
107
- # from the connection pool.
108
152
with pymongo .MongoClient (** conn_params ) as new_connection :
109
153
patientrecords = new_connection [db_name ].encryption__patientrecord .find ()
110
154
ssn = patientrecords [0 ]["ssn" ]
111
155
self .assertTrue (isinstance (ssn , Binary ))
112
-
113
- def test_textfield (self ):
114
- self .assertEqual (
115
- Patient .objects .get (patient_notes = "patient notes " * 25 ).patient_notes ,
116
- "patient notes " * 25 ,
117
- )
0 commit comments