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

Proposed by Vincent Ladeuil on 2012-06-28
Status: Merged
Approved by: Graham Binns on 2012-06-28
Approved revision: no longer in the source branch.
Merged at revision: 15524
Proposed branch: lp:~vila/launchpad/py27-mail-header-continuation-lines
Merge into: lp:launchpad
Diff against target: 53 lines (+16/-9)
2 files modified
lib/lp/archiveuploader/tests/test_uploadprocessor.py (+4/-9)
lib/lp/services/mail/tests/test_sendmail.py (+12/-0)
To merge this branch: bzr merge lp:~vila/launchpad/py27-mail-header-continuation-lines
Reviewer Review Type Date Requested Status
Graham Binns (community) code 2012-06-28 Approve on 2012-06-28
Review via email: mp+112579@code.launchpad.net

Commit Message

Fix mail related test failure by allowing both types of continuation lines to be compatible with both python 2.6 and 2.7.

Description of the Change

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.

To post a comment you must log in.
Graham Binns (gmb) wrote :

[1]

39 + def test_long_subject_wrapping(self):

This needs a comment at the start explaining the expected behaviour. You
could probably just move the comment from later in the test up here.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archiveuploader/tests/test_uploadprocessor.py'
2--- lib/lp/archiveuploader/tests/test_uploadprocessor.py 2012-03-16 18:17:46 +0000
3+++ lib/lp/archiveuploader/tests/test_uploadprocessor.py 2012-06-28 14:48:23 +0000
4@@ -1957,14 +1957,6 @@
5 self.assertEqual(deb.priority_name, ddeb.priority_name)
6
7
8-class TestBuildUploadProcessor(TestUploadProcessorBase):
9- """Test that processing build uploads works."""
10-
11- def setUp(self):
12- super(TestBuildUploadProcessor, self).setUp()
13- self.uploadprocessor = self.setupBreezyAndGetUploadProcessor()
14-
15-
16 class TestUploadHandler(TestUploadProcessorBase):
17
18 def setUp(self):
19@@ -2169,7 +2161,10 @@
20 # Failures should generate a message that includes the upload log URL.
21 self.doFailureRecipeBuild()
22 (mail,) = pop_notifications()
23- subject = mail['Subject'].replace('\n\t', ' ')
24+ # Python2.6 prefixes continuation lines with a \t, 2.7 uses a single
25+ # space instead, try both to stay compatible (see email/generator.py
26+ # Generator._write_headers for details).
27+ subject = mail['Subject'].replace('\n\t', ' ').replace('\n ', ' ')
28 self.assertIn('Failed to upload', subject)
29 body = mail.get_payload(decode=True)
30 self.assertIn('Upload Log: http', body)
31
32=== modified file 'lib/lp/services/mail/tests/test_sendmail.py'
33--- lib/lp/services/mail/tests/test_sendmail.py 2011-12-19 23:38:16 +0000
34+++ lib/lp/services/mail/tests/test_sendmail.py 2012-06-28 14:48:23 +0000
35@@ -51,6 +51,18 @@
36 self.assertEqual('body', ctrl.body)
37 self.assertEqual([], ctrl.attachments)
38
39+ def test_long_subject_wrapping(self):
40+ # Python2.6 prefixes continuation lines with '\t', 2.7 uses a single
41+ # space instead. Catch any change in this behaviour to avoid having to
42+ # redo the full diagnosis in the future.
43+ before = '0123456789' * 6 + 'before'
44+ after = 'after' + '0123456789'
45+ hdr = email.header.Header(before + ' ' + after, header_name='Subject')
46+ encoded = hdr.encode()
47+ self.assertTrue(('before\n after' in encoded)
48+ or ('before\n\t after' in encoded),
49+ 'Header.encode() changed continuation lines again')
50+
51 def test_addAttachment(self):
52 """addAttachment should add a part to the list of attachments."""
53 ctrl = MailController(