[PATCH 2 of 6] e-mail: add trivial test case

Thomas De Schampheleire patrickdepinguin at gmail.com
Sun Aug 2 20:51:36 UTC 2015


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1438541177 -7200
#      Sun Aug 02 20:46:17 2015 +0200
# Node ID b23eae36b776a9bf8ce3c06a18e0189d337f7502
# Parent  c530a2d8643042b7424e4bec5f00a1017eeae57d
e-mail: add trivial test case

Add a first trivial e-mail test, new tests to be added in subsequent
commits.

diff --git a/kallithea/tests/other/test_mail.py b/kallithea/tests/other/test_mail.py
new file mode 100644
--- /dev/null
+++ b/kallithea/tests/other/test_mail.py
@@ -0,0 +1,46 @@
+import mock
+
+import kallithea
+from kallithea.tests import *
+from kallithea.model.db import User
+
+class smtplib_mock(object):
+
+    @classmethod
+    def SMTP(cls, server, port, local_hostname):
+        return smtplib_mock()
+
+    def ehlo(self):
+        pass
+    def quit(self):
+        pass
+    def sendmail(self, sender, dest, msg):
+        smtplib_mock.lastsender = sender
+        smtplib_mock.lastdest = dest
+        smtplib_mock.lastmsg = msg
+        pass
+
+ at mock.patch('kallithea.lib.rcmail.smtp_mailer.smtplib', smtplib_mock)
+class TestMail(BaseTestCase):
+
+    def test_send_mail_trivial(self):
+        mailserver = 'smtp.mailserver.org'
+        recipients = ['rcpt1', 'rcpt2']
+        envelope_from = 'noreply at mailserver.org'
+        subject = 'subject'
+        body = 'body'
+        html_body = 'html_body'
+
+        config_mock = {
+                'smtp_server': mailserver,
+                'app_email_from': envelope_from,
+        }
+        with mock.patch('kallithea.lib.celerylib.tasks.config', config_mock):
+            kallithea.lib.celerylib.tasks.send_email(recipients, subject, body, html_body)
+
+        self.assertSetEqual(smtplib_mock.lastdest, set(recipients))
+        self.assertEqual(smtplib_mock.lastsender, envelope_from)
+        self.assertIn('From: %s' % envelope_from, smtplib_mock.lastmsg)
+        self.assertIn('Subject: %s' % subject, smtplib_mock.lastmsg)
+        self.assertIn(body, smtplib_mock.lastmsg)
+        self.assertIn(html_body, smtplib_mock.lastmsg)


More information about the kallithea-general mailing list