示例#1
0
 def handle(self, *args, **kwargs):
     """
     Send all pending habit reminders. This command should be called on a
     cronjob once an hour (ideally shortly after the top of the hour).
     """
     now = timezone.now().replace(minute=0, second=0, microsecond=0)
     for habit in Habit.scheduled_for_reminder(now.weekday(), now.hour):
         # Only send the reminder if either
         #   a) the habit has never had any reminders send for it
         #   b) the habit last had a reminder sent at least an hour ago
         if habit.reminder_last_sent is None or habit.reminder_last_sent < now:
             habit.reminder_last_sent = now
             habit.save()
             send_reminder_email(habit)
示例#2
0
 def handle(self, *args, **kwargs):
     """
     Send all pending habit reminders. This command should be called on a
     cronjob once an hour (ideally shortly after the top of the hour).
     """
     now = timezone.now().replace(minute=0, second=0, microsecond=0)
     for habit in Habit.scheduled_for_reminder(now.weekday(), now.hour):
         # Only send the reminder if either
         #   a) the habit has never had any reminders send for it
         #   b) the habit last had a reminder sent at least an hour ago
         if habit.reminder_last_sent is None or habit.reminder_last_sent < now:
             habit.reminder_last_sent = now
             habit.save()
             send_reminder_email(habit)
示例#3
0
    def test_send_reminder_email_for_archived_habit(self):
        self.h.archived = True

        result = send_reminder_email(self.h)

        self.assertIsNone(result)
        self.assertEqual(len(mail.outbox), 0)
示例#4
0
    def test_send_reminder_email_for_archived_habit(self):
        self.h.archived = True

        result = send_reminder_email(self.h)

        self.assertIsNone(result)
        self.assertEqual(len(mail.outbox), 0)
示例#5
0
    def test_send_reminder_email(self):
        send_reminder_email(self.h)

        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue('Frobble your wingdangle' in mail.outbox[0].subject)
示例#6
0
    def test_send_reminder_email(self):
        send_reminder_email(self.h)

        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue('Frobble your wingdangle' in mail.outbox[0].subject)