← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~vila/launchpad/py27-mail-header-continuation-lines into lp:launchpad

 

Vincent Ladeuil has proposed merging lp:~vila/launchpad/py27-mail-header-continuation-lines into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1018862 in Launchpad itself: "Test failures in lp.archiveuploader.tests.test_uploadprocessor.TestUploadHandler.testSourcePackageRecipeBuild_fail_mail on Python 2.7"
  https://bugs.launchpad.net/launchpad/+bug/1018862

For more details, see:
https://code.launchpad.net/~vila/launchpad/py27-mail-header-continuation-lines/+merge/112579

Fix a test failure on python 2.7 where the way long mail header lines are split:
- 2.6 prefixed the continuation lines with '\t'
- 2.7 prefixed them with a single space.

Tested on lp setups for lucid and precise.

I also deleted some dead code left over from some very old refactoring.
-- 
https://code.launchpad.net/~vila/launchpad/py27-mail-header-continuation-lines/+merge/112579
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~vila/launchpad/py27-mail-header-continuation-lines into lp:launchpad.
=== modified file 'lib/lp/archiveuploader/tests/test_uploadprocessor.py'
--- lib/lp/archiveuploader/tests/test_uploadprocessor.py	2012-03-16 18:17:46 +0000
+++ lib/lp/archiveuploader/tests/test_uploadprocessor.py	2012-06-28 14:37:45 +0000
@@ -1957,14 +1957,6 @@
         self.assertEqual(deb.priority_name, ddeb.priority_name)
 
 
-class TestBuildUploadProcessor(TestUploadProcessorBase):
-    """Test that processing build uploads works."""
-
-    def setUp(self):
-        super(TestBuildUploadProcessor, self).setUp()
-        self.uploadprocessor = self.setupBreezyAndGetUploadProcessor()
-
-
 class TestUploadHandler(TestUploadProcessorBase):
 
     def setUp(self):
@@ -2169,7 +2161,10 @@
         # Failures should generate a message that includes the upload log URL.
         self.doFailureRecipeBuild()
         (mail,) = pop_notifications()
-        subject = mail['Subject'].replace('\n\t', ' ')
+        # Python2.6 prefixes continuation lines with a \t, 2.7 uses a single
+        # space instead, try both to stay compatible (see email/generator.py
+        # Generator._write_headers for details).
+        subject = mail['Subject'].replace('\n\t', ' ').replace('\n ', ' ')
         self.assertIn('Failed to upload', subject)
         body = mail.get_payload(decode=True)
         self.assertIn('Upload Log: http', body)

=== modified file 'lib/lp/services/mail/tests/test_sendmail.py'
--- lib/lp/services/mail/tests/test_sendmail.py	2011-12-19 23:38:16 +0000
+++ lib/lp/services/mail/tests/test_sendmail.py	2012-06-28 14:37:45 +0000
@@ -51,6 +51,18 @@
         self.assertEqual('body', ctrl.body)
         self.assertEqual([], ctrl.attachments)
 
+    def test_long_subject_wrapping(self):
+        before = '0123456789' * 6 + 'before'
+        after = 'after' + '0123456789'
+        hdr = email.header.Header(before + ' ' + after, header_name='Subject')
+        encoded = hdr.encode()
+        # Python2.6 prefixes continuation lines with '\t', 2.7 uses a single
+        # space instead. Catch any change in this behaviour to avoid having to
+        # redo the full diagnosis in the future.
+        self.assertTrue(('before\n after' in encoded)
+                        or ('before\n\t after' in encoded),
+                        'Header.encode() changed continuation lines again')
+
     def test_addAttachment(self):
         """addAttachment should add a part to the list of attachments."""
         ctrl = MailController(


Follow ups