@@ -185,18 +185,12 @@ def test_another_staff_member_no_day_off(self):
185
185
self .assertFalse (check_day_off_for_staff (self .staff_member2 , "2023-10-06" ))
186
186
187
187
188
- class TestCreateAndSaveAppointment (BaseTest ):
189
-
188
+ class TestCreateAndSaveAppointment (BaseTest , TestCase ):
190
189
def setUp (self ):
191
- super ().setUp () # Call the parent class setup
192
- # Specific setups for this test class
193
- self .ar = self .create_appt_request_for_sm1 ()
190
+ super ().setUp ()
194
191
self .factory = RequestFactory ()
195
192
self .request = self .factory .get ('/' )
196
-
197
- def tearDown (self ):
198
- Appointment .objects .all ().delete ()
199
- AppointmentRequest .objects .all ().delete ()
193
+ self .ar = self .create_appt_request_for_sm1 ()
200
194
201
195
def test_create_and_save_appointment (self ):
202
196
client_data = {
@@ -210,7 +204,8 @@ def test_create_and_save_appointment(self):
210
204
'additional_info' : 'Please bring a Zat gun.'
211
205
}
212
206
213
- appointment = create_and_save_appointment (self .ar , client_data , appointment_data , self .request )
207
+ with patch ('appointment.utils.db_helpers.schedule_email_reminder' ) as mock_schedule_reminder :
208
+ appointment = create_and_save_appointment (self .ar , client_data , appointment_data , self .request )
214
209
215
210
self .assertIsNotNone (appointment )
216
211
self .assertEqual (appointment .client .email , client_data ['email' ])
@@ -219,6 +214,32 @@ def test_create_and_save_appointment(self):
219
214
self .assertEqual (appointment .address , appointment_data ['address' ])
220
215
self .assertEqual (appointment .additional_info , appointment_data ['additional_info' ])
221
216
217
+ if DJANGO_Q_AVAILABLE :
218
+ mock_schedule_reminder .assert_called_once ()
219
+ else :
220
+ mock_schedule_reminder .assert_not_called ()
221
+
222
+ @patch ('appointment.utils.db_helpers.DJANGO_Q_AVAILABLE' , False )
223
+ def test_create_and_save_appointment_without_django_q (self ):
224
+ client_data = {
225
+
226
+ 'name' : 'samantha.carter' ,
227
+ }
228
+ appointment_data = {
229
+ 'phone' : '987654321' ,
230
+ 'want_reminder' : True ,
231
+ 'address' : '456, SGC, Colorado Springs, USA' ,
232
+ 'additional_info' : 'Bring naquadah generator.'
233
+ }
234
+
235
+ with patch ('appointment.utils.db_helpers.logger.warning' ) as mock_logger_warning :
236
+ appointment = create_and_save_appointment (self .ar , client_data , appointment_data , self .request )
237
+
238
+ self .assertIsNotNone (appointment )
239
+ self .assertEqual (appointment .client .email , client_data ['email' ])
240
+ mock_logger_warning .assert_called_with (
241
+ f"Email reminder requested for appointment { appointment .id } , but django-q is not available." )
242
+
222
243
223
244
def get_mock_reverse (url_name , ** kwargs ):
224
245
"""A mocked version of the reverse function."""
0 commit comments