class TestSchedule(TestCase): def setUp(self): self.contact = Contact.objects.create(first_name='John', last_name='Doe') self.goal = Goal.objects.create(contact=self.contact, body='test') self.router = MockRouter() self.app = GoalsApp(router=self.router) def test_future_start_date(self): """ date_next_notified should equal schedule_start_date if in future """ now = datetime.datetime.now() delta = relativedelta(days=+1) self.goal.schedule_start_date = now + delta self.goal.schedule_frequency = 'daily' self.assertEqual(self.goal.get_next_date(), now + delta) def test_near_past(self): """ date_next_notified should equal schedule_start_date if in future """ now = datetime.datetime.now() delta = relativedelta(days=+1) self.goal.schedule_start_date = now - delta + relativedelta(hours=+1) self.goal.schedule_frequency = 'daily' self.assertEqual(self.goal.get_next_date(), self.goal.schedule_start_date + delta) def test_one_time(self): """ date_next_notified should equal schedule_start_date if one time """ now = datetime.datetime.now() self.goal.schedule_start_date = now self.goal.schedule_frequency = 'one-time' self.assertEqual(self.goal.get_next_date(), self.goal.schedule_start_date) def test_goals_to_send_cron_job(self): """ make sure date_next_notified is updated on cron job """ now = datetime.datetime.now() delta = relativedelta(days=+1, hours=+1) self.goal.schedule_start_date = now - delta self.goal.schedule_frequency = 'daily' self.goal.date_next_notified = now - delta self.goal.save() self.app.status_update() goal = Goal.objects.get(pk=self.goal.pk) self.assertTrue(goal.date_next_notified > self.goal.date_next_notified) def test_no_goals_to_send_cron_job(self): """ make sure only goals with date_next_notified < now are used """ now = datetime.datetime.now() delta = relativedelta(hours=+5) self.goal.schedule_start_date = now + delta self.goal.schedule_frequency = 'daily' self.goal.date_next_notified = now + delta self.goal.save() self.app.status_update() goal = Goal.objects.get(pk=self.goal.pk) self.assertEqual(goal.date_next_notified, self.goal.date_next_notified)
def setUp(self): self.contact = Contact.objects.create(first_name='John', last_name='Doe') self.goal = Goal.objects.create(contact=self.contact, body='test') self.router = MockRouter() self.app = GoalsApp(router=self.router)