From fc6aa225dccb4dc7445dd55ebecdf7d0a2056f59 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Tue, 4 Jun 2019 09:58:41 +0200 Subject: [PATCH] Create unittest for parse_mail_date --- test/test_mail_utils.py | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/test/test_mail_utils.py b/test/test_mail_utils.py index fb9746e..4a0aa06 100644 --- a/test/test_mail_utils.py +++ b/test/test_mail_utils.py @@ -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) -- 1.7.1