Fix timezone in test for parse_mail_date
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 15 Jul 2019 11:06:36 +0000 (13:06 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 8 Aug 2019 09:54:44 +0000 (11:54 +0200)
test/test_mail_utils.py

index eb65ece..182fd90 100644 (file)
@@ -27,10 +27,11 @@ from tempfile import mkdtemp
 from shutil import rmtree
 from email import message
 from email.errors import MultipartInvariantViolationDefect
-from datetime import datetime as dt
+from datetime import timezone, datetime as dt
 
 from src import mail_utils
 
+UTC = timezone.utc
 
 
 EMAIL_TEXT = r"""Return-Path: <autotest-sender@vm1.net.lan>
@@ -191,6 +192,7 @@ class MailUtilsFunctionTest(unittest.TestCase):
         filename = self.create_mail()
         msg, attachment_filenames = \
             mail_utils.parse_mail_file(filename, attachment_filenames=True)
+        self.assertIsInstance(msg, message.Message)
         if len(msg.defects) == 1:
             # msg ContentType is multipart/mixed but with only headers,
             # msg.is_multipart is False.
@@ -211,9 +213,9 @@ class MailUtilsFunctionTest(unittest.TestCase):
 
         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)),
+            ('Thu, 10 Sep 2015 14:45:23 +0200', dt(2015, 9, 10, 12, 45, 23)),
             ('Wed, 26 Jun 2018 20:29:36 -0700 (PDT)',
-             dt(2018, 6, 26, 13, 29, 36)))
+             dt(2018, 6, 27, 3, 29, 36)))
 
         for to_parse, result in examples:
             msg = message.Message()
@@ -223,7 +225,8 @@ class MailUtilsFunctionTest(unittest.TestCase):
             msg['Date'] = to_parse
             msg.set_unixfrom('Autotest-Sender@localhost')
 
-            self.assertEqual(mail_utils.parse_mail_date(msg), result)
+            self.assertEqual(mail_utils.parse_mail_date(msg).astimezone(UTC),
+                             result.replace(tzinfo=UTC))
 
     def test_latin1_mail(self):
         """Check reading mail with non-ascii chars not encoded with utf8"""