| 1 | |
|---|
| 2 | |
|---|
| 3 | '''Test that most interfaces of TurboMail 2.x are working in TurboMail 3.x''' |
|---|
| 4 | |
|---|
| 5 | import unittest |
|---|
| 6 | import warnings |
|---|
| 7 | |
|---|
| 8 | import turbomail |
|---|
| 9 | from turbomail import Message, MailNotEnabledException |
|---|
| 10 | from turbomail.managers.immediate import ImmediateManager |
|---|
| 11 | from turbomail.transports.debug import DebugTransportFactory |
|---|
| 12 | |
|---|
| 13 | class TestTurboMail2xCompatibility(unittest.TestCase): |
|---|
| 14 | |
|---|
| 15 | def setUp(self): |
|---|
| 16 | warnings.filterwarnings('ignore', 'Property ".+" is deprecated.*', |
|---|
| 17 | category=DeprecationWarning) |
|---|
| 18 | warnings.filterwarnings('ignore', 'Please specify the author using.*', |
|---|
| 19 | category=DeprecationWarning) |
|---|
| 20 | |
|---|
| 21 | def tearDown(self): |
|---|
| 22 | turbomail.control.interface.stop(force=True) |
|---|
| 23 | turbomail.control.interface.config = {'mail.on': False} |
|---|
| 24 | warnings.resetwarnings() |
|---|
| 25 | |
|---|
| 26 | def test_message_instantiation_with_positional_parameters(self): |
|---|
| 27 | message = Message('from@example.com', 'to@example.com', 'Test') |
|---|
| 28 | message.plain = 'Hello world!' |
|---|
| 29 | msg_string = str(message) |
|---|
| 30 | self.failUnless('From: from@example.com' in msg_string) |
|---|
| 31 | self.failUnless('To: to@example.com' in msg_string) |
|---|
| 32 | self.failUnless('Subject: Test' in msg_string) |
|---|
| 33 | |
|---|
| 34 | def test_message_instantiation_with_keyword_parameters(self): |
|---|
| 35 | message = Message(sender='from@example.com', recipient='to@example.com', |
|---|
| 36 | subject='Test') |
|---|
| 37 | message.plain = 'Hello world!' |
|---|
| 38 | msg_string = str(message) |
|---|
| 39 | self.failUnless('From: from@example.com' in msg_string) |
|---|
| 40 | self.failUnless('To: to@example.com' in msg_string) |
|---|
| 41 | self.failUnless('Subject: Test' in msg_string) |
|---|
| 42 | |
|---|
| 43 | def test_message_instantiation_with_tuples(self): |
|---|
| 44 | message = Message(('Foo Bar', 'from@example.com'), |
|---|
| 45 | ('To', 'to@example.com'), 'Test') |
|---|
| 46 | message.plain = 'Hello world!' |
|---|
| 47 | msg_string = str(message) |
|---|
| 48 | self.failUnless('From: Foo Bar <from@example.com>' in msg_string) |
|---|
| 49 | self.failUnless('To: To <to@example.com>' in msg_string) |
|---|
| 50 | self.failUnless('Subject: Test' in msg_string) |
|---|
| 51 | |
|---|
| 52 | def test_message_enqueue_not_enabled(self): |
|---|
| 53 | message = Message('from@example.com', 'to@example.com', 'Test') |
|---|
| 54 | message.plain = 'Hello world!' |
|---|
| 55 | self.assertRaises(MailNotEnabledException, turbomail.enqueue, message) |
|---|
| 56 | |
|---|
| 57 | def test_message_enqueue(self): |
|---|
| 58 | turbomail.control.interface.config = {'mail.on': True} |
|---|
| 59 | fake_setuptools = {'immediate': ImmediateManager, |
|---|
| 60 | 'debug': DebugTransportFactory} |
|---|
| 61 | turbomail.control.interface.start(extra_classes=fake_setuptools) |
|---|
| 62 | |
|---|
| 63 | message = Message('from@example.com', 'to@example.com', 'Test') |
|---|
| 64 | message.plain = 'Hello world!' |
|---|
| 65 | warnings.filterwarnings('ignore', '.*enqueue.*', category=DeprecationWarning) |
|---|
| 66 | turbomail.enqueue(message) |
|---|
| 67 | |
|---|
| 68 | def test_message_plain_text_as_callable(self): |
|---|
| 69 | message = Message('from@example.com', 'to@example.com', 'Test') |
|---|
| 70 | message.plain = lambda: 'Hello world!' |
|---|
| 71 | msg_string = str(message) |
|---|
| 72 | self.failUnless('Hello world!' in msg_string) |
|---|
| 73 | |
|---|
| 74 | def test_message_properties(self): |
|---|
| 75 | message = Message('from@example.com', 'to@example.com', 'Test') |
|---|
| 76 | message.plain = 'Hello world!' |
|---|
| 77 | |
|---|
| 78 | property_names = ['bcc', 'cc', 'date', 'disposition', 'encoding', |
|---|
| 79 | 'headers', 'organization', 'plain', 'priority', |
|---|
| 80 | 'recipient', 'replyto', 'rich', 'sender', 'smtpfrom', |
|---|
| 81 | 'subject'] |
|---|
| 82 | for name in property_names: |
|---|
| 83 | getattr(message, name) |
|---|
| 84 | |
|---|
| 85 | args = dict(zip(property_names, ['foo@example.com'] * len(property_names))) |
|---|
| 86 | Message(**args) |
|---|
| 87 | |
|---|
| 88 | def test_use_deprecated_smtp_from(self): |
|---|
| 89 | message = Message(smtpfrom='smtpfrom@example.com') |
|---|
| 90 | self.assertEqual('smtpfrom@example.com', str(message.smtp_from)) |
|---|
| 91 | self.assertEqual(message.smtpfrom, message.smtp_from) |
|---|
| 92 | message.smtpfrom = 'smtp_from@example.com' |
|---|
| 93 | self.assertEqual('smtp_from@example.com', str(message.smtp_from)) |
|---|
| 94 | self.assertEqual(message.smtpfrom, message.smtp_from) |
|---|
| 95 | |
|---|
| 96 | def test_use_deprecated_reply_to(self): |
|---|
| 97 | message = Message(replyto='replyto@example.com') |
|---|
| 98 | self.assertEqual('replyto@example.com', str(message.reply_to)) |
|---|
| 99 | self.assertEqual(message.replyto, message.reply_to) |
|---|
| 100 | message.replyto = 'reply_to@example.com' |
|---|
| 101 | self.assertEqual('reply_to@example.com', str(message.reply_to)) |
|---|
| 102 | self.assertEqual(message.replyto, message.reply_to) |
|---|
| 103 | |
|---|
| 104 | def test_use_deprecated_recipient(self): |
|---|
| 105 | message = Message(recipient='recipient@example.com') |
|---|
| 106 | self.assertEqual('recipient@example.com', str(message.to)) |
|---|
| 107 | self.assertEqual(message.recipient, message.to) |
|---|
| 108 | message.recipient = 'to@example.com' |
|---|
| 109 | self.assertEqual('to@example.com', str(message.to)) |
|---|
| 110 | self.assertEqual(message.recipient, message.to) |
|---|
| 111 | |
|---|
| 112 | def test_use_sender_for_author_if_no_author_given(self): |
|---|
| 113 | message = Message(sender='sender@example.com', to='to@example.com', |
|---|
| 114 | subject='Test') |
|---|
| 115 | self.assertEqual('sender@example.com', str(message.sender)) |
|---|
| 116 | message.plain = 'Hello world!' |
|---|
| 117 | msg_string = str(message) |
|---|
| 118 | self.failUnless('From: sender@example.com' in msg_string) |
|---|
| 119 | self.failUnless('To: to@example.com' in msg_string) |
|---|
| 120 | self.failUnless('Subject: Test' in msg_string) |
|---|
| 121 | self.failIf('Sender: ' in msg_string) |
|---|
| 122 | self.assertEqual('sender@example.com', str(message.sender)) |
|---|
| 123 | |
|---|
| 124 | |
|---|