def test_monthly_schedule(self): # Todo, doesn't handle last-day-of-month config = _make_performance_config(self.domain, MONTHLY, hour=8, day_of_month=4) as_of = datetime(2015, 1, 4, 8) configs_on_4th_day = get_message_configs_at_this_hour(as_of=as_of) self.assertEqual(1, len(configs_on_4th_day)) self.assertEqual(config._id, configs_on_4th_day[0]._id) # check subfunctions self.assertEqual(0, len(get_daily_messages(as_of))) self.assertEqual(0, len(get_weekly_messages(as_of))) self.assertEqual(1, len(get_monthly_messages(as_of))) # check wrong day wrong_day = as_of.replace(day=5) self.assertEqual(0, len(get_monthly_messages(as_of=wrong_day))) # check wrong hour wrong_hour = as_of.replace(hour=5) self.assertEqual(0, len(get_monthly_messages(as_of=wrong_hour))) # next month ok next_month = as_of.replace(month=2) self.assertEqual(1, len(get_monthly_messages(as_of=next_month)))
def test_weekly_schedule(self): config = _make_performance_config(self.domain, WEEKLY, day_of_week=4, hour=8) as_of = datetime(2015, 8, 14, 8) # happens to be a friday (weekday 4) configs_on_4th_day = get_message_configs_at_this_hour(as_of=as_of) self.assertEqual(1, len(configs_on_4th_day)) self.assertEqual(config._id, configs_on_4th_day[0]._id) # check subfunctions self.assertEqual(0, len(get_daily_messages(as_of))) self.assertEqual(1, len(get_weekly_messages(as_of))) self.assertEqual(0, len(get_monthly_messages(as_of))) # any weekday that's not 4th wrong_day = as_of.replace(day=15) self.assertEqual(0, len(get_weekly_messages(wrong_day))) # wrong hour wrong_hour = as_of.replace(hour=7) self.assertEqual(0, len(get_weekly_messages(wrong_hour))) # one week later should be ok next_week = as_of + timedelta(days=7) self.assertEqual(1, len(get_weekly_messages(next_week)))
def test_weekly_schedule(self): config = _make_performance_config(self.domain, WEEKLY, day_of_week=4, hour=8) try: as_of = datetime(2015, 8, 14, 8) # happens to be a friday (weekday 4) configs_on_4th_day = get_message_configs_at_this_hour(as_of=as_of) self.assertEqual(1, len(configs_on_4th_day)) self.assertEqual(config._id, configs_on_4th_day[0]._id) # check subfunctions self.assertEqual(0, len(get_daily_messages(as_of))) self.assertEqual(1, len(get_weekly_messages(as_of))) self.assertEqual(0, len(get_monthly_messages(as_of))) # any weekday that's not 4th wrong_day = as_of.replace(day=15) self.assertEqual(0, len(get_weekly_messages(wrong_day))) # wrong hour wrong_hour = as_of.replace(hour=7) self.assertEqual(0, len(get_weekly_messages(wrong_hour))) # one week later should be ok next_week = as_of + timedelta(days=7) self.assertEqual(1, len(get_weekly_messages(next_week))) finally: config.delete()
def test_daily_schedule(self): config = _make_performance_config(self.domain, DAILY, hour=4) as_of = datetime(2015, 1, 1, 4) configs_at_4_hours = get_message_configs_at_this_hour(as_of=as_of) self.assertEqual(1, len(configs_at_4_hours)) self.assertEqual(config._id, configs_at_4_hours[0]._id) # check subfunctions self.assertEqual(1, len(get_daily_messages(as_of))) self.assertEqual(0, len(get_weekly_messages(as_of))) self.assertEqual(0, len(get_monthly_messages(as_of))) # test wrong hour wrong_hour = as_of.replace(hour=5) self.assertEqual(0, len(get_daily_messages(wrong_hour))) # test different day is fine new_day = as_of + timedelta(days=5) self.assertEqual(1, len(get_daily_messages(new_day)))