Merge lp:~bjornt/launchpad/compare-email-headers into lp:launchpad

Proposed by Björn Tillenius
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 10879
Proposed branch: lp:~bjornt/launchpad/compare-email-headers
Merge into: lp:launchpad
Diff against target: 83 lines (+23/-7)
3 files modified
lib/lp/code/mail/tests/test_branchmergeproposal.py (+1/-1)
lib/lp/codehosting/scanner/tests/test_email.py (+9/-6)
lib/lp/testing/__init__.py (+13/-0)
To merge this branch: bzr merge lp:~bjornt/launchpad/compare-email-headers
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+25520@code.launchpad.net

Description of the change

Add TestCase.assertEmailHeadersEqual() for comparing e-mail headers.

In case of long headers, the headers are unfolded before being compared.
Also change some tests to use the new method, so that they can cope with
factory.getUniqueString() being changed to return longer strings.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/mail/tests/test_branchmergeproposal.py'
--- lib/lp/code/mail/tests/test_branchmergeproposal.py 2010-04-06 23:47:36 +0000
+++ lib/lp/code/mail/tests/test_branchmergeproposal.py 2010-05-18 14:28:36 +0000
@@ -519,7 +519,7 @@
519 candidate = removeSecurityProxy(candidate)519 candidate = removeSecurityProxy(candidate)
520 expected_email = '%s <%s>' % (520 expected_email = '%s <%s>' % (
521 candidate.displayname, candidate.preferredemail.email)521 candidate.displayname, candidate.preferredemail.email)
522 self.assertEqual(expected_email, mails[0]['To'])522 self.assertEmailHeadersEqual(expected_email, mails[0]['To'])
523523
524524
525def test_suite():525def test_suite():
526526
=== modified file 'lib/lp/codehosting/scanner/tests/test_email.py'
--- lib/lp/codehosting/scanner/tests/test_email.py 2010-04-23 07:54:02 +0000
+++ lib/lp/codehosting/scanner/tests/test_email.py 2010-05-18 14:28:36 +0000
@@ -61,7 +61,7 @@
61 message = email.message_from_string(initial_email[2])61 message = email.message_from_string(initial_email[2])
62 email_body = message.get_payload()62 email_body = message.get_payload()
63 self.assertTextIn(expected, email_body)63 self.assertTextIn(expected, email_body)
64 self.assertEqual(64 self.assertEmailHeadersEqual(
65 '[Branch %s] 0 revisions' % self.db_branch.unique_name,65 '[Branch %s] 0 revisions' % self.db_branch.unique_name,
66 message['Subject'])66 message['Subject'])
6767
@@ -76,7 +76,7 @@
76 message = email.message_from_string(initial_email[2])76 message = email.message_from_string(initial_email[2])
77 email_body = message.get_payload()77 email_body = message.get_payload()
78 self.assertTextIn(expected, email_body)78 self.assertTextIn(expected, email_body)
79 self.assertEqual(79 self.assertEmailHeadersEqual(
80 '[Branch %s] 1 revision' % self.db_branch.unique_name,80 '[Branch %s] 1 revision' % self.db_branch.unique_name,
81 message['Subject'])81 message['Subject'])
8282
@@ -94,7 +94,7 @@
94 message = email.message_from_string(uncommit_email[2])94 message = email.message_from_string(uncommit_email[2])
95 email_body = message.get_payload()95 email_body = message.get_payload()
96 self.assertTextIn(expected, email_body)96 self.assertTextIn(expected, email_body)
97 self.assertEqual(97 self.assertEmailHeadersEqual(
98 '[Branch %s] 1 revision removed' % self.db_branch.unique_name,98 '[Branch %s] 1 revision removed' % self.db_branch.unique_name,
99 message['Subject'])99 message['Subject'])
100100
@@ -122,10 +122,13 @@
122 subject = (122 subject = (
123 'Subject: [Branch %s] Test branch' % self.db_branch.unique_name)123 'Subject: [Branch %s] Test branch' % self.db_branch.unique_name)
124 self.assertTextIn(expected, uncommit_email_body)124 self.assertTextIn(expected, uncommit_email_body)
125 recommit_email_body = recommit_email[2]125
126 recommit_email_msg = email.message_from_string(recommit_email[2])
127 recommit_email_body = recommit_email_msg.get_payload()[0].get_payload(
128 decode=True)
129 subject = '[Branch %s] Rev 1: second' % self.db_branch.unique_name
130 self.assertEmailHeadersEqual(subject, recommit_email_msg['Subject'])
126 body_bits = [131 body_bits = [
127 'Subject: [Branch %s] Rev 1: second'
128 % self.db_branch.unique_name,
129 'revno: 1',132 'revno: 1',
130 'committer: %s' % author,133 'committer: %s' % author,
131 'branch nick: %s' % self.bzr_branch.nick,134 'branch nick: %s' % self.bzr_branch.nick,
132135
=== modified file 'lib/lp/testing/__init__.py'
--- lib/lp/testing/__init__.py 2010-05-06 13:39:11 +0000
+++ lib/lp/testing/__init__.py 2010-05-18 14:28:36 +0000
@@ -413,6 +413,19 @@
413 os.chdir(tempdir)413 os.chdir(tempdir)
414 self.addCleanup(os.chdir, cwd)414 self.addCleanup(os.chdir, cwd)
415415
416 def _unfoldEmailHeader(self, header):
417 """Unfold a multiline e-mail header."""
418 header = ''.join(header.splitlines())
419 return header.replace('\t', ' ')
420
421 def assertEmailHeadersEqual(self, expected, observed):
422 """Assert that two e-mail headers are equal.
423
424 The headers are unfolded before being compared.
425 """
426 return self.assertEqual(
427 self._unfoldEmailHeader(expected),
428 self._unfoldEmailHeader(observed))
416429
417class TestCaseWithFactory(TestCase):430class TestCaseWithFactory(TestCase):
418431