From 67beba06bc4a3d0ebac358eb59c9987c02d21bac Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Tue, 17 Mar 2015 13:53:40 +0100 Subject: Don't fail to parse mail if neither Date nor Received header is avail. - Issue #331 --- service/test/unit/adapter/test_mail.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'service/test/unit') diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py index 317db5de..5bb46687 100644 --- a/service/test/unit/adapter/test_mail.py +++ b/service/test/unit/adapter/test_mail.py @@ -31,6 +31,9 @@ class TestPixelatedMail(unittest.TestCase): def setUp(self): self.querier = mock() + def tearDown(self): + unstub() + def test_parse_date_from_soledad_uses_date_header_if_available(self): leap_mail_date = 'Wed, 3 Sep 2014 12:36:17 -0300' leap_mail_date_in_iso_format = "2014-09-03T12:36:17-03:00" @@ -52,6 +55,17 @@ class TestPixelatedMail(unittest.TestCase): self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format) + def test_parse_date_from_soledad_fallback_to_now_if_neither_date_nor_received_header(self): + leap_mail_date_in_iso_format = "2014-09-03T13:11:15-03:00" + + when(pixelated.support.date).iso_now().thenReturn(leap_mail_date_in_iso_format) + fdoc, hdoc, bdoc = test_helper.leap_mail() + del hdoc.content['date'] + + mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier) + + self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format) + def test_update_tags_return_a_set_with_the_current_tags(self): soledad_docs = test_helper.leap_mail(extra_headers={'X-tags': '["custom_1", "custom_2"]'}) pixelated_mail = PixelatedMail.from_soledad(*soledad_docs, soledad_querier=self.querier) -- cgit v1.2.3