From 675ecfeef586b060d88dfcf8cced389b8fcbf7a7 Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Tue, 25 Jan 2011 16:48:51 -0800 Subject: Added one and changed two MimeDel tests for rev 1272 changes. --- tests/test_handlers.py | 82 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 10 deletions(-) diff --git a/tests/test_handlers.py b/tests/test_handlers.py index ef9a30ec..04647764 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2010 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2011 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -1139,6 +1139,7 @@ class TestMimeDel(TestBase): self._mlist.filter_mime_types = ['image/jpeg'] self._mlist.pass_mime_types = [] self._mlist.convert_html_to_plaintext = 1 + self._mlist.collapse_alternatives = 1 def test_outer_matches(self): msg = email.message_from_string("""\ @@ -1172,10 +1173,9 @@ yyy --BOUNDARY-- """) MimeDel.process(self._mlist, msg, {}) - eq(len(msg.get_payload()), 1) - subpart = msg.get_payload(0) - eq(subpart.get_content_type(), 'image/gif') - eq(subpart.get_payload(), 'yyy') + self.assertTrue(not msg.is_multipart()) + eq(msg.get_content_type(), 'image/gif') + eq(msg.get_payload(), 'yyy') def test_collapse_multipart_alternative(self): eq = self.assertEqual @@ -1204,11 +1204,9 @@ yyy --BOUNDARY-- """) MimeDel.process(self._mlist, msg, {}) - eq(len(msg.get_payload()), 1) - eq(msg.get_content_type(), 'multipart/mixed') - subpart = msg.get_payload(0) - eq(subpart.get_content_type(), 'image/gif') - eq(subpart.get_payload(), 'yyy') + self.assertTrue(not msg.is_multipart()) + eq(msg.get_content_type(), 'image/gif') + eq(msg.get_payload(), 'yyy') def test_convert_to_plaintext(self): # BAW: This test is dependent on your particular lynx version @@ -1301,6 +1299,70 @@ This is plain text eq(msg.get_content_type(), 'text/plain') eq(msg.get_payload(), 'This is plain text') + def test_recast_multipart(self): + eq = self.assertEqual + self._mlist.filter_mime_types.append('application/pdf') + msg = email.message_from_string("""\ +From: aperson@dom.ain +MIME-Version: 1.0 +Content-type: multipart/mixed; + boundary="Boundary_0" + +--Boundary_0 +Content-Type: multipart/mixed; + boundary="Boundary_1" + +--Boundary_1 +Content-type: multipart/mixed; + boundary="Boundary_2" + +--Boundary_2 +Content-type: multipart/alternative; + boundary="Boundary_3" + +--Boundary_3 +Content-type: text/plain; charset=us-ascii +Content-transfer-encoding: 7BIT + +Plain text part +--Boundary_3 +Content-type: text/html; charset=us-ascii +Content-transfer-encoding: 7BIT + +HTML part +--Boundary_3-- + + +--Boundary_2 +Content-type: application/pdf +Content-transfer-encoding: 7BIT + +PDF part inner 2 +--Boundary_2-- +--Boundary_1 +Content-type: text/plain; charset=us-ascii +Content-transfer-encoding: 7BIT + +second text +--Boundary_1-- + +--Boundary_0 +Content-Type: application/pdf +Content-transfer-encoding: 7BIT + +PDF part outer +--Boundary_0-- +""") + MimeDel.process(self._mlist, msg, {}) + payload = msg.get_payload() + eq(len(payload), 2) + part1 = msg.get_payload(0) + eq(part1.get_content_type(), 'text/plain') + eq(part1.get_payload(), 'Plain text part') + part2 = msg.get_payload(1) + eq(part2.get_content_type(), 'text/plain') + eq(part2.get_payload(), 'second text') + class TestModerate(TestBase): -- cgit v1.2.3