def test_mailer_does_not_reconnect_if_connected(self, mock_is_alive, mock_reconnect, mock_message): mailer = Mailer() mailer.server = MagicMock() mock_message.return_value = '' mock_is_alive.return_value = True mailer.send(MagicMock()) assert not mock_reconnect.called
def test_mailer_tries_to_reconnect_if_server_disconnected(self, mock_is_alive, mock_reconnect, mock_message): mailer = Mailer() mailer.server = MagicMock() mock_message.return_value = '' mock_is_alive.return_value = False mailer.send(MagicMock()) assert mock_reconnect.called
def test_message_can_contain_subject_with_scandinavian_characters(self): mail = Mail(recipient = '*****@*****.**', sender = '*****@*****.**', body = 'Hello world', subject = 'Hællæ bællå ålø!') message = Mailer.turn_mail_into_message(mail) self.assertEqual('Subject: =?utf-8?b?SMOmbGzDpiBiw6ZsbMOlIMOlbMO4IQ==?=\n' in message, True)
def test_message_contains_body_with_correct_value(self): mail = Mail(recipient = '*****@*****.**', sender = '*****@*****.**', body = 'Hello world', subject = 'Hola!') message = Mailer.turn_mail_into_message(mail) self.assertEqual('\n\nSGVsbG8gd29ybGQ=' in message, True)
def test_message_contains_subject_header_with_correct_value(self): mail = Mail(recipient = '*****@*****.**', sender = '*****@*****.**', body = 'Hello world', subject = 'Hola!') message = Mailer.turn_mail_into_message(mail) self.assertEqual('Subject: =?utf-8?q?Hola!?=\n' in message, True)
def test_message_contains_from_header_with_name_if_provided(self): mail = Mail(recipient = '*****@*****.**', sender = '*****@*****.**', sender_name = 'Billy Bob', body = 'Hello world') message = Mailer.turn_mail_into_message(mail) self.assertEqual('From: Billy Bob <*****@*****.**>\n' in message, True)
def test_message_contains_from_header_with_correct_value(self): mail = Mail(recipient = '*****@*****.**', sender = '*****@*****.**', body = 'Hello world') message = Mailer.turn_mail_into_message(mail) self.assertEqual('From: [email protected]\n' in message, True)