From: Christian Herdtweck Date: Thu, 14 Nov 2019 11:04:30 +0000 (+0100) Subject: Add unittest for prepare_recipients X-Git-Tag: v1.6.3~2^2 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=710e9ac2378f8b1b70f3a035be9bdf7063dffff8;p=pyi2ncommon Add unittest for prepare_recipients --- diff --git a/test/test_mail_validator.py b/test/test_mail_validator.py index 9405b74..6a2a9d6 100644 --- a/test/test_mail_validator.py +++ b/test/test_mail_validator.py @@ -4,6 +4,7 @@ import os import unittest +from socket import gethostname from src import mail_validator @@ -215,3 +216,23 @@ class MailUtilsValidatorTest(unittest.TestCase): os.unlink("trgdir/.123") os.unlink("trgdir/.5267") + def test_prepare_recipients(self): + """Test :py:meth:`MailValidator._prepare_recipients'.""" + localhost = gethostname() + # simple user name + self.assertEqual(self.validator._prepare_recipients('username'), + ['username@' + localhost, ]) + + # list of names + self.assertEqual(self.validator._prepare_recipients( + ('user1', 'user2')), + ['user1@' + localhost, 'user2@' + localhost]) + + # include external + self.assertEqual(self.validator._prepare_recipients( + ('local', 'external@domain.tld')), + ['local@' + localhost, 'external@domain.tld']) + + # invalid + self.assertRaises(ValueError, self.validator._prepare_recipients, + '"John Doe" ')