示例#1
0
    def test_generate_email_message(self):
        rendered = NewsletterEmailSender._render_newsletter(
            self.released_newsletter_1)
        send_newsletter = NewsletterEmailSender()
        message = send_newsletter._generate_email_message(
            '*****@*****.**', rendered)

        self.assertEqual(message.subject, self.released_newsletter_1.subject)
        self.assertEqual(message.body, rendered['html'])
        self.assertEqual(message.to, ['*****@*****.**'])
示例#2
0
    def test_get_subscriber_emails_return_email_message_instances(self):
        rendered = NewsletterEmailSender._render_newsletter(
            self.released_newsletter_1)
        send_newsletter = NewsletterEmailSender()

        email_msg_generator = send_newsletter._get_batch_email_messages(
            rendered)

        messages = list(next(email_msg_generator))

        self.assertTrue(isinstance(messages[0], mail.EmailMessage))
示例#3
0
    def test_send_email_newsletter_with_no_subscribers(self):
        newsletters = Newsletter.objects.filter(id__in=[
            self.released_newsletter_1.id, self.released_newsletter_2.id
        ])
        self.assertFalse(newsletters.filter(is_sent=True).exists())

        Subscriber.objects.all().update(subscribed=False)
        send_newsletter = NewsletterEmailSender()
        send_newsletter.send_emails()

        self.assertFalse(newsletters.filter(is_sent=True).exists())
示例#4
0
    def test_get_subscriber_emails_with_zero_subscribers(self):
        Subscriber.objects.all().update(subscribed=False)

        rendered = NewsletterEmailSender._render_newsletter(
            self.released_newsletter_1)
        send_newsletter = NewsletterEmailSender()

        email_msg_generator = send_newsletter._get_batch_email_messages(
            rendered)

        with self.assertRaises(StopIteration):
            next(email_msg_generator)
示例#5
0
    def test_get_subscriber_emails(self):
        rendered = NewsletterEmailSender._render_newsletter(
            self.released_newsletter_1)
        send_newsletter = NewsletterEmailSender()
        # set batch size to 2
        send_newsletter.batch_size = 2

        email_msg_generator = send_newsletter._get_batch_email_messages(
            rendered)

        # total five subscribed emails were added in the setUp()
        self.assertEqual(len(list(next(email_msg_generator))), 2)
        self.assertEqual(len(list(next(email_msg_generator))), 2)
        self.assertEqual(len(list(next(email_msg_generator))), 1)
示例#6
0
    def test_render_newsletter(self):
        rendered = NewsletterEmailSender._render_newsletter(
            self.released_newsletter_1)

        self.assertEqual(rendered['subject'],
                         self.released_newsletter_1.subject)
        self.assertEqual(type(rendered), dict)
示例#7
0
 def test_send_email_newsletter_with_error(self, logger):
     send_newsletter = NewsletterEmailSender()
     send_newsletter.connection.send_messages = mock.Mock(
         side_effect=Exception())
     send_newsletter.send_emails()
     logger.error.assert_called()