def test_get_all_due_events(self): patient = Patient() patient.save() # The fixtures already contain two due events self.assertEquals(scheduler.get_all_due_events().count(), 2) sendable = InfoMessage(text="Test Message", way_of_communication = get_woc("sms")) sendable.recipient = patient sendable.save() schedule1 = ScheduledEvent(sendable=sendable, send_time=datetime.now()) schedule1.save() schedule2 = ScheduledEvent(sendable=sendable, send_time=(datetime.now() - timedelta(days=1))) schedule2.save() schedule3 = ScheduledEvent(sendable=sendable, send_time=(datetime.now() + timedelta(days=1))) schedule3.save() self.assertEquals(scheduler.get_all_due_events().count(), 4) self.assertTrue(schedule1 in scheduler.get_all_due_events()) self.assertTrue(schedule2 in scheduler.get_all_due_events()) self.assertFalse(schedule3 in scheduler.get_all_due_events()) schedule4 = ScheduledEvent(sendable=sendable, send_time=datetime.now(), state = "failed") schedule4.save() schedule5 = ScheduledEvent(sendable=sendable, send_time=(datetime.now() - timedelta(days=1)), state = "sent") schedule5.save() self.assertEquals(scheduler.get_all_due_events().count(), 4) schedule1.delete() schedule2.delete() schedule3.delete() schedule4.delete() schedule5.delete()
def scheduled_events_count(state = 'new'): return scheduler.get_all_due_events().count()