示例#1
0
    def test_send_multiple_email_dicts(self):
        """ It should accept and send a list of EmailMessage dicts. """
        N = 10
        msgs = [mail.EmailMessage() for i in range(N)]
        tasks.send_emails(msgs, backend_kwargs={})

        self.assertEqual(len(mail.outbox), N)
        for i in range(N):
            self.assertEqual(email_to_dict(msgs[i]), email_to_dict(mail.outbox[i]))
示例#2
0
    def test_send_multiple_email_dicts(self):
        """ It should accept and send a list of EmailMessage dicts. """
        N = 10
        msgs = [mail.EmailMessage() for i in range(N)]
        tasks.send_emails(msgs, backend_kwargs={})

        self.assertEqual(len(mail.outbox), N)
        for i in range(N):
            self.assertEqual(email_to_dict(msgs[i]), email_to_dict(mail.outbox[i]))
示例#3
0
 def test_send_multiple_email_dicts_response(self):
     """ It should return the number of messages sent. """
     N = 10
     msgs = [mail.EmailMessage() for i in range(N)]
     messages_sent = tasks.send_emails(msgs, backend_kwargs={})
     self.assertEqual(messages_sent, N)
     self.assertEqual(len(mail.outbox), N)
示例#4
0
 def test_send_multiple_email_dicts_response(self):
     """ It should return the number of messages sent. """
     N = 10
     msgs = [mail.EmailMessage() for i in range(N)]
     messages_sent = tasks.send_emails(msgs, backend_kwargs={})
     self.assertEqual(messages_sent, N)
     self.assertEqual(len(mail.outbox), N)
示例#5
0
    def test_send_multiple_emails(self):
        N = 10
        msgs = [mail.EmailMessage(subject="msg %d" % i) for i in range(N)]
        tasks.send_emails(msgs, backend_kwargs={'foo': 'bar'})

        # Assert that only "odd"/good messages have been sent.
        self.assertEqual(len(mail.outbox), 5)
        self.assertEqual(
            [msg.subject for msg in mail.outbox],
            ["msg 1", "msg 3", "msg 5", "msg 7", "msg 9"]
        )

        # Assert that "even"/bad messages have been requeued,
        # one retry task per bad message.
        self.assertEqual(len(self._retry_calls), 5)
        odd_msgs = [msg for idx, msg in enumerate(msgs) if even(idx)]
        for msg, (args, kwargs) in zip(odd_msgs, self._retry_calls):
            retry_args = args[0]
            self.assertEqual(retry_args, [[msg], {'foo': 'bar'}])
            self.assertTrue(isinstance(kwargs.get('exc'), RuntimeError))
            self.assertFalse(kwargs.get('throw', True))
示例#6
0
    def test_send_multiple_emails(self):
        N = 10
        msgs = [mail.EmailMessage(subject="msg %d" % i) for i in range(N)]
        tasks.send_emails([email_to_dict(msg) for msg in msgs],
                          backend_kwargs={'foo': 'bar'})

        # Assert that only "odd"/good messages have been sent.
        self.assertEqual(len(mail.outbox), 5)
        self.assertEqual([msg.subject for msg in mail.outbox],
                         ["msg 1", "msg 3", "msg 5", "msg 7", "msg 9"])

        # Assert that "even"/bad messages have been requeued,
        # one retry task per bad message.
        self.assertEqual(len(self._retry_calls), 5)
        odd_msgs = [msg for idx, msg in enumerate(msgs) if even(idx)]
        for msg, (args, kwargs) in zip(odd_msgs, self._retry_calls):
            retry_args = args[0]
            self.assertEqual(retry_args, [[email_to_dict(msg)], {
                'foo': 'bar'
            }])
            self.assertTrue(isinstance(kwargs.get('exc'), RuntimeError))
            self.assertFalse(kwargs.get('throw', True))
示例#7
0
 def test_backend_parameters(self):
     """ It should pass kwargs like username and password to the backend. """
     TracingBackend.kwargs = None
     msg = mail.EmailMessage()
     tasks.send_emails(msg, backend_kwargs={'foo': 'bar'})
     self.assertEqual(TracingBackend.kwargs.get('foo'), 'bar')
示例#8
0
 def test_uses_correct_backend(self):
     """ It should use the backend configured in CELERY_EMAIL_BACKEND. """
     TracingBackend.called = False
     msg = mail.EmailMessage()
     tasks.send_emails(msg, backend_kwargs={})
     self.assertTrue(TracingBackend.called)