def test_small_text_is_preserved(self):
     # Text parts below the limit are unchanged.
     message = self.makeMailmanMessage(self.mm_list, self.subscriber_email,
                                       'subject', 'content')
     moderated_message = LPSize.truncated_message(message, limit=1000)
     parts = [part for part in moderated_message.walk()]
     types = [part.get_content_type() for part in parts]
     self.assertEqual(['multipart/mixed', 'text/plain'], types)
     self.assertEqual('content', parts[1].get_payload())
 def test_small_text_is_preserved(self):
     # Text parts below the limit are unchanged.
     message = self.makeMailmanMessage(
         self.mm_list, self.subscriber_email, 'subject', 'content')
     moderated_message = LPSize.truncated_message(message, limit=1000)
     parts = [part for part in moderated_message.walk()]
     types = [part.get_content_type() for part in parts]
     self.assertEqual(['multipart/mixed', 'text/plain'], types)
     self.assertEqual('content', parts[1].get_payload())
 def test_large_text_is_truncated(self):
     # Text parts above the limit are truncated.
     message = self.makeMailmanMessage(self.mm_list, self.subscriber_email,
                                       'subject', 'content excess')
     moderated_message = LPSize.truncated_message(message, limit=7)
     parts = [part for part in moderated_message.walk()]
     types = [part.get_content_type() for part in parts]
     self.assertEqual(['multipart/mixed', 'text/plain'], types)
     self.assertEqual('content\n[truncated for moderation]',
                      parts[1].get_payload())
 def test_large_text_is_truncated(self):
     # Text parts above the limit are truncated.
     message = self.makeMailmanMessage(
         self.mm_list, self.subscriber_email, 'subject', 'content excess')
     moderated_message = LPSize.truncated_message(message, limit=7)
     parts = [part for part in moderated_message.walk()]
     types = [part.get_content_type() for part in parts]
     self.assertEqual(['multipart/mixed', 'text/plain'], types)
     self.assertEqual(
         'content\n[truncated for moderation]', parts[1].get_payload())
 def test_attchments_are_removed(self):
     # Plain-text and multipart are preserved, everything else is removed.
     attachment = MIMEApplication('binary gibberish', 'octet-stream')
     message = self.makeMailmanMessage(
         self.mm_list, self.subscriber_email, 'subject', 'content',
         attachment=attachment)
     moderated_message = LPSize.truncated_message(message)
     parts = [part for part in moderated_message.walk()]
     types = [part.get_content_type() for part in parts]
     self.assertEqual(['multipart/mixed', 'text/plain'], types)
 def test_attchments_are_removed(self):
     # Plain-text and multipart are preserved, everything else is removed.
     attachment = MIMEApplication('binary gibberish', 'octet-stream')
     message = self.makeMailmanMessage(self.mm_list,
                                       self.subscriber_email,
                                       'subject',
                                       'content',
                                       attachment=attachment)
     moderated_message = LPSize.truncated_message(message)
     parts = [part for part in moderated_message.walk()]
     types = [part.get_content_type() for part in parts]
     self.assertEqual(['multipart/mixed', 'text/plain'], types)