Update docs with information about how to use thread-unsafe code in
[salmon.git] / tests / test_handler.py
blob5f9ff5bb58a5acf789b456fd03fd68e1b025799a
1 from unittest.mock import Mock
2 import sys
4 from salmon import mail, utils
5 from salmon.routing import Router
7 from .setup_env import SalmonTestCase
9 sample_message = """From: someone@localhost
10 To: someone@localhost
12 Test
13 """
16 def create_message():
17 return mail.MailRequest("localhost", "someone@localhost", "someone@localhost", sample_message)
20 class HandlerTestCase(SalmonTestCase):
21 def tearDown(self):
22 Router.clear_routes()
23 Router.clear_states()
24 for key in Router.HANDLERS.keys():
25 del sys.modules[key]
26 Router.HANDLERS.clear()
27 utils.settings = None
29 def test_log_handler(self):
30 import salmon.handlers.log # noqa
31 Router.deliver(create_message())
33 def test_queue_handler(self):
34 import salmon.handlers.queue # noqa
35 Router.deliver(create_message())
37 def test_forward(self):
38 utils.import_settings(False)
40 import salmon.handlers.forward # noqa
41 salmon.handlers.forward.settings.relay = Mock()
42 Router.deliver(create_message())
44 self.assertEqual(salmon.handlers.forward.settings.relay.deliver.call_count, 1)