1- from datetime import date , datetime , time
1+ from datetime import date , datetime , time , timedelta
22
33import pymongo
44from bson .binary import Binary
@@ -20,31 +20,47 @@ class FieldTests(QueryableEncryptionTestCase):
2020 def setUp (self ):
2121 Patient .objects .create (
2222 patient_id = 1 ,
23- patient_name = "John Doe" ,
24- patient_notes = "patient notes " * 25 ,
23+ full_name = "John Doe" ,
24+ notes = "patient notes " * 25 ,
2525 registration_date = datetime (2023 , 10 , 1 , 12 , 0 , 0 ),
2626 is_active = True ,
27- email = "john.doe@example.com" ,
27+ contact_email = "john.doe@example.com" ,
2828 )
2929 PatientRecord .objects .create (
3030 ssn = "123-45-6789" ,
3131 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 ,
3434 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"
3551 )
3652
3753 def test_binaryfield (self ):
3854 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" ,
4057 )
4158
4259 def test_booleanfield (self ):
4360 self .assertTrue (Patient .objects .get (patient_id = 1 ).is_active )
4461
4562 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" )
4864 self .assertEqual (PatientRecord .objects .get (ssn = "123-45-6789" ).ssn , "123-45-6789" )
4965
5066 def test_datefield (self ):
@@ -61,36 +77,67 @@ def test_datetimefield(self):
6177 )
6278
6379 def test_decimalfield (self ):
64- Billing .objects .create (account_balance = 100.50 )
6580 self .assertTrue (Billing .objects .filter (account_balance__gte = 100.0 ).exists ())
6681
82+ def test_durationfield (self ):
83+ self .assertTrue (Billing .objects .filter (payment_duration__gte = timedelta (days = 15 )).exists ())
84+
6785 def test_emailfield (self ):
6886 self .assertEqual (
69- Patient .objects .get (email = "john.doe@example.com" ).email , "john.doe@example.com"
87+ Patient .objects .get (contact_email = "john.doe@example.com" ).contact_email ,
88+ "john.doe@example.com" ,
7089 )
7190
7291 def test_floatfield (self ):
7392 self .assertTrue (PatientRecord .objects .filter (weight__gte = 175.0 ).exists ())
7493
7594 def test_integerfield (self ):
76- CreditCard .objects .create (cc_type = "Visa" , cc_number = "1234567890123456" )
7795 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 ,
79122 )
80123
81124 def test_ipaddressfield (self ):
82- PatientPortalUser .objects .create (ip_address = "127.0.0.1" , url = "https://example.com" )
83125 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"
85127 )
86128
87129 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+ )
90138
91139 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 ))
94141
95142 def test_encrypted_patient_record_in_encrypted_database (self ):
96143 patients = connections ["encrypted" ].database .encryption__patient .find ()
@@ -102,16 +149,7 @@ def test_encrypted_patient_record_in_unencrypted_database(self):
102149 conn_params = connections ["encrypted" ].get_connection_params ()
103150 db_name = settings .DATABASES ["encrypted" ]["NAME" ]
104151 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.
108152 with pymongo .MongoClient (** conn_params ) as new_connection :
109153 patientrecords = new_connection [db_name ].encryption__patientrecord .find ()
110154 ssn = patientrecords [0 ]["ssn" ]
111155 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