From 710e9ac2378f8b1b70f3a035be9bdf7063dffff8 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Thu, 14 Nov 2019 12:04:30 +0100 Subject: [PATCH] Add unittest for prepare_recipients --- test/test_mail_validator.py | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) 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" ') -- 1.7.1