Create unittest for parse_mail_date
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 4 Jun 2019 07:58:41 +0000 (09:58 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 8 Aug 2019 09:54:43 +0000 (11:54 +0200)
test/test_mail_utils.py

index fb9746e..4a0aa06 100644 (file)
@@ -25,7 +25,9 @@ import os
 from os.path import isdir, join
 from tempfile import mkdtemp
 from shutil import rmtree
+from email import message
 from email.errors import MultipartInvariantViolationDefect
+from datetime import datetime as dt
 
 from src import mail_utils
 
@@ -347,3 +349,22 @@ class MailUtilsFunctionTest(unittest.TestCase):
         self.assertIn('Subject', msg)
         self.assertTrue(msg['Subject'].startswith(
             r"Emailfilter test 7b25f7a3-115: b'2018\xe5\xb9\xb4\xe5\xba"))
+
+    def test_parse_mail_date(self):
+        """Test function parse_mail_date"""
+
+        examples = (
+            ('Fri, 15 May 2009 17:58:28 +0000', dt(2009, 5, 15, 17, 58, 28)),
+            ('Thu, 10 Sep 2015 14:45:23 +0200', dt(2015, 9, 10, 16, 45, 23)),
+            ('Wed, 26 Jun 2018 20:29:36 -0700 (PDT)',
+             dt(2018, 6, 26, 13, 29, 36)))
+
+        for to_parse, result in examples:
+            msg = message.Message()
+            msg['From'] = 'Autotest-Sender@localhost'
+            msg['To'] = 'Autotest-Recipient@localhost'
+            msg['Subject'] = 'Testing parse_mail_date'
+            msg['Date'] = to_parse
+            msg.set_unixfrom('Autotest-Sender@localhost')
+
+            self.assertEqual(mail_utils.parse_mail_date(msg), result)