import os
import unittest
+from socket import gethostname
from src import mail_validator
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>')