You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

27 lines
780 B

from smtplib import SMTPServerDisconnected
from unittest.mock import Mock, patch
from django.test import TestCase
from hc.lib.emails import EmailThread
@patch("hc.lib.emails.time.sleep")
class EmailsTestCase(TestCase):
def test_it_retries(self, mock_time):
mock_msg = Mock()
mock_msg.send = Mock(side_effect=[SMTPServerDisconnected, None])
t = EmailThread(mock_msg)
t.run()
self.assertEqual(mock_msg.send.call_count, 2)
def test_it_limits_retries(self, mock_time):
mock_msg = Mock()
mock_msg.send = Mock(side_effect=SMTPServerDisconnected)
with self.assertRaises(SMTPServerDisconnected):
t = EmailThread(mock_msg)
t.run()
self.assertEqual(mock_msg.send.call_count, 3)