From 4d36d0b34237d1568df8c01ee5a49ff99a567961 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 22 Jan 2021 16:29:35 +0100 Subject: [PATCH] Fix tests with Products.MailHost 4.11. Fixes https://github.com/plone/plone.app.discussion/issues/174 --- news/174.bugfix | 2 ++ .../discussion/tests/test_notifications.py | 35 ++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 news/174.bugfix diff --git a/news/174.bugfix b/news/174.bugfix new file mode 100644 index 0000000..bf9b438 --- /dev/null +++ b/news/174.bugfix @@ -0,0 +1,2 @@ +Fix tests with Products.MailHost 4.11. +[maurits] diff --git a/plone/app/discussion/tests/test_notifications.py b/plone/app/discussion/tests/test_notifications.py index 9ed3492..13f9f6d 100644 --- a/plone/app/discussion/tests/test_notifications.py +++ b/plone/app/discussion/tests/test_notifications.py @@ -67,23 +67,26 @@ class TestUserNotificationUnit(unittest.TestCase): self.assertTrue(self.mailhost.messages[0]) msg = self.mailhost.messages[0] msg = msg.decode("utf-8") - self.assertTrue('To: john@plone.test' in msg) - self.assertTrue('From: portal@plone.test' in msg) + self.assertIn('To: john@plone.test', msg) + self.assertIn('From: portal@plone.test', msg) # We expect the headers to be properly header encoded (7-bit): - self.assertTrue( - 'Subject: =?utf-8?q?A_comment_has_been_posted=2E?=\n' - in msg) + self.assertIn( + 'Subject: =?utf-8?q?A_comment_has_been_posted=2E?=', + msg) # The output should be encoded in a reasonable manner - # (in this case quoted-printable): - self.assertTrue( - 'A comment on "K=C3=B6lle Alaaf" has been posted here:' - in msg) - self.assertTrue( - 'http://nohost/plone/d=\noc1/view#{0}'.format(comment_id) - in msg) - self.assertTrue('Comment text' in msg) - self.assertFalse('Approve comment' in msg) - self.assertFalse('Delete comment' in msg) + # (in this case quoted-printable). + # Depending on which Python version and which Products.MailHost version, + # you may get lines separated by '\n' or '\r\n' in here. + msg = msg.replace('\r\n', '\n') + self.assertIn( + 'A comment on "K=C3=B6lle Alaaf" has been posted here:', + msg) + self.assertIn( + 'http://nohost/plone/d=\noc1/view#{0}'.format(comment_id), + msg) + self.assertIn('Comment text', msg) + self.assertNotIn('Approve comment', msg) + self.assertNotIn('Delete comment', msg) def test_do_not_notify_user_when_notification_is_disabled(self): registry = queryUtility(IRegistry) @@ -213,7 +216,7 @@ class TestModeratorNotificationUnit(unittest.TestCase): self.assertTrue('From: portal@plone.test' in msg) # We expect the headers to be properly header encoded (7-bit): self.assertTrue( - 'Subject: =?utf-8?q?A_comment_has_been_posted=2E?=\n' + 'Subject: =?utf-8?q?A_comment_has_been_posted=2E?=' in msg) # The output should be encoded in a reasonable manner # (in this case quoted-printable):