def test_04_wrap_jobs(self): wrapped = wrap_job("test.my_send_mail", True) with mock.patch.object(SENDER, 'send_mail') as mock_mail: result = wrapped("hi") mock_mail.assert_called_once_with("hi") self.assertTrue(result) with mock.patch.object(SENDER, 'send_mail') as mock_mail: result = my_send_mail("hi") mock_mail.assert_called_once_with("hi") self.assertEqual(result, 1337)
def send_or_enqueue_email(config, recipient, subject, body, sender=None, reply_to=None, mimetype="plain"): """ According to the value of ``config["enqueue_job"]``, send the email directly or send a job to the queue (if a queue is configured). See ``SMTPServer.test_email`` for parameters. :return: True if the job is sent to the queue, return value of ``SMTPServer.test_email`` otherwise """ if has_job_queue() and config.get("enqueue_job", False): send = wrap_job(SEND_EMAIL_JOB_NAME, True) else: send = SMTPServer.test_email return send(config, recipient, subject, body, sender, reply_to, mimetype)