def test_mail_process(settings): settings.EMAIL_BACKEND = "djrill.mail.backends.djrill.DjrillBackend" with mock.patch('django.core.mail.EmailMultiAlternatives') as mock_mail: mock_mail.return_value.mandrill_response = [{ "email": "*****@*****.**", "status": "sent", "_id": "123", "reject_reason": None, }] template = MailTemplateFactory(template_type=MailTemplate.MANDRILL) message = MessageFactory( template=template, content_object=EnquiryFactory(), ) m1 = MailFactory(message=message) m2 = MailFactory(message=message, retry_count=9) MailFactory(message=message, retry_count=11) m4 = MailFactory(message=message) m5 = MailFactory(message=message, retry_count=0) m6 = MailFactory(message=message, retry_count=1) MailFactory(message=message, retry_count=99) sent = _mail_process() assert [m1.pk, m2.pk, m4.pk, m5.pk, m6.pk] == sent m1.refresh_from_db() assert '123' == m1.sent_response_code
def test_mail_select_and_send_rejected_again(): with mock.patch('django.core.mail.EmailMultiAlternatives') as mock_mail: mock_mail.return_value.mandrill_response = [{ "email": "*****@*****.**", "status": "rejected", "_id": "123", "reject_reason": "hard-bounce" }] template = MailTemplateFactory(template_type=MailTemplate.MANDRILL) message = MessageFactory( template=template, content_object=EnquiryFactory(), ) obj = MailFactory(message=message, retry_count=4) _mail_select_and_send([obj.pk]) obj.refresh_from_db() assert 5 == obj.retry_count