

def test_ok(self):
    CaseReminderHandler.now = datetime(year=2012, month=2, day=17, hour=12, minute=0)
    self.assertEqual(self.handler1.get_reminder(self.case1), None)
    set_case_property_directly(self.case1, 'start_sending1', 'ok')
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, (CaseReminderHandler.now + timedelta(days=self.handler1.start_offset)))
    old_reminder_id = reminder._id
    set_case_property_directly(self.case1, 'case_property1', 'abc')
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder._id, old_reminder_id)
    old_reminder_id = reminder._id
    set_case_property_directly(self.case1, 'start_sending1', None)
    self.case1.save()
    self.assertEqual(self.handler1.get_reminder(self.case1), None)
    self.assertEqual(CaseReminder.get(old_reminder_id).doc_type, 'CaseReminder-Deleted')
    start = datetime(2012, 2, 20, 9, 0, 0)
    set_case_property_directly(self.case1, 'start_sending1', start)
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, (start + timedelta(days=self.handler1.start_offset)))
    old_reminder_id = reminder._id
    start = datetime(2012, 2, 22, 10, 15, 0)
    set_case_property_directly(self.case1, 'start_sending1', start)
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, (start + timedelta(days=self.handler1.start_offset)))
    self.assertEqual(CaseReminder.get(old_reminder_id).doc_type, 'CaseReminder-Deleted')
    old_reminder_id = reminder._id
    set_case_property_directly(self.case1, 'case_property1', 'xyz')
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder._id, old_reminder_id)
    old_reminder_id = reminder._id
    set_case_property_directly(self.case1, 'start_sending1', None)
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertEqual(reminder, None)
    self.assertEqual(CaseReminder.get(old_reminder_id).doc_type, 'CaseReminder-Deleted')
    start = date(2012, 2, 20)
    set_case_property_directly(self.case1, 'start_sending1', start)
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, (datetime(start.year, start.month, start.day) + timedelta(days=self.handler1.start_offset)))
    old_reminder_id = reminder._id
    start = date(2012, 2, 22)
    set_case_property_directly(self.case1, 'start_sending1', start)
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, (datetime(start.year, start.month, start.day) + timedelta(days=self.handler1.start_offset)))
    self.assertEqual(CaseReminder.get(old_reminder_id).doc_type, 'CaseReminder-Deleted')
    old_reminder_id = reminder._id
    set_case_property_directly(self.case1, 'case_property1', 'abc')
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder._id, old_reminder_id)
    old_reminder_id = reminder._id
    set_case_property_directly(self.case1, 'start_sending1', None)
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertEqual(reminder, None)
    self.assertEqual(CaseReminder.get(old_reminder_id).doc_type, 'CaseReminder-Deleted')
    set_case_property_directly(self.case1, 'start_sending1', '2012-02-25 11:15')
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, (datetime(2012, 2, 25, 11, 15) + timedelta(days=self.handler1.start_offset)))
    old_reminder_id = reminder._id
    set_case_property_directly(self.case1, 'start_sending1', '2012-02-26 11:20')
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder.next_fire, (datetime(2012, 2, 26, 11, 20) + timedelta(days=self.handler1.start_offset)))
    self.assertEqual(CaseReminder.get(old_reminder_id).doc_type, 'CaseReminder-Deleted')
    old_reminder_id = reminder._id
    set_case_property_directly(self.case1, 'case_property1', 'xyz')
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertNotEqual(reminder, None)
    self.assertEqual(reminder._id, old_reminder_id)
    old_reminder_id = reminder._id
    set_case_property_directly(self.case1, 'start_sending1', None)
    self.case1.save()
    reminder = self.handler1.get_reminder(self.case1)
    self.assertEqual(reminder, None)
    self.assertEqual(CaseReminder.get(old_reminder_id).doc_type, 'CaseReminder-Deleted')

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