root / trunk / tests / test_custom_transport_injection.py

Revision 117, 1.7 kB (checked in by fs, 2 months ago)

renamed providers to transports which reflects the real purpose better

Line 
1#!/usr/bin/env python
2# -*- coding: UTF-8 -*-
3'''Test the injection of custom TurboMail transports without setuptools.'''
4
5import logging
6import unittest
7
8from turbomail.api import Manager, Transport
9from turbomail.control import interface
10from turbomail.message import Message
11
12logging.disable(logging.WARNING)
13
14
15class DummyTransport(Transport):
16    def deliver(self, message):
17        return True
18
19
20class DummyManager(Manager):
21    def deliver(self, message):
22        return True
23
24
25class 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
Note: See TracBrowser for help on using the browser.