Add unittest for prepare_recipients
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 14 Nov 2019 11:04:30 +0000 (12:04 +0100)
committerPlamen Dimitrov <pdimitrov@pevogam.com>
Tue, 19 Nov 2019 09:04:00 +0000 (11:04 +0200)
test/test_mail_validator.py

index 9405b74..6a2a9d6 100644 (file)
@@ -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" <john.doe@domain.tld>')