

def test_ok(self):
    CaseReminderHandler.now = datetime(year=2012, month=2, day=16, hour=11, minute=0)
    set_case_property_directly(self.case1, 'start_sending1', 'ok')
    set_case_property_directly(self.case1, 'start_sending2', 'ok')
    set_case_property_directly(self.case2, 'start_sending1', 'ok')
    set_case_property_directly(self.case2, 'start_sending3', 'ok')
    self.case1.save()
    self.case2.save()
    self.assertNotEqual(self.handler1.get_reminder(self.case1), None)
    self.assertEqual(self.handler1.get_reminder(self.case2), None)
    self.assertNotEqual(self.handler2.get_reminder(self.case1), None)
    self.assertEqual(self.handler2.get_reminder(self.case2), None)
    self.assertEqual(self.handler3.get_reminder(self.case1), None)
    self.assertEqual(self.handler3.get_reminder(self.case2), None)
    self.assertEqual(self.handler1.get_reminder(self.case1).next_fire, (CaseReminderHandler.now + timedelta(days=self.handler1.start_offset)))
    self.assertEqual(self.handler2.get_reminder(self.case1).next_fire, (CaseReminderHandler.now + timedelta(days=self.handler2.start_offset)))
    CaseReminderHandler.now = datetime(year=2012, month=2, day=16, hour=11, minute=15)
    self.handler1.case_type = 'case_type_b'
    self.handler1.save()
    self.handler2.case_type = 'case_type_b'
    self.handler2.save()
    self.handler3.case_type = 'case_type_b'
    self.handler3.save()
    self.assertEqual(self.handler1.get_reminder(self.case1), None)
    self.assertNotEqual(self.handler1.get_reminder(self.case2), None)
    self.assertEqual(self.handler2.get_reminder(self.case1), None)
    self.assertEqual(self.handler2.get_reminder(self.case2), None)
    self.assertEqual(self.handler3.get_reminder(self.case1), None)
    self.assertNotEqual(self.handler3.get_reminder(self.case2), None)
    self.assertEqual(self.handler1.get_reminder(self.case2).next_fire, (CaseReminderHandler.now + timedelta(days=self.handler1.start_offset)))
    self.assertEqual(self.handler3.get_reminder(self.case2).next_fire, (CaseReminderHandler.now + timedelta(days=self.handler3.start_offset)))
    prev_now = CaseReminderHandler.now
    CaseReminderHandler.now = datetime(year=2012, month=2, day=16, hour=11, minute=30)
    self.case1.type = 'case_type_b'
    self.case1.save()
    self.assertNotEqual(self.handler1.get_reminder(self.case1), None)
    self.assertNotEqual(self.handler1.get_reminder(self.case2), None)
    self.assertNotEqual(self.handler2.get_reminder(self.case1), None)
    self.assertEqual(self.handler2.get_reminder(self.case2), None)
    self.assertEqual(self.handler3.get_reminder(self.case1), None)
    self.assertNotEqual(self.handler3.get_reminder(self.case2), None)
    self.assertEqual(self.handler1.get_reminder(self.case1).next_fire, (CaseReminderHandler.now + timedelta(days=self.handler1.start_offset)))
    self.assertEqual(self.handler2.get_reminder(self.case1).next_fire, (CaseReminderHandler.now + timedelta(days=self.handler2.start_offset)))
    self.assertEqual(self.handler1.get_reminder(self.case2).next_fire, (prev_now + timedelta(days=self.handler1.start_offset)))
    self.assertEqual(self.handler3.get_reminder(self.case2).next_fire, (prev_now + timedelta(days=self.handler3.start_offset)))
    prev_now = CaseReminderHandler.now
    CaseReminderHandler.now = datetime(year=2012, month=2, day=16, hour=11, minute=45)
    self.case2.type = 'case_type_a'
    self.case2.save()
    self.assertNotEqual(self.handler1.get_reminder(self.case1), None)
    self.assertEqual(self.handler1.get_reminder(self.case2), None)
    self.assertNotEqual(self.handler2.get_reminder(self.case1), None)
    self.assertEqual(self.handler2.get_reminder(self.case2), None)
    self.assertEqual(self.handler3.get_reminder(self.case1), None)
    self.assertEqual(self.handler3.get_reminder(self.case2), None)
    self.assertEqual(self.handler1.get_reminder(self.case1).next_fire, (prev_now + timedelta(days=self.handler1.start_offset)))
    self.assertEqual(self.handler2.get_reminder(self.case1).next_fire, (prev_now + timedelta(days=self.handler2.start_offset)))

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