def test_ok(self):
        #
        # Test changing a start condition of "ok"
        #
        # Spawn the reminder with an "ok" start condition value
        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)
        )
        
        # Test that saving the case without changing the start condition has no effect
        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)
        
        # Test retiring the reminder
        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")
        
        #
        # Test changing a start condition which is a datetime value
        #
        # Spawn the reminder with datetime start condition value
        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)
        )
        
        # Reset the datetime start condition
        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")
        
        # Test that saving the case without changing the start condition has no effect
        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)
        
        # Retire the reminder
        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")
        
        #
        # Test changing a start condition which is a date value
        #
        # Spawn the reminder with date start condition value
        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)
        )
        
        # Reset the date start condition
        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")
        
        # Test that saving the case without changing the start condition has no effect
        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)
        
        # Retire the reminder
        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")
        
        #
        # Test changing a start condition which is a string representation of a datetime value
        #
        # Spawn the reminder with datetime start condition value
        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)
        )
        
        # Reset the datetime start condition
        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")
        
        # Test that saving the case without changing the start condition has no effect
        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)
        
        # Retire the reminder
        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