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

  1. from smtplib import SMTPServerDisconnected
  2. from unittest.mock import Mock, patch
  3. from django.test import TestCase
  4. from hc.lib.emails import EmailThread
  5. @patch("hc.lib.emails.time.sleep")
  6. class EmailsTestCase(TestCase):
  7. def test_it_retries(self, mock_time):
  8. mock_msg = Mock()
  9. mock_msg.send = Mock(side_effect=[SMTPServerDisconnected, None])
  10. t = EmailThread(mock_msg)
  11. t.run()
  12. self.assertEqual(mock_msg.send.call_count, 2)
  13. def test_it_limits_retries(self, mock_time):
  14. mock_msg = Mock()
  15. mock_msg.send = Mock(side_effect=SMTPServerDisconnected)
  16. with self.assertRaises(SMTPServerDisconnected):
  17. t = EmailThread(mock_msg)
  18. t.run()
  19. self.assertEqual(mock_msg.send.call_count, 3)