def test_relay(self, smtp_mock): relay_obj = relay(port=0) smtp_mock.return_value = Mock() relay_obj.send('test@localhost', 'zedshaw@localhost', 'Test message', 'Test body') self.assertEqual(smtp_mock.return_value.sendmail.call_count, 1) self.assertEqual(smtp_mock.return_value.quit.call_count, 1)
def test_ConfirmationEngine_send(smtp_mock): smtp_mock.return_value = Mock() Queue("run/queue").clear() engine.clear() list_name = "testing" action = "subscribing to" host = "localhost" message = mail.MailRequest("fakepeer", "somedude@localhost", "testing-subscribe@localhost", "Fake body.") engine.send(relay(port=8899), "testing", message, "confirmation.msg", locals()) assert smtp_mock.return_value.sendmail.called assert smtp_mock.return_value.quit.called assert delivered("somedude", to_queue=engine.pending) return smtp_mock.return_value.sendmail.call_args[0][2]
def test_ConfirmationEngine_send(self, smtp_mock): smtp_mock.return_value = Mock() Queue('run/queue').clear() self.engine.clear() list_name = 'testing' action = 'subscribing to' host = 'localhost' message = mail.MailRequest('fakepeer', 'somedude@localhost', 'testing-subscribe@localhost', 'Fake body.') self.engine.send(relay(port=0), 'testing', message, 'confirmation.msg', locals()) self.assertEqual(smtp_mock.return_value.sendmail.call_count, 1) self.assertEqual(smtp_mock.return_value.quit.call_count, 1) assert delivered('somedude', to_queue=self.engine.pending) return smtp_mock.return_value.sendmail.call_args[0][2]
def test_ConfirmationEngine_send(smtp_mock): smtp_mock.return_value = Mock() Queue('run/queue').clear() engine.clear() list_name = 'testing' action = 'subscribing to' host = 'localhost' message = mail.MailRequest('fakepeer', 'somedude@localhost', 'testing-subscribe@localhost', 'Fake body.') engine.send(relay(port=8899), 'testing', message, 'confirmation.msg', locals()) assert smtp_mock.return_value.sendmail.called assert smtp_mock.return_value.quit.called assert delivered('somedude', to_queue=engine.pending) return smtp_mock.return_value.sendmail.call_args[0][2]
from salmon.testing import RouterConversation, queue, relay relay = relay(port=8823) client = RouterConversation("somedude@localhost", "requests_tests") confirm_format = "testing-confirm-[0-9]+@" noreply_format = "testing-noreply@" def test_forwards_relay_host(): """ !!!!!! YOU MUST CONFIGURE YOUR config/settings.py OR THIS WILL FAIL !!!!!! Makes sure that your config/settings.py is configured to forward mail from localhost (or your direct host) to your relay. """ client.begin() client.say("tester@localhost", "Test that forward works.", "tester@localhost") def test_drops_open_relay_messages(): """ But, make sure that mail NOT for test.com gets dropped silently. """ client.begin() client.say("*****@*****.**", "Relay should not happen") assert len(queue()) == 0, "You are configured currently to accept everything. " \ "You should change config/settings.py router_defaults " \ "so host is your actual host name that will receive mail."
from mock import Mock, patch from nose.tools import assert_equal, with_setup from salmon.testing import ( RouterConversation, assert_in_state, clear_queue, delivered, queue, relay, ) from .setup_env import setup_salmon_dirs, teardown_salmon_dirs relay = relay(port=0) @with_setup(setup_salmon_dirs, teardown_salmon_dirs) def test_clear_queue(): queue().push("Test") assert_equal(queue().count(), 1) clear_queue() assert_equal(queue().count(), 0) @patch("smtplib.SMTP") @with_setup(setup_salmon_dirs, teardown_salmon_dirs) def test_relay(smtp_mock): smtp_mock.return_value = Mock()
from mock import Mock, patch from nose.tools import with_setup from salmon.testing import ( RouterConversation, assert_in_state, clear_queue, delivered, queue, relay, spelling, ) from .setup_env import setup_salmon_dirs, teardown_salmon_dirs relay = relay(port=8899) @with_setup(setup_salmon_dirs, teardown_salmon_dirs) def test_clear_queue(): queue().push("Test") assert queue().count() > 0 clear_queue() assert queue().count() == 0 @patch("smtplib.SMTP") @with_setup(setup_salmon_dirs, teardown_salmon_dirs) def test_relay(smtp_mock): smtp_mock.return_value = Mock()
from mock import Mock, patch from nose.tools import assert_equal, with_setup from salmon.testing import RouterConversation, assert_in_state, clear_queue, delivered, queue, relay from .setup_env import setup_salmon_dirs, teardown_salmon_dirs relay = relay(port=0) @with_setup(setup_salmon_dirs, teardown_salmon_dirs) def test_clear_queue(): queue().push("Test") assert_equal(queue().count(), 1) clear_queue() assert_equal(queue().count(), 0) @patch("smtplib.SMTP") @with_setup(setup_salmon_dirs, teardown_salmon_dirs) def test_relay(smtp_mock): smtp_mock.return_value = Mock() relay.send('test@localhost', 'zedshaw@localhost', 'Test message', 'Test body') assert_equal(smtp_mock.return_value.sendmail.call_count, 1) assert_equal(smtp_mock.return_value.quit.call_count, 1) @with_setup(setup_salmon_dirs, teardown_salmon_dirs)
from nose.tools import * # noqa from salmon.testing import RouterConversation, queue, relay relay = relay(port=8823) client = RouterConversation("somedude@localhost", "requests_tests") confirm_format = "testing-confirm-[0-9]+@" noreply_format = "testing-noreply@" def test_forwards_relay_host(): """ !!!!!! YOU MUST CONFIGURE YOUR config/settings.py OR THIS WILL FAIL !!!!!! Makes sure that your config/settings.py is configured to forward mail from localhost (or your direct host) to your relay. """ client.begin() client.say("tester@localhost", "Test that forward works.", "tester@localhost") def test_drops_open_relay_messages(): """ But, make sure that mail NOT for test.com gets dropped silently. """ client.begin() client.say("*****@*****.**", "Relay should not happen") assert queue().count() == 0, "You are configured currently to accept everything. " \ "You should change config/settings.py router_defaults " \ "so host is your actual host name that will receive mail."
from nose.tools import with_setup from salmon.testing import ( RouterConversation, assert_in_state, clear_queue, delivered, queue, relay, spelling, ) from .setup_env import setup_salmon_dirs, teardown_salmon_dirs relay = relay(port=8899) @with_setup(setup_salmon_dirs, teardown_salmon_dirs) def test_clear_queue(): queue().push("Test") assert queue().count() > 0 clear_queue() assert queue().count() == 0 @patch("smtplib.SMTP") @with_setup(setup_salmon_dirs, teardown_salmon_dirs) def test_relay(smtp_mock): smtp_mock.return_value = Mock()