def testDailyReportLenientWindow(self): ReportNotification(hour=12, minute=0, interval='daily').save() self._check('daily', datetime(2014, 10, 31, 12, 5), 1) # lenient window # but not too lenient self.assertRaises( ValueError, lambda: list(get_scheduled_report_ids('daily', end_datetime=datetime(2014, 10, 31, 12, 6))) )
def testDailyReportLenientWindow(self): ReportNotification(hour=12, minute=0, interval='daily').save() self._check('daily', datetime(2014, 10, 31, 12, 5), 1) # lenient window # but not too lenient self.assertRaises( ValueError, lambda: list( get_scheduled_report_ids( 'daily', end_datetime=datetime(2014, 10, 31, 12, 6))))
def _check(self, period, as_of, count): # get_scheduled_report_ids relies on end_datetime # being strictly greater than start_datetime # for tests targeting an exact minute mark, # we need to add a small amount to make it after. # This is a reasonable thing to do because in production, # it'll always run a short time after the periodic task is fired as_of += timedelta(microseconds=1) self.assertEqual(count, len(list(get_scheduled_report_ids(period, end_datetime=as_of))))
def _check(self, period, as_of, count): # get_scheduled_report_ids relies on end_datetime # being strictly greater than start_datetime # for tests targeting an exact minute mark, # we need to add a small amount to make it after. # This is a reasonable thing to do because in production, # it'll always run a short time after the periodic task is fired as_of += timedelta(microseconds=1) self.assertEqual( count, len(list(get_scheduled_report_ids(period, end_datetime=as_of))))
def testDefaultValue(self): now = datetime.utcnow() # This line makes sure that the date of the ReportNotification is an increment of 15 minutes ReportNotification(hour=now.hour, minute=(now.minute // 15) * 15, interval='daily').save() if now.minute % 15 <= 5: self._check('daily', None, 1) else: self.assertRaises( ValueError, lambda: list(get_scheduled_report_ids('daily', None)))
def monthly_reports(): for report_id in get_scheduled_report_ids('monthly'): send_delayed_report(report_id)
def weekly_reports(): for report_id in get_scheduled_report_ids('weekly'): send_delayed_report(report_id)
def daily_reports(): for report_id in get_scheduled_report_ids('daily'): send_delayed_report(report_id)
def _check(self, period, as_of, count): self.assertEqual(count, len(list(get_scheduled_report_ids(period, as_of))))