class EmailModuleFuncTest(unittest.TestCase): def setUp(self): self.controller = QueueController("localhost", 9025) self.controller.start() def tearDown(self): self.controller.stop() def test_warnings(self): email._mailer = None with warnings.catch_warnings(record=True): warnings.simplefilter("error") self.assertRaises(UserWarning, email.send_email, "*****@*****.**", "*****@*****.**", "test subject", "test body") self.assertRaises(UserWarning, email.send_html_email, "*****@*****.**", "*****@*****.**", "test subject", "plain body", "<p>html body</p>") def test_send_email(self): email.configure({"host": "localhost", "port": 9025}) body = "This is the bloody test body" email.send_email("*****@*****.**", "*****@*****.**", "test subject", body) message = list(self.controller)[0] (from_str, from_cs) = decode_header(message["From"])[0] (to_str, to_cs) = decode_header(message["To"])[0] (subject_str, subject_cs) = decode_header(message["Subject"])[0] self.assertEqual("*****@*****.**", from_str) self.assertEqual("*****@*****.**", to_str) self.assertEqual("test subject", subject_str) self.assertEqual(body, unicode(message.get_payload(decode=True), message.get_content_charset())) def test_send_html_email(self): email.configure({"host": "localhost", "port": 9025}) text = u"This is the bloody test body" html = u"<p>This is the bloody test body</p>" email.send_html_email("*****@*****.**", "*****@*****.**", "test subject", text, html) message = list(self.controller)[0] (from_str, from_cs) = decode_header(message["From"])[0] (to_str, to_cs) = decode_header(message["To"])[0] (subject_str, subject_cs) = decode_header(message["Subject"])[0] self.assertEqual("*****@*****.**", from_str) self.assertEqual("*****@*****.**", to_str) self.assertEqual("test subject", subject_str) self.assertEqual(text, unicode(message.get_payload(0).get_payload(decode=True), message.get_payload(0).get_content_charset())) self.assertEqual("text/plain", message.get_payload(0).get_content_type()) self.assertEqual(html, unicode(message.get_payload(1).get_payload(decode=True), message.get_payload(1).get_content_charset())) self.assertEqual("text/html", message.get_payload(1).get_content_type())
class MailerTest(unittest.TestCase): def setUp(self): self.controller = QueueController("localhost", 9025) self.controller.start() def tearDown(self): self.controller.stop() def test_send_email(self): mailer = Mailer("localhost", 9025) body = "This is the bloody test body" mailer.send_email("*****@*****.**", "*****@*****.**", "test subject", body) message = list(self.controller)[0] (from_str, from_cs) = decode_header(message["From"])[0] (to_str, to_cs) = decode_header(message["To"])[0] (subject_str, subject_cs) = decode_header(message["Subject"])[0] self.assertEqual("*****@*****.**", from_str) self.assertEqual("*****@*****.**", to_str) self.assertEqual("test subject", subject_str) self.assertEqual( body, unicode(message.get_payload(decode=True), message.get_content_charset())) def test_send_html_email(self): mailer = Mailer("localhost", 9025) text = u"This is the bloody test body" html = u"<p>This is the bloody test body</p>" mailer.send_html_email("*****@*****.**", "*****@*****.**", "test subject", text, html) message = list(self.controller)[0] (from_str, from_cs) = decode_header(message["From"])[0] (to_str, to_cs) = decode_header(message["To"])[0] (subject_str, subject_cs) = decode_header(message["Subject"])[0] self.assertEqual("*****@*****.**", from_str) self.assertEqual("*****@*****.**", to_str) self.assertEqual("test subject", subject_str) self.assertEqual( text, unicode( message.get_payload(0).get_payload(decode=True), message.get_payload(0).get_content_charset())) self.assertEqual("text/plain", message.get_payload(0).get_content_type()) self.assertEqual( html, unicode( message.get_payload(1).get_payload(decode=True), message.get_payload(1).get_content_charset())) self.assertEqual("text/html", message.get_payload(1).get_content_type())
class BaseEmailTestCase(unittest.TestCase): def setUp(self): self.controller = QueueController('localhost', 9025) self.controller.start() self._smtp_host = self.controller.server.host self._smtp_port = self.controller.server.port def tearDown(self): self.controller.stop() del self._smtp_host del self._smtp_port
class MailerTest(unittest.TestCase): def setUp(self): self.controller = QueueController("localhost", 9025) self.controller.start() def tearDown(self): self.controller.stop() def test_send_email(self): mailer = Mailer("localhost", 9025) body = "This is the bloody test body" mailer.send_email("*****@*****.**", "*****@*****.**", "test subject", body) message = list(self.controller)[0] (from_str, from_cs) = decode_header(message["From"])[0] (to_str, to_cs) = decode_header(message["To"])[0] (subject_str, subject_cs) = decode_header(message["Subject"])[0] self.assertEqual("*****@*****.**", from_str) self.assertEqual("*****@*****.**", to_str) self.assertEqual("test subject", subject_str) self.assertEqual(body, unicode(message.get_payload(decode=True), message.get_content_charset())) def test_send_html_email(self): mailer = Mailer("localhost", 9025) text = u"This is the bloody test body" html = u"<p>This is the bloody test body</p>" mailer.send_html_email("*****@*****.**", "*****@*****.**", "test subject", text, html) message = list(self.controller)[0] (from_str, from_cs) = decode_header(message["From"])[0] (to_str, to_cs) = decode_header(message["To"])[0] (subject_str, subject_cs) = decode_header(message["Subject"])[0] self.assertEqual("*****@*****.**", from_str) self.assertEqual("*****@*****.**", to_str) self.assertEqual("test subject", subject_str) self.assertEqual(text, unicode(message.get_payload(0).get_payload(decode=True), message.get_payload(0).get_content_charset())) self.assertEqual("text/plain", message.get_payload(0).get_content_type()) self.assertEqual(html, unicode(message.get_payload(1).get_payload(decode=True), message.get_payload(1).get_content_charset())) self.assertEqual("text/html", message.get_payload(1).get_content_type())
def start(self): """See `lazr.smtptest.controller.QueueController`.""" QueueController.start(self) # Reset the connection statistics, since the base class's start() # method causes a connection to occur. self.reset()
def __init__(self, host, port): """See `lazr.smtptest.controller.QueueController`.""" self.oob_queue = Queue() self.err_queue = Queue() QueueController.__init__(self, host, port)
def setUp(self): self.controller = QueueController('localhost', 9025) self.controller.start() self._smtp_host = self.controller.server.host self._smtp_port = self.controller.server.port
def setUp(self): self.controller = QueueController("localhost", 9025) self.controller.start()
class EmailModuleFuncTest(unittest.TestCase): def setUp(self): self.controller = QueueController("localhost", 9025) self.controller.start() def tearDown(self): self.controller.stop() def test_warnings(self): email._mailer = None with warnings.catch_warnings(record=True): warnings.simplefilter("error") self.assertRaises(UserWarning, email.send_email, "*****@*****.**", "*****@*****.**", "test subject", "test body") self.assertRaises(UserWarning, email.send_html_email, "*****@*****.**", "*****@*****.**", "test subject", "plain body", "<p>html body</p>") def test_send_email(self): email.configure({"host": "localhost", "port": 9025}) body = "This is the bloody test body" email.send_email("*****@*****.**", "*****@*****.**", "test subject", body) message = list(self.controller)[0] (from_str, from_cs) = decode_header(message["From"])[0] (to_str, to_cs) = decode_header(message["To"])[0] (subject_str, subject_cs) = decode_header(message["Subject"])[0] self.assertEqual("*****@*****.**", from_str) self.assertEqual("*****@*****.**", to_str) self.assertEqual("test subject", subject_str) self.assertEqual( body, unicode(message.get_payload(decode=True), message.get_content_charset())) def test_send_html_email(self): email.configure({"host": "localhost", "port": 9025}) text = u"This is the bloody test body" html = u"<p>This is the bloody test body</p>" email.send_html_email("*****@*****.**", "*****@*****.**", "test subject", text, html) message = list(self.controller)[0] (from_str, from_cs) = decode_header(message["From"])[0] (to_str, to_cs) = decode_header(message["To"])[0] (subject_str, subject_cs) = decode_header(message["Subject"])[0] self.assertEqual("*****@*****.**", from_str) self.assertEqual("*****@*****.**", to_str) self.assertEqual("test subject", subject_str) self.assertEqual( text, unicode( message.get_payload(0).get_payload(decode=True), message.get_payload(0).get_content_charset())) self.assertEqual("text/plain", message.get_payload(0).get_content_type()) self.assertEqual( html, unicode( message.get_payload(1).get_payload(decode=True), message.get_payload(1).get_content_charset())) self.assertEqual("text/html", message.get_payload(1).get_content_type())