Merge lp:~jml/launchpad/subject-and-attachment into lp:launchpad

Proposed by Jonathan Lange
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 11433
Proposed branch: lp:~jml/launchpad/subject-and-attachment
Merge into: lp:launchpad
Diff against target: 203 lines (+58/-26)
2 files modified
lib/devscripts/ec2test/remote.py (+19/-11)
lib/devscripts/ec2test/tests/test_remote.py (+39/-15)
To merge this branch: bzr merge lp:~jml/launchpad/subject-and-attachment
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+33544@code.launchpad.net

Commit message

Change the subject and attachment of EC2 test mails.

Description of the change

This branch changes the subject and attachment name of the EC2 email.

For most email, the subject will become:

  Test Results: branch-name -> devel: SUCCESS
  Test Results: branch-name -> db-devel: FAILURE

For test runs against a trunk:

  Test Results: devel r12345: SUCCESS

The reasoning is that it's nice to be able to quickly distinguish between newly incoming mail. I thought about dropping the "SUCCESS" bit in order to preserve threading, but not sure it's worth it.

The attachment then becomes:

  branch-name.subunit.gz

In anticipation of better support for just clicking on the damn attachment.

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/devscripts/ec2test/remote.py'
--- lib/devscripts/ec2test/remote.py 2010-08-18 18:04:38 +0000
+++ lib/devscripts/ec2test/remote.py 2010-08-24 16:22:46 +0000
@@ -314,12 +314,12 @@
314 conn = bzrlib.smtp_connection.SMTPConnection(self._bzr_config)314 conn = bzrlib.smtp_connection.SMTPConnection(self._bzr_config)
315 conn.send_email(message)315 conn.send_email(message)
316316
317 def get_trunk_details(self):317 def get_target_details(self):
318 """Return (branch_url, revno) for trunk."""318 """Return (branch_url, revno) for trunk."""
319 branch = bzrlib.branch.Branch.open(self._local_branch_path)319 branch = bzrlib.branch.Branch.open(self._local_branch_path)
320 return branch.get_parent().encode('utf-8'), branch.revno()320 return branch.get_parent().encode('utf-8'), branch.revno()
321321
322 def get_branch_details(self):322 def get_source_details(self):
323 """Return (branch_url, revno) for the branch we're merging in.323 """Return (branch_url, revno) for the branch we're merging in.
324324
325 If we're not merging in a branch, but instead just testing a trunk,325 If we're not merging in a branch, but instead just testing a trunk,
@@ -337,12 +337,18 @@
337337
338 def get_nick(self):338 def get_nick(self):
339 """Get the nick of the branch we are testing."""339 """Get the nick of the branch we are testing."""
340 details = self.get_branch_details()340 details = self.get_source_details()
341 if not details:341 if not details:
342 details = self.get_trunk_details()342 details = self.get_target_details()
343 url, revno = details343 url, revno = details
344 return self._last_segment(url)344 return self._last_segment(url)
345345
346 def get_revno(self):
347 """Get the revno of the branch we are testing."""
348 if self._revno is not None:
349 return self._revno
350 return bzrlib.branch.Branch.open(self._local_branch_path).revno()
351
346 def get_merge_description(self):352 def get_merge_description(self):
347 """Get a description of the merge request.353 """Get a description of the merge request.
348354
@@ -353,10 +359,10 @@
353 # XXX: JonathanLange 2010-08-17: Not actually used yet. I think it359 # XXX: JonathanLange 2010-08-17: Not actually used yet. I think it
354 # would be a great thing to have in the subject of the emails we360 # would be a great thing to have in the subject of the emails we
355 # receive.361 # receive.
356 source = self.get_branch_details()362 source = self.get_source_details()
357 if not source:363 if not source:
358 return self.get_nick()364 return '%s r%s' % (self.get_nick(), self.get_revno())
359 target = self.get_trunk_details()365 target = self.get_target_details()
360 return '%s => %s' % (366 return '%s => %s' % (
361 self._last_segment(source[0]), self._last_segment(target[0]))367 self._last_segment(source[0]), self._last_segment(target[0]))
362368
@@ -391,7 +397,8 @@
391 status = 'SUCCESS'397 status = 'SUCCESS'
392 else:398 else:
393 status = 'FAILURE'399 status = 'FAILURE'
394 subject = 'Test results: %s' % (status,)400 subject = 'Test results: %s: %s' % (
401 self.get_merge_description(), status)
395 message['Subject'] = subject402 message['Subject'] = subject
396403
397 # Make the body.404 # Make the body.
@@ -403,7 +410,8 @@
403 zipped_log = MIMEApplication(full_log_gz, 'x-gzip')410 zipped_log = MIMEApplication(full_log_gz, 'x-gzip')
404 zipped_log.add_header(411 zipped_log.add_header(
405 'Content-Disposition', 'attachment',412 'Content-Disposition', 'attachment',
406 filename='%s.log.gz' % self.get_nick())413 filename='%s-r%s.subunit.gz' % (
414 self.get_nick(), self.get_revno()))
407 message.attach(zipped_log)415 message.attach(zipped_log)
408 return message416 return message
409417
@@ -609,14 +617,14 @@
609 ''')617 ''')
610618
611 # Describe the trunk branch.619 # Describe the trunk branch.
612 trunk, trunk_revno = self._request.get_trunk_details()620 trunk, trunk_revno = self._request.get_target_details()
613 msg = '%s, revision %d\n' % (trunk, trunk_revno)621 msg = '%s, revision %d\n' % (trunk, trunk_revno)
614 add_to_html('''\622 add_to_html('''\
615 <p><strong>%s</strong></p>623 <p><strong>%s</strong></p>
616 ''' % (escape(msg),))624 ''' % (escape(msg),))
617 log(msg)625 log(msg)
618626
619 branch_details = self._request.get_branch_details()627 branch_details = self._request.get_source_details()
620 if not branch_details:628 if not branch_details:
621 add_to_html('<p>(no merged branch)</p>\n')629 add_to_html('<p>(no merged branch)</p>\n')
622 log('(no merged branch)')630 log('(no merged branch)')
623631
=== modified file 'lib/devscripts/ec2test/tests/test_remote.py'
--- lib/devscripts/ec2test/tests/test_remote.py 2010-08-18 17:36:12 +0000
+++ lib/devscripts/ec2test/tests/test_remote.py 2010-08-24 16:22:46 +0000
@@ -235,31 +235,49 @@
235 req = self.make_request(emails=['foo@example.com'])235 req = self.make_request(emails=['foo@example.com'])
236 self.assertEqual(True, req.wants_email)236 self.assertEqual(True, req.wants_email)
237237
238 def test_get_trunk_details(self):238 def test_get_target_details(self):
239 parent = 'http://example.com/bzr/branch'239 parent = 'http://example.com/bzr/branch'
240 tree = self.make_trunk(parent)240 tree = self.make_trunk(parent)
241 req = self.make_request(trunk=tree)241 req = self.make_request(trunk=tree)
242 self.assertEqual(242 self.assertEqual(
243 (parent, tree.branch.revno()), req.get_trunk_details())243 (parent, tree.branch.revno()), req.get_target_details())
244244
245 def test_get_branch_details_no_commits(self):245 def test_get_revno_target_only(self):
246 # If there's only a target branch, then the revno is the revno of that
247 # branch.
248 parent = 'http://example.com/bzr/branch'
249 tree = self.make_trunk(parent)
250 req = self.make_request(trunk=tree)
251 self.assertEqual(tree.branch.revno(), req.get_revno())
252
253 def test_get_revno_source_and_target(self):
254 # If we're merging in a branch, then the revno is the revno of the
255 # branch we're merging in.
256 tree = self.make_trunk()
257 # Fake a merge, giving silly revision ids.
258 tree.add_pending_merge('foo', 'bar')
259 req = self.make_request(
260 branch_url='https://example.com/bzr/thing', revno=42, trunk=tree)
261 self.assertEqual(42, req.get_revno())
262
263 def test_get_source_details_no_commits(self):
246 req = self.make_request(trunk=self.make_trunk())264 req = self.make_request(trunk=self.make_trunk())
247 self.assertEqual(None, req.get_branch_details())265 self.assertEqual(None, req.get_source_details())
248266
249 def test_get_branch_details_no_merge(self):267 def test_get_source_details_no_merge(self):
250 tree = self.make_trunk()268 tree = self.make_trunk()
251 tree.commit(message='foo')269 tree.commit(message='foo')
252 req = self.make_request(trunk=tree)270 req = self.make_request(trunk=tree)
253 self.assertEqual(None, req.get_branch_details())271 self.assertEqual(None, req.get_source_details())
254272
255 def test_get_branch_details_merge(self):273 def test_get_source_details_merge(self):
256 tree = self.make_trunk()274 tree = self.make_trunk()
257 # Fake a merge, giving silly revision ids.275 # Fake a merge, giving silly revision ids.
258 tree.add_pending_merge('foo', 'bar')276 tree.add_pending_merge('foo', 'bar')
259 req = self.make_request(277 req = self.make_request(
260 branch_url='https://example.com/bzr/thing', revno=42, trunk=tree)278 branch_url='https://example.com/bzr/thing', revno=42, trunk=tree)
261 self.assertEqual(279 self.assertEqual(
262 ('https://example.com/bzr/thing', 42), req.get_branch_details())280 ('https://example.com/bzr/thing', 42), req.get_source_details())
263281
264 def test_get_nick_trunk_only(self):282 def test_get_nick_trunk_only(self):
265 tree = self.make_trunk(parent_url='http://example.com/bzr/db-devel')283 tree = self.make_trunk(parent_url='http://example.com/bzr/db-devel')
@@ -277,7 +295,8 @@
277 def test_get_merge_description_trunk_only(self):295 def test_get_merge_description_trunk_only(self):
278 tree = self.make_trunk(parent_url='http://example.com/bzr/db-devel')296 tree = self.make_trunk(parent_url='http://example.com/bzr/db-devel')
279 req = self.make_request(trunk=tree)297 req = self.make_request(trunk=tree)
280 self.assertEqual('db-devel', req.get_merge_description())298 self.assertEqual(
299 'db-devel r%s' % req.get_revno(), req.get_merge_description())
281300
282 def test_get_merge_description_merge(self):301 def test_get_merge_description_merge(self):
283 tree = self.make_trunk(parent_url='http://example.com/bzr/db-devel/')302 tree = self.make_trunk(parent_url='http://example.com/bzr/db-devel/')
@@ -355,12 +374,16 @@
355 def test_report_email_subject_success(self):374 def test_report_email_subject_success(self):
356 req = self.make_request(emails=['foo@example.com'])375 req = self.make_request(emails=['foo@example.com'])
357 email = req._build_report_email(True, 'foo', 'gobbledygook')376 email = req._build_report_email(True, 'foo', 'gobbledygook')
358 self.assertEqual('Test results: SUCCESS', email['Subject'])377 self.assertEqual(
378 'Test results: %s: SUCCESS' % req.get_merge_description(),
379 email['Subject'])
359380
360 def test_report_email_subject_failure(self):381 def test_report_email_subject_failure(self):
361 req = self.make_request(emails=['foo@example.com'])382 req = self.make_request(emails=['foo@example.com'])
362 email = req._build_report_email(False, 'foo', 'gobbledygook')383 email = req._build_report_email(False, 'foo', 'gobbledygook')
363 self.assertEqual('Test results: FAILURE', email['Subject'])384 self.assertEqual(
385 'Test results: %s: FAILURE' % req.get_merge_description(),
386 email['Subject'])
364387
365 def test_report_email_recipients(self):388 def test_report_email_recipients(self):
366 req = self.make_request(emails=['foo@example.com', 'bar@example.com'])389 req = self.make_request(emails=['foo@example.com', 'bar@example.com'])
@@ -388,7 +411,8 @@
388 self.assertIsInstance(attachment, MIMEApplication)411 self.assertIsInstance(attachment, MIMEApplication)
389 self.assertEqual('application/x-gzip', attachment['Content-Type'])412 self.assertEqual('application/x-gzip', attachment['Content-Type'])
390 self.assertEqual(413 self.assertEqual(
391 'attachment; filename="%s.log.gz"' % req.get_nick(),414 'attachment; filename="%s-r%s.subunit.gz"' % (
415 req.get_nick(), req.get_revno()),
392 attachment['Content-Disposition'])416 attachment['Content-Disposition'])
393 self.assertEqual(417 self.assertEqual(
394 "gobbledygook", attachment.get_payload().decode('base64'))418 "gobbledygook", attachment.get_payload().decode('base64'))
@@ -623,8 +647,8 @@
623 [body, attachment] = user_message.get_payload()647 [body, attachment] = user_message.get_payload()
624 self.assertEqual('application/x-gzip', attachment['Content-Type'])648 self.assertEqual('application/x-gzip', attachment['Content-Type'])
625 self.assertEqual(649 self.assertEqual(
626 'attachment; filename="%s.log.gz"' % request.get_nick(),650 'attachment;',
627 attachment['Content-Disposition'])651 attachment['Content-Disposition'][:len('attachment;')])
628 attachment_contents = attachment.get_payload().decode('base64')652 attachment_contents = attachment.get_payload().decode('base64')
629 uncompressed = gunzip_data(attachment_contents)653 uncompressed = gunzip_data(attachment_contents)
630 self.assertEqual(654 self.assertEqual(