def create_weekly_event(callback, day, hour, minute, callback_args=None): # relies on all the built-in checks in EventSchedule.save() schedule = EventSchedule(callback=callback, hours=set([hour]), \ days_of_week=set([day]), minutes=set([minute]), \ callback_args=callback_args ) schedule.save() return schedule
def start (self): """Configure your app in the start phase.""" if not self.bootstrapped: # initialize the forms app for registration self._form_app = self.router.get_app("form") # this tells the form app to add itself as a message handler # which registers the regex and function that this will dispatch to self._form_app.add_message_handler_to(self) formslogic = WeltelFormsLogic() formslogic.app = self # this tells the form app that this is also a form handler self._form_app.add_form_handler("weltel", formslogic) self.boostrapped = True # we could also put this in the fixture # set up automatic deregistration event try: EventSchedule.objects.get(callback="weltel.callbacks.automatic_deregistration") except EventSchedule.DoesNotExist: # automatically deregister users we haven't seen in 3 weeks set_daily_event("weltel.callbacks.automatic_deregistration", \ hour=0, minute=15, callback_args=3) # set up bi-weekly shida report try: EventSchedule.objects.get(callback="weltel.callbacks.shida_report") except EventSchedule.DoesNotExist: schedule = EventSchedule(callback="weltel.callbacks.shida_report", \ hours=set([8,15]), minutes=set([0]) ) schedule.save()
def start(self): """Configure your app in the start phase.""" if not self.bootstrapped: # initialize the forms app for registration self._form_app = self.router.get_app("form") # this tells the form app to add itself as a message handler # which registers the regex and function that this will dispatch to self._form_app.add_message_handler_to(self) formslogic = WeltelFormsLogic() formslogic.app = self # this tells the form app that this is also a form handler self._form_app.add_form_handler("weltel", formslogic) self.boostrapped = True # set up bi-daily shida report try: EventSchedule.objects.get(callback="weltel.callbacks.shida_report") except EventSchedule.DoesNotExist: schedule = EventSchedule(callback="weltel.callbacks.shida_report", hours=set([8, 14]), minutes=set([0])) schedule.save() # set up daily inactive check try: EventSchedule.objects.get(callback="weltel.callbacks.mark_inactive") except EventSchedule.DoesNotExist: set_daily_event("weltel.callbacks.mark_inactive", hour=0, minute=15, callback_args=[3]) # set up daily 'other report' try: EventSchedule.objects.get(callback="weltel.callbacks.other_report") except EventSchedule.DoesNotExist: set_daily_event("weltel.callbacks.other_report", hour=14, minute=30, callback_args=[])
def create_daily_event(callback, hour, minute, callback_args): # relies on all the built-in checks in EventSchedule.save() schedule = EventSchedule(callback=callback, hours=set([hour]), \ minutes=set([minute]), \ callback_args=callback_args ) schedule.save() return schedule
def setUp(self): super(testDecoratedExecution, self).setUp() global callback_counter callback_counter = 0 EventSchedule.objects.all().delete() ExecutionRecord.objects.all().delete() schedule = EventSchedule(callback="scheduler.tests.decorators.decorated_callback", \ minutes=ALL_VALUE) schedule.save() self.schedule = EventSchedule.objects.get(pk=schedule.pk)
def test_one_shot(self): """ Test scheduler in real time""" global callback_counter self.router.start() schedule = EventSchedule(callback="scheduler.tests.slow.callback_func", minutes=ALL, callback_args=([3])) schedule.save() time.sleep(180.0) self.assertEquals(callback_counter,9) self.router.stop()
def test_recurring(self): """ Test regular recurring schedules """ global callback_counter self.router.start() self.router.get_app("scheduler").schedule_thread._debug_speedup(minutes=1) schedule = EventSchedule(callback="scheduler.tests.speedup.callback_func", minutes=ALL, callback_args=([3])) schedule.save() time.sleep(2.9) self.assertEquals(callback_counter, 9) self.router.stop()
def setUp(self): super(TestTasks, self).setUp() global callback_counter callback_counter = 0 EventSchedule.objects.all().delete() ExecutionRecord.objects.all().delete() schedule = EventSchedule(callback="scheduler.tests.tasks.callback_func", \ minutes=ALL_VALUE) schedule.save() self.schedule = EventSchedule.objects.get(pk=schedule.pk) self.assertTrue(self.schedule.last_ran is None)
def test_one_shot(self): """ Basically test 'count'""" global callback_counter self.router.start() # speedup the scheduler so that 1 second == 1 minute self.router.get_app('scheduler').schedule_thread._debug_speedup(minutes=1) schedule = EventSchedule(callback="scheduler.tests.realtime.callback_func", minutes=ALL, callback_args=([3]), count=1) schedule.save() time.sleep(3.0) self.assertEquals(callback_counter,3) self.router.stop()
def load_schedules(): # TODO make this sane. # {module: {function: (hours, minutes)}} # everything is daily. # we convert from TZ time to UTC theschedule = {"logistics_project.apps.tanzania.reminders.delivery": {"first_facility": (9, 0), "second_facility": (9, 0), "third_facility": (9, 0), "first_district": (9, 0), "second_district": (9, 0), "third_district": (9, 0)}, "logistics_project.apps.tanzania.reminders.randr": {"first_facility": (9, 0), "second_facility": (9, 0), "third_facility": (9, 0), "first_district": (9, 0), "second_district": (9, 0), "third_district": (9, 0)}, "logistics_project.apps.tanzania.reminders.stockonhand": {"first": (9, 0), "second": (9, 0), "third": (9, 0)}, "logistics_project.apps.tanzania.reminders.stockonhandthankyou": {"first": (9, 0)}, "logistics_project.apps.tanzania.reminders.reports": {"delivery_summary": (9, 0), "soh_summary": (9, 0), "randr_summary": (9, 0), "email_reports": (9, 0)}, "logistics_project.apps.tanzania.reminders.test": {"test_email_admins": (9, 0)}} tanzania_tz = timezone("Africa/Dar_es_Salaam") def _to_tz_time(hours, minutes): localized = tanzania_tz.normalize(tanzania_tz.localize(datetime(2011, 1, 1, hours, minutes))) utced = localized.astimezone(pytz.utc) return (utced.hour, utced.minute) for module, funcdict in theschedule.items(): for func, (hours, minutes) in funcdict.items(): func_abspath = "%s.%s" % (module, func) hours, minutes = _to_tz_time(hours, minutes) try: schedule = EventSchedule.objects.get(callback=func_abspath) schedule.hours = [hours] schedule.minutes = [minutes] except EventSchedule.DoesNotExist: schedule = EventSchedule(callback=func_abspath, hours=[hours], minutes=[minutes]) schedule.save()
def testDefaults(self): schedule = EventSchedule(callback="foo", minutes=ALL_VALUE) schedule.save() sback = EventSchedule.objects.get(pk=schedule.pk) self.assertEqual([], sback.months) self.assertEqual([], sback.days_of_month) self.assertEqual([], sback.days_of_week) self.assertEqual([], sback.hours) self.assertEqual(["*"], sback.minutes)
def schedule_notifications (self, reg, reg_time): """schedule all future notificaitons to be sent for this patient""" for day in config.notification_days: send_at = self.calc_send_time(reg_time, reg.contact_time, day) #scheduler works in local server time instead of UTC local_send_at = send_at.astimezone(pytz.timezone(config.server_tz)).replace(tzinfo=None) schedule = EventSchedule(callback="circumcision.app.send_notification", \ start_time=local_send_at, count=1, minutes='*', callback_args=[reg.patient_id, day, reg.language], description='patient %s; day %d' % (reg.patient_id, day)) schedule.save()
def test_recurring(self): """ Test regular recurring schedules """ global callback_counter self.router.start() self.router.get_app('scheduler').schedule_thread._debug_speedup( minutes=1) schedule = EventSchedule( callback="scheduler.tests.speedup.callback_func", minutes=ALL, callback_args=([3])) schedule.save() time.sleep(2.9) self.assertEquals(callback_counter, 9) self.router.stop()
def start(self): # create a scheduled event if not present # due to bug in fixture handling in scheduler event_desc = 'groupmessaging_main' if EventSchedule.objects.filter(description=event_desc).count() > 0: return schedule = EventSchedule(description=event_desc, \ callback="groupmessaging.utils.process_queue_callback", \ minutes=self.minutes, \ callback_args=('self.router')) schedule.save() self.log('DEBUG', u"Created Event Schedule %s" % event_desc)
def test_timestart_timestop(self): """ Test timebound schedules """ global callback_counter self.router.start() self.router.get_app('scheduler').schedule_thread._debug_speedup(minutes=1) start_time = datetime.now() + timedelta(minutes=2) end_time = datetime.now() + timedelta(minutes=4) schedule = EventSchedule(callback="scheduler.tests.realtime.callback_func", minutes=ALL, callback_args=([3]), \ start_time = start_time, end_time = end_time) schedule.save() time.sleep(7.0) self.assertEquals(callback_counter,6) self.router.stop()
def test_timestart_timestop(self): """ Test timebound schedules """ global callback_counter self.router.start() self.router.get_app('scheduler').schedule_thread._debug_speedup( minutes=1) start_time = datetime.now() + timedelta(minutes=2) end_time = datetime.now() + timedelta(minutes=4) schedule = EventSchedule(callback="scheduler.tests.speedup.callback_func", minutes=ALL, callback_args=([3]), \ start_time = start_time, end_time = end_time) schedule.save() time.sleep(7.0) self.assertEquals(callback_counter, 6) self.router.stop()
def test_days_of_month(self): """ days of month are indexed starting '1' """ schedule = EventSchedule(callback="foo", days_of_month=set([1,15,30]), hours=set([10]), \ minutes=set([0])) self.assertFalse(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start+10*hour)) self.assertFalse(schedule.should_fire(start+10*hour+min)) self.assertFalse(schedule.should_fire(start+10*min)) self.assertTrue(schedule.should_fire(start+14*day+10*hour)) self.assertFalse(schedule.should_fire(start+14*day+9*hour)) self.assertFalse(schedule.should_fire(start+14*day+11*hour)) self.assertTrue(schedule.should_fire(start+29*day+10*hour)) self.assertFalse(schedule.should_fire(start+29*day+1*min)) self.assertFalse(schedule.should_fire(start+29*day-1*min))
def testExecutionFailure(self): fail_schedule = EventSchedule(callback="scheduler.tests.execution.fail", \ minutes=ALL_VALUE) fail_schedule.save() self.assertEqual(0, ExecutionRecord.objects.count()) asof = datetime.utcnow() self.assertEqual(None, fail_schedule.run(asof)) fail_schedule = EventSchedule.objects.get(pk=fail_schedule.pk) self.assertEqual(asof, fail_schedule.last_ran) self.assertEqual(1, ExecutionRecord.objects.count()) self.assertEqual(1, FailedExecutionRecord.objects.count()) [rec] = FailedExecutionRecord.objects.all() self.assertEqual(fail_schedule, rec.schedule) self.assertEqual(asof, rec.runtime) self.assertEqual("FAIL.", rec.message) self.assertEqual("FAIL.", rec.message)
def test_one_shot(self): """ Basically test 'count'""" global callback_counter self.router.start() # speedup the scheduler so that 1 second == 1 minute self.router.get_app('scheduler').schedule_thread._debug_speedup( minutes=1) schedule = EventSchedule( callback="scheduler.tests.speedup.callback_func", minutes=ALL, callback_args=([3]), count=1) schedule.save() time.sleep(3.0) self.assertEquals(callback_counter, 3) self.router.stop()
def test_hours(self): schedule = EventSchedule(callback="foo", hours=set([3,5,23]), \ minutes='*') self.assertFalse(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start + 3 * hour)) self.assertFalse(schedule.should_fire(start + 4 * hour)) self.assertTrue(schedule.should_fire(start + 5 * hour)) self.assertFalse(schedule.should_fire(start + 6 * hour)) self.assertTrue(schedule.should_fire(start + 23 * hour))
def testFields(self): schedule = EventSchedule(callback="foo", \ minutes=ALL_VALUE) args = ["a", 2, None] kwargs = {"foo": "bar", "4": None, "asdf": 18} schedule.callback_args = args schedule.callback_kwargs = kwargs schedule.save() sback = EventSchedule.objects.get(pk=schedule.pk) self.assertEqual(len(args), len(sback.callback_args)) for i, val in enumerate(args): self.assertEqual(sback.callback_args[i], val) self.assertEqual(len(kwargs), len(sback.callback_kwargs)) for k, val in kwargs.items(): self.assertEqual(sback.callback_kwargs[k], val)
def test_all(self): schedule = EventSchedule(callback="foo", \ minutes=ALL) self.assertTrue(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start + sec)) self.assertTrue(schedule.should_fire(start + min)) self.assertTrue(schedule.should_fire(start + hour)) self.assertTrue(schedule.should_fire(start + day)) self.assertTrue(schedule.should_fire(start + week)) self.assertTrue( schedule.should_fire(start + sec + min + hour + day + week))
def test_hours(self): schedule = EventSchedule(callback="foo", hours=set([3,5,23]), \ minutes='*') self.assertFalse(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start+3*hour)) self.assertFalse(schedule.should_fire(start+4*hour)) self.assertTrue(schedule.should_fire(start+5*hour)) self.assertFalse(schedule.should_fire(start+6*hour)) self.assertTrue(schedule.should_fire(start+23*hour))
def test_all(self): schedule = EventSchedule(callback="foo", \ minutes=ALL) self.assertTrue(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start+sec)) self.assertTrue(schedule.should_fire(start+min)) self.assertTrue(schedule.should_fire(start+hour)) self.assertTrue(schedule.should_fire(start+day)) self.assertTrue(schedule.should_fire(start+week)) self.assertTrue(schedule.should_fire(start+sec+min+hour+day+week))
def start (self): """Configure your app in the start phase.""" if not self.bootstrapped: # initialize the forms app for registration self._form_app = self.router.get_app("form") # this tells the form app to add itself as a message handler # which registers the regex and function that this will dispatch to self._form_app.add_message_handler_to(self) formslogic = WeltelFormsLogic() formslogic.app = self # this tells the form app that this is also a form handler self._form_app.add_form_handler("weltel", formslogic) self.boostrapped = True # set up bi-daily shida report try: EventSchedule.objects.get(callback="weltel.callbacks.shida_report") except EventSchedule.DoesNotExist: schedule = EventSchedule(callback="weltel.callbacks.shida_report", \ hours=set([8,14]), minutes=set([0]) ) schedule.save() # set up daily inactive check try: EventSchedule.objects.get(callback="weltel.callbacks.mark_inactive") except EventSchedule.DoesNotExist: set_daily_event("weltel.callbacks.mark_inactive", hour=0, minute=15, callback_args=[3]) # set up daily 'other report' try: EventSchedule.objects.get(callback="weltel.callbacks.other_report") except EventSchedule.DoesNotExist: set_daily_event("weltel.callbacks.other_report", hour=14, minute=30, callback_args=[])
def test_month(self): """ months are indexed from '1' """ schedule = EventSchedule(callback="foo", months=set([2]), \ days_of_month='*', hours='*', \ minutes='*') self.assertFalse(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start+31*day)) self.assertTrue(schedule.should_fire(start+31*day+sec)) self.assertTrue(schedule.should_fire(start+31*day+min)) self.assertTrue(schedule.should_fire(start+31*day+hour)) self.assertTrue(schedule.should_fire(start+31*day+day)) self.assertTrue(schedule.should_fire(start+31*day+sec+min+hour+day))
def test_days_of_month(self): """ Fire event on the 1st, 15th, and 30th of the month at 10:00 am Note: days of month are indexed starting '1' """ schedule = EventSchedule(callback="foo", days_of_month=set([1,15,30]), hours=set([10]), \ minutes=set([0])) self.assertFalse(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start + 10 * hour)) self.assertFalse(schedule.should_fire(start + 10 * hour + min)) self.assertFalse(schedule.should_fire(start + 10 * min)) self.assertFalse(schedule.should_fire(start + day + 10 * hour)) self.assertTrue(schedule.should_fire(start + 14 * day + 10 * hour)) self.assertFalse(schedule.should_fire(start + 14 * day + 9 * hour)) self.assertFalse(schedule.should_fire(start + 14 * day + 11 * hour)) self.assertFalse(schedule.should_fire(start + 13 * day + 10 * hour)) self.assertFalse(schedule.should_fire(start + 15 * day + 10 * hour)) self.assertTrue(schedule.should_fire(start + 29 * day + 10 * hour)) self.assertFalse(schedule.should_fire(start + 29 * day + 1 * min)) self.assertFalse(schedule.should_fire(start + 29 * day - 1 * min)) self.assertFalse(schedule.should_fire(start + 28 * day + 10 * hour))
def test_days_of_week(self): """ fire event monday, friday, and sunday, at 8:15 am and 5:15 pm Note: days of week are indexed starting '0' """ schedule = EventSchedule(callback="foo", days_of_week=set([0,4,6]), hours=set([8,17]), \ minutes=set([15])) self.assertFalse(schedule.should_fire(start)) self.assertFalse(schedule.should_fire(start + 5 * day)) self.assertFalse(schedule.should_fire(start + 7 * day)) self.assertFalse(schedule.should_fire(start + 3 * hour)) self.assertFalse(schedule.should_fire(start + 5 * day + 7 * hour)) self.assertFalse(schedule.should_fire(start + 7 * day + 16 * hour)) self.assertFalse(schedule.should_fire(start + 8 * hour + 13 * min)) self.assertFalse( schedule.should_fire(start + 5 * day + 8 * hour + 16 * min)) self.assertFalse( schedule.should_fire(start + 7 * day + 8 * hour + 25 * min)) self.assertFalse( schedule.should_fire(start + 3 * day + 8 * hour + 15 * min)) self.assertFalse( schedule.should_fire(start + 5 * day + 17 * hour + 15 * min)) self.assertTrue(schedule.should_fire(start + 8 * hour + 15 * min)) self.assertTrue(schedule.should_fire(start + 17 * hour + 15 * min)) self.assertTrue( schedule.should_fire(start + 4 * day + 8 * hour + 15 * min)) self.assertTrue( schedule.should_fire(start + 6 * day + 17 * hour + 15 * min))
def test_minutes(self): schedule = EventSchedule(callback="foo", \ minutes=set([1,3,5]), count=1) self.assertFalse(schedule.should_fire(start)) self.assertFalse(schedule.should_fire(start + sec)) self.assertTrue(schedule.should_fire(start + 1 * min)) self.assertFalse(schedule.should_fire(start + 2 * min)) self.assertTrue(schedule.should_fire(start + 3 * min)) self.assertFalse(schedule.should_fire(start + 4 * min)) self.assertTrue(schedule.should_fire(start + 5 * min)) self.assertFalse(schedule.should_fire(start + hour)) self.assertFalse(schedule.should_fire(start + day)) self.assertFalse(schedule.should_fire(start + week))
def test_month(self): """ Fire event every minute in February Note: months are indexed from '1' """ schedule = EventSchedule(callback="foo", months=set([2]), \ days_of_month='*', hours='*', \ minutes='*') self.assertFalse(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start + month)) self.assertTrue(schedule.should_fire(start + month + sec)) self.assertTrue(schedule.should_fire(start + month + min)) self.assertTrue(schedule.should_fire(start + month + hour)) self.assertTrue(schedule.should_fire(start + month + day)) self.assertTrue( schedule.should_fire(start + month + sec + min + hour + day)) self.assertFalse(schedule.should_fire(start + 2 * month)) self.assertFalse(schedule.should_fire(start + 2 * month + sec)) self.assertFalse(schedule.should_fire(start + 2 * month + min)) self.assertFalse(schedule.should_fire(start + 2 * month + hour)) self.assertFalse(schedule.should_fire(start + 2 * month + day))
def load_schedules(): # TODO make this sane. # {module: {function: (hours, minutes)}} # everything is daily. # we convert from TZ time to UTC theschedule = { "logistics_project.apps.tanzania.reminders.delivery": { "first_facility": (9, 0), "second_facility": (9, 0), "third_facility": (9, 0), "first_district": (9, 0), "second_district": (9, 0), "third_district": (9, 0) }, "logistics_project.apps.tanzania.reminders.randr": { "first_facility": (9, 0), "second_facility": (9, 0), "third_facility": (9, 0), "first_district": (9, 0), "second_district": (9, 0), "third_district": (9, 0) }, "logistics_project.apps.tanzania.reminders.stockonhand": { "first": (9, 0), "second": (9, 0), "third": (9, 0) }, "logistics_project.apps.tanzania.reminders.stockonhandthankyou": { "first": (9, 0) }, "logistics_project.apps.tanzania.reminders.reports": { "delivery_summary": (9, 0), "soh_summary": (9, 0), "randr_summary": (9, 0), "email_reports": (9, 0) }, "logistics_project.apps.tanzania.reminders.test": { "test_email_admins": (9, 0) } } tanzania_tz = timezone("Africa/Dar_es_Salaam") def _to_tz_time(hours, minutes): localized = tanzania_tz.normalize( tanzania_tz.localize(datetime(2011, 1, 1, hours, minutes))) utced = localized.astimezone(pytz.utc) return (utced.hour, utced.minute) for module, funcdict in theschedule.items(): for func, (hours, minutes) in funcdict.items(): func_abspath = "%s.%s" % (module, func) hours, minutes = _to_tz_time(hours, minutes) try: schedule = EventSchedule.objects.get(callback=func_abspath) schedule.hours = [hours] schedule.minutes = [minutes] except EventSchedule.DoesNotExist: schedule = EventSchedule(callback=func_abspath, hours=[hours], minutes=[minutes]) schedule.save()
def test_month(self): """ Fire event every minute in February Note: months are indexed from '1' """ schedule = EventSchedule(callback="foo", months=set([2]), \ days_of_month='*', hours='*', \ minutes='*') self.assertFalse(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start+month)) self.assertTrue(schedule.should_fire(start+month+sec)) self.assertTrue(schedule.should_fire(start+month+min)) self.assertTrue(schedule.should_fire(start+month+hour)) self.assertTrue(schedule.should_fire(start+month+day)) self.assertTrue(schedule.should_fire(start+month+sec+min+hour+day)) self.assertFalse(schedule.should_fire(start+2*month)) self.assertFalse(schedule.should_fire(start+2*month+sec)) self.assertFalse(schedule.should_fire(start+2*month+min)) self.assertFalse(schedule.should_fire(start+2*month+hour)) self.assertFalse(schedule.should_fire(start+2*month+day))
def test_minutes(self): schedule = EventSchedule(callback="foo", \ minutes=set([1,3,5]), count=1) self.assertFalse(schedule.should_fire(start)) self.assertFalse(schedule.should_fire(start+sec)) self.assertTrue(schedule.should_fire(start+1*min)) self.assertFalse(schedule.should_fire(start+2*min)) self.assertTrue(schedule.should_fire(start+3*min)) self.assertFalse(schedule.should_fire(start+4*min)) self.assertTrue(schedule.should_fire(start+5*min)) self.assertFalse(schedule.should_fire(start+hour)) self.assertFalse(schedule.should_fire(start+day)) self.assertFalse(schedule.should_fire(start+week))
def test_days_of_month(self): """ Fire event on the 1st, 15th, and 30th of the month at 10:00 am Note: days of month are indexed starting '1' """ schedule = EventSchedule(callback="foo", days_of_month=set([1,15,30]), hours=set([10]), \ minutes=set([0])) self.assertFalse(schedule.should_fire(start)) self.assertTrue(schedule.should_fire(start+10*hour)) self.assertFalse(schedule.should_fire(start+10*hour+min)) self.assertFalse(schedule.should_fire(start+10*min)) self.assertFalse(schedule.should_fire(start+day+10*hour)) self.assertTrue(schedule.should_fire(start+14*day+10*hour)) self.assertFalse(schedule.should_fire(start+14*day+9*hour)) self.assertFalse(schedule.should_fire(start+14*day+11*hour)) self.assertFalse(schedule.should_fire(start+13*day+10*hour)) self.assertFalse(schedule.should_fire(start+15*day+10*hour)) self.assertTrue(schedule.should_fire(start+29*day+10*hour)) self.assertFalse(schedule.should_fire(start+29*day+1*min)) self.assertFalse(schedule.should_fire(start+29*day-1*min)) self.assertFalse(schedule.should_fire(start+28*day+10*hour))
def test_days_of_week(self): """ fire event monday, friday, and sunday, at 8:15 am and 5:15 pm Note: days of week are indexed starting '0' """ schedule = EventSchedule(callback="foo", days_of_week=set([0,4,6]), hours=set([8,17]), \ minutes=set([15])) self.assertFalse(schedule.should_fire(start)) self.assertFalse(schedule.should_fire(start+5*day)) self.assertFalse(schedule.should_fire(start+7*day)) self.assertFalse(schedule.should_fire(start+3*hour)) self.assertFalse(schedule.should_fire(start+5*day+7*hour)) self.assertFalse(schedule.should_fire(start+7*day+16*hour)) self.assertFalse(schedule.should_fire(start+8*hour+13*min)) self.assertFalse(schedule.should_fire(start+5*day+8*hour+16*min)) self.assertFalse(schedule.should_fire(start+7*day+8*hour+25*min)) self.assertFalse(schedule.should_fire(start+3*day+8*hour+15*min)) self.assertFalse(schedule.should_fire(start+5*day+17*hour+15*min)) self.assertTrue(schedule.should_fire(start+8*hour+15*min)) self.assertTrue(schedule.should_fire(start+17*hour+15*min)) self.assertTrue(schedule.should_fire(start+4*day+8*hour+15*min)) self.assertTrue(schedule.should_fire(start+6*day+17*hour+15*min))