def test_SMTPReceiver_process_message(): receiver = server.SMTPReceiver(host="localhost", port=0) msg = test_mail_request() with patch("salmon.server.routing.Router") as router_mock, \ patch("salmon.server.undeliverable_message"): response = receiver.process_message(msg.Peer, msg.From, msg.To, str(msg)) assert response is None, response with patch("salmon.server.routing.Router") as router_mock, \ patch("salmon.server.undeliverable_message"): router_mock.deliver.side_effect = Exception() response = receiver.process_message(msg.Peer, msg.From, msg.To, str(msg)) assert response is None, response with patch("salmon.server.routing.Router") as router_mock, \ patch("salmon.server.undeliverable_message"): router_mock.deliver.side_effect = server.SMTPError(450, "Not found") response = receiver.process_message(msg.Peer, msg.From, msg.To, str(msg)) assert_equal(response, "450 Not found") # Python 3's smtpd takes some extra kawrgs, but i we don't care about that at the moment with patch("salmon.server.routing.Router") as router_mock, \ patch("salmon.server.undeliverable_message"): response = receiver.process_message(msg.Peer, msg.From, msg.To, str(msg), mail_options=[], rcpt_options=[]) assert response is None, response
def test_SMTPReceiver(self): receiver = server.SMTPReceiver(port=0) receiver.start() receiver.process_message('localhost', 'test@localhost', 'test@localhost', 'Fake body.') routing.Router.deliver.side_effect = RuntimeError("Raised on purpose") receiver.process_message('localhost', 'test@localhost', 'test@localhost', 'Fake body.') receiver.close()
def test_SMTPReceiver(): receiver = server.SMTPReceiver(port=0) receiver.start() receiver.process_message('localhost', 'test@localhost', 'test@localhost', 'Fake body.') routing.Router.deliver.side_effect = raises_exception receiver.process_message('localhost', 'test@localhost', 'test@localhost', 'Fake body.') receiver.close()
def make_fake_settings(host, port): """ When running as a logging server we need a fake settings module to work with since the logging server can be run in any directory, so there may not be a config/settings.py file to import. """ logging.basicConfig(filename="logs/logger.log", level=logging.DEBUG) routing.Router.load(['salmon.handlers.log', 'salmon.handlers.queue']) settings = imp.new_module('settings') settings.receiver = server.SMTPReceiver(host, port) settings.relay = None logging.info("Logging mode enabled, will not send email to anyone, just log.") return settings
def test_SMTPReceiver_process_message(): receiver = server.SMTPReceiver(host="localhost", port=0) msg = test_mail_request() with patch("salmon.server.routing.Router") as router_mock, \ patch("salmon.server.undeliverable_message"): response = receiver.process_message(msg.Peer, msg.From, msg.To, str(msg)) assert response is None, response with patch("salmon.server.routing.Router") as router_mock, \ patch("salmon.server.undeliverable_message"): router_mock.deliver.side_effect = Exception() response = receiver.process_message(msg.Peer, msg.From, msg.To, str(msg)) assert response is None, response with patch("salmon.server.routing.Router") as router_mock, \ patch("salmon.server.undeliverable_message"): router_mock.deliver.side_effect = server.SMTPError(450, "Not found") response = receiver.process_message(msg.Peer, msg.From, msg.To, str(msg)) assert_equal(response, "450 Not found")
def test_SMTPreceiver(): receiver = server.SMTPReceiver(host="localhost", port=8895) msg = test_mail_request() receiver.process_message(msg.Peer, msg.From, msg.To, str(msg))