Ejemplo n.º 1
0
    def test_can_email_hypothesis_evidence_digest(self):
        """Test that we can email a digest containing new hypotheses and evidence."""
        for x in [1, 2]:
            board = create_board(board_title="Board #{}".format(x), days=0)
            BoardFollower.objects.create(
                board=board, user=self.daily,
            )
            hypothesis = Hypothesis.objects.create(
                board=board,
                hypothesis_text="Hypothesis #{}".format(x),
                creator=self.weekly,
            )
            evidence = Evidence.objects.create(
                board=board,
                evidence_desc="Evidence #{}".format(x),
                creator=self.weekly,
            )
            notify_add(board, self.weekly, hypothesis)
            notify_add(board, self.weekly, evidence)

        succeeded, passed, failed = send_digest_emails(DigestFrequency.daily)
        self.assertEqual(succeeded, 1)
        self.assertEqual(len(mail.outbox), 1, "No digest email sent")
        txt_body = mail.outbox[0].body
        logger.info(txt_body)

        for x in [1, 2]:
            self.assertTrue("Board #{}".format(x) in txt_body)
            self.assertTrue("Hypothesis #{}".format(x) in txt_body)
            self.assertTrue("Evidence #{}".format(x) in txt_body)
Ejemplo n.º 2
0
 def handle(self, *args, **options):
     """Handle the command invocation."""
     if options['frequency'] == 'daily':
         self.report(send_digest_emails(DigestFrequency.daily))
     elif options['frequency'] == 'weekly':
         digest_day = getattr(settings, 'DIGEST_WEEKLY_DAY')
         current_day = timezone.now().weekday()
         if current_day == digest_day or options['force']:
             if current_day != digest_day and options['force']:
                 msg = 'Forcing weekly digest to be sent (scheduled=%s, current=%s)' % (digest_day, current_day)
                 self.stdout.write(self.style.WARNING(msg))  # pylint: disable=no-member
             self.report(send_digest_emails(DigestFrequency.weekly))
         else:
             msg = 'Skipping weekly digest until day %s (current=%s)' % (digest_day, current_day)
             self.stdout.write(self.style.WARNING(msg))  # pylint: disable=no-member
     else:
         raise CommandError('Expected frequency "daily" or "weekly"')
Ejemplo n.º 3
0
 def test_can_email_first_daily_digest(self):
     """Test that we can email a digest if the user hasn't received a daily digest before."""
     create_board(board_title='New Board', days=0)
     succeeded, passed, failed = send_digest_emails(DigestFrequency.daily)
     self.assertEqual(succeeded, 1)
     self.assertEqual(passed, 0)
     self.assertEqual(failed, 0)
     self.assertEqual(len(mail.outbox), 1, 'No digest email sent')
     self.assertGreater(len(mail.outbox[0].alternatives), 0, 'No HTML body attached to digest email')
     self.assertListEqual(mail.outbox[0].to, [self.daily.email])
     self.assertEqual(mail.outbox[0].from_email, DEFAULT_FROM_EMAIL)