Exemplo n.º 1
0
    def test_basic(self, mock_smtp):
        # send a message
        mail._send_email('hello', 'stuff', '*****@*****.**')
        mock_smtp.assert_called_once_with(host=config.get('email', 'host'),
            port=config.getint('email', 'port'))

        # verify
        mock_sendmail = mock_smtp.return_value.sendmail
        self.assertEqual(mock_sendmail.call_count, 1)
        self.assertEqual(mock_sendmail.call_args[0][0],
            config.get('email', 'from'))
        self.assertEqual(mock_sendmail.call_args[0][1], '*****@*****.**')

        # verify message attributes
        message = Parser().parsestr(mock_sendmail.call_args[0][2])
        self.assertEqual(message.get_payload(), 'stuff')
        self.assertEqual(message.get('Subject', None), 'hello')
        self.assertEqual(message.get('From', None), config.get('email', 'from'))
        self.assertEqual(message.get('To', None), '*****@*****.**')
Exemplo n.º 2
0
    def test_basic(self, mock_smtp):
        # send a message
        mail._send_email('hello', 'stuff', '*****@*****.**')
        mock_smtp.assert_called_once_with(host=config.get('email', 'host'),
                                          port=config.getint('email', 'port'))

        # verify
        mock_sendmail = mock_smtp.return_value.sendmail
        self.assertEqual(mock_sendmail.call_count, 1)
        self.assertEqual(mock_sendmail.call_args[0][0],
                         config.get('email', 'from'))
        self.assertEqual(mock_sendmail.call_args[0][1], '*****@*****.**')

        # verify message attributes
        message = Parser().parsestr(mock_sendmail.call_args[0][2])
        self.assertEqual(message.get_payload(), 'stuff')
        self.assertEqual(message.get('Subject', None), 'hello')
        self.assertEqual(message.get('From', None), config.get('email', 'from'))
        self.assertEqual(message.get('To', None), '*****@*****.**')
Exemplo n.º 3
0
 def test_send_failure(self, mock_error, mock_smtp):
     mock_smtp.return_value.sendmail.side_effect = smtplib.SMTPRecipientsRefused(['*****@*****.**'])
     mail._send_email('hello', 'stuff', '*****@*****.**')
     self.assertTrue(mock_error.called)
Exemplo n.º 4
0
 def test_connect_failure(self, mock_error, mock_smtp):
     mock_smtp.side_effect = smtplib.SMTPConnectError(123, 'aww crap')
     mail._send_email('hello', 'stuff', '*****@*****.**')
     self.assertTrue(mock_error.called)
Exemplo n.º 5
0
 def test_send_failure(self, mock_error, mock_smtp):
     mock_smtp.return_value.sendmail.side_effect = smtplib.SMTPRecipientsRefused(
         ['*****@*****.**'])
     mail._send_email('hello', 'stuff', '*****@*****.**')
     self.assertTrue(mock_error.called)
Exemplo n.º 6
0
 def test_connect_failure(self, mock_error, mock_smtp):
     mock_smtp.side_effect = smtplib.SMTPConnectError(123, 'aww crap')
     mail._send_email('hello', 'stuff', '*****@*****.**')
     self.assertTrue(mock_error.called)