| 1 | |
|---|
| 2 | |
|---|
| 3 | '''Test the injection of custom TurboMail transports without setuptools.''' |
|---|
| 4 | |
|---|
| 5 | import logging |
|---|
| 6 | import unittest |
|---|
| 7 | |
|---|
| 8 | from turbomail.api import Manager, Transport |
|---|
| 9 | from turbomail.control import interface |
|---|
| 10 | from turbomail.message import Message |
|---|
| 11 | |
|---|
| 12 | logging.disable(logging.WARNING) |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | class DummyTransport(Transport): |
|---|
| 16 | def deliver(self, message): |
|---|
| 17 | return True |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | class DummyManager(Manager): |
|---|
| 21 | def deliver(self, message): |
|---|
| 22 | return True |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | class TestCustomTransportInjection(unittest.TestCase): |
|---|
| 26 | """Test the injection of custom TurboMail transports without setuptools.""" |
|---|
| 27 | |
|---|
| 28 | def setUp(self): |
|---|
| 29 | self.manager = DummyManager() |
|---|
| 30 | self.transport = DummyTransport() |
|---|
| 31 | self.message = Message(author=("Author", "author@example.com"), |
|---|
| 32 | to=("Recipient", "recipient@example.com"), |
|---|
| 33 | subject="Test message subject.", |
|---|
| 34 | plain="This is a test message.") |
|---|
| 35 | interface.config = {'mail.on': True} |
|---|
| 36 | |
|---|
| 37 | def tearDown(self): |
|---|
| 38 | interface.stop(force=True) |
|---|
| 39 | interface.config = {'mail.on': False} |
|---|
| 40 | |
|---|
| 41 | def test_provide_dict_with_additional_managers_and_transports_which_overrides_setuptools(self): |
|---|
| 42 | interface.config.update({'mail.manager': 'immediate', |
|---|
| 43 | 'mail.transport': 'foo',}) |
|---|
| 44 | interface.start(extra_classes=dict(immediate=self.manager, foo=self.transport)) |
|---|
| 45 | self.assertEqual(self.manager, interface.manager) |
|---|
| 46 | self.assertEqual(self.transport, interface.transport) |
|---|
| 47 | interface.send(self.message) |
|---|
| 48 | |
|---|
| 49 | def test_dont_fail_if_no_extra_classes_were_provided(self): |
|---|
| 50 | interface.start() |
|---|
| 51 | |
|---|