Beispiel #1
0
    def test_resend(self):
        # Test resend enables queue
        with self.settings(MAILER_EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend"):
            q = Queue.objects.create(pk=1, name="test", mail_enabled=False)
            q1 = Queue.objects.create(pk=2, name="test1", mail_enabled=True)

            mailer.send_mail("Subject", "Body", "*****@*****.**", ["*****@*****.**"], queue=1)
            self.assertEqual(Message.objects.count(), 1)
            self.assertEqual(Message.objects.filter(queue=q).count(), 1)

            mailer.send_mail("Subject", "Body", "*****@*****.**", ["*****@*****.**"], queue=2)
            self.assertEqual(Message.objects.count(), 2)
            self.assertEqual(Message.objects.filter(queue=q1).count(), 1)

            engine.send_all()

            self.assertEqual(Message.objects.count(), 1)
            self.assertEqual(Message.objects.deferred().count(), 1)
            self.assertEqual(MessageLog.objects.count(), 1)

            date = datetime.datetime.now() - datetime.timedelta(minutes=15)
            engine.resend(['test'], date.strftime("%Y-%m-%d %H:%M"))

            q = Queue.objects.get(pk=1)

            self.assertEqual(q.mail_enabled, True)
            self.assertEqual(Message.objects.count(), 1)
            self.assertEqual(Message.objects.filter(queue=q).count(), 1)
            self.assertEqual(Message.objects.deferred().count(), 0)
Beispiel #2
0
 def test_resend_no_queue_found(self):
     # Test queue not found on resend
     with self.settings(MAILER_EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend"):
         res = mailer.send_mail('sub', 'body', '*****@*****.**', ['*****@*****.**'], queue=1)
         self.assertEqual(res, 0)
     with patch('logging.warning') as warn:
         engine.resend(['notest'])
         warn.assert_called_once_with('Queue notest not found')
Beispiel #3
0
    def test_resend_no_time(self):
        # Test resend renables queue with no time option
        with self.settings(MAILER_EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend"):
            Queue.objects.create(pk=1, name="test", mail_enabled=False)
            q1 = Queue.objects.create(pk=2, name="test1", mail_enabled=False)

            mailer.send_mail("Subject", "Body", "*****@*****.**", ["*****@*****.**"], queue=2)
            self.assertEqual(Message.objects.count(), 1)
            self.assertEqual(Message.objects.filter(queue=q1).count(), 1)

            mailer.send_mail("Subject", "Body", "*****@*****.**", ["*****@*****.**"], queue=2)
            self.assertEqual(Message.objects.count(), 2)
            self.assertEqual(Message.objects.filter(queue=q1).count(), 2)

            engine.send_all()

            self.assertEqual(Message.objects.count(), 2)
            self.assertEqual(Message.objects.deferred().count(), 2)

            engine.resend(['test', 'test1'])

            self.assertEqual(Message.objects.deferred().count(), 0)
            self.assertEqual(Message.objects.count(), 2)
 def handle(self, *args, **options):
     if 'send_from' in options:
         resend(options['queue'], options['send_from'])
     else:
         resend(options['queue'])