

def test_ok(self):
    self.assertEqual(self.handler.get_reminder(self.case), None)
    CaseReminderHandler.now = datetime(year=2011, month=12, day=31, hour=23, minute=0)
    set_case_property_directly(self.case, 'start_sending', 'ok')
    self.case.save()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=1, hour=7, minute=0))
    self.assertEqual(reminder.start_date, date(year=2012, month=1, day=1))
    self.assertEqual(reminder.schedule_iteration_num, 1)
    self.assertEqual(reminder.current_event_sequence_num, 0)
    self.assertEqual(reminder.last_fired, None)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=1, hour=7, minute=0)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=1, hour=8, minute=0))
    self.assertEqual(reminder.schedule_iteration_num, 1)
    self.assertEqual(reminder.current_event_sequence_num, 1)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=1, hour=8, minute=1)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=1, hour=8, minute=15))
    self.assertEqual(reminder.schedule_iteration_num, 1)
    self.assertEqual(reminder.current_event_sequence_num, 1)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    event = self.get_expected_callback(datetime(2012, 1, 1, 8, 1), self.user_id)
    self.assertNotEqual(event, None)
    self.assertEqual(event.status, CALLBACK_PENDING)
    Call.objects.create(couch_recipient_doc_type='CommCareUser', couch_recipient=self.user_id, phone_number='14445551234', direction='I', date=datetime(year=2012, month=1, day=1, hour=8, minute=5))
    CaseReminderHandler.now = datetime(year=2012, month=1, day=1, hour=8, minute=15)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=1, hour=8, minute=45))
    self.assertEqual(reminder.schedule_iteration_num, 1)
    self.assertEqual(reminder.current_event_sequence_num, 1)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=1, hour=8, minute=45)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=2, hour=7, minute=0))
    self.assertEqual(reminder.schedule_iteration_num, 2)
    self.assertEqual(reminder.current_event_sequence_num, 0)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    event = self.get_expected_callback(datetime(2012, 1, 1, 8, 1), self.user_id)
    self.assertNotEqual(event, None)
    self.assertEqual(event.status, CALLBACK_RECEIVED)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=2, hour=7, minute=0)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=2, hour=8, minute=0))
    self.assertEqual(reminder.schedule_iteration_num, 2)
    self.assertEqual(reminder.current_event_sequence_num, 1)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=2, hour=8, minute=1)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=2, hour=8, minute=15))
    self.assertEqual(reminder.schedule_iteration_num, 2)
    self.assertEqual(reminder.current_event_sequence_num, 1)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    event = self.get_expected_callback(datetime(2012, 1, 2, 8, 1), self.user_id)
    self.assertNotEqual(event, None)
    self.assertEqual(event.status, CALLBACK_PENDING)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=2, hour=8, minute=15)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=2, hour=8, minute=45))
    self.assertEqual(reminder.schedule_iteration_num, 2)
    self.assertEqual(reminder.current_event_sequence_num, 1)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    event = self.get_expected_callback(datetime(2012, 1, 2, 8, 1), self.user_id)
    self.assertNotEqual(event, None)
    self.assertEqual(event.status, CALLBACK_PENDING)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=2, hour=8, minute=45)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=3, hour=7, minute=0))
    self.assertEqual(reminder.schedule_iteration_num, 3)
    self.assertEqual(reminder.current_event_sequence_num, 0)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    event = self.get_expected_callback(datetime(2012, 1, 2, 8, 1), self.user_id)
    self.assertNotEqual(event, None)
    self.assertEqual(event.status, CALLBACK_MISSED)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=3, hour=7, minute=0)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=3, hour=8, minute=0))
    self.assertEqual(reminder.schedule_iteration_num, 3)
    self.assertEqual(reminder.current_event_sequence_num, 1)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=3, hour=8, minute=1)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=3, hour=8, minute=15))
    self.assertEqual(reminder.schedule_iteration_num, 3)
    self.assertEqual(reminder.current_event_sequence_num, 1)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    event = self.get_expected_callback(datetime(2012, 1, 3, 8, 1), self.user_id)
    self.assertNotEqual(event, None)
    self.assertEqual(event.status, CALLBACK_PENDING)
    CaseReminderHandler.now = datetime(year=2012, month=1, day=3, hour=8, minute=15)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=3, hour=8, minute=45))
    self.assertEqual(reminder.schedule_iteration_num, 3)
    self.assertEqual(reminder.current_event_sequence_num, 1)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    event = self.get_expected_callback(datetime(2012, 1, 3, 8, 1), self.user_id)
    self.assertNotEqual(event, None)
    self.assertEqual(event.status, CALLBACK_PENDING)
    Call.objects.create(couch_recipient_doc_type='CommCareUser', couch_recipient=self.user_id, phone_number='4445551234', direction='I', date=datetime(year=2012, month=1, day=3, hour=8, minute=22))
    CaseReminderHandler.now = datetime(year=2012, month=1, day=3, hour=8, minute=45)
    CaseReminderHandler.fire_reminders()
    reminder = self.handler.get_reminder(self.case)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.schedule_iteration_num, 4)
    self.assertEqual(reminder.current_event_sequence_num, 0)
    self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
    self.assertEqual(reminder.active, False)
    event = self.get_expected_callback(datetime(2012, 1, 3, 8, 1), self.user_id)
    self.assertNotEqual(event, None)
    self.assertEqual(event.status, CALLBACK_RECEIVED)

dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/reminders/tests/__init__.py ReminderCallbackTestCase.test_ok/original