Merge lp:~thumper/launchpad/send-mail-job-logging into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 10923
Proposed branch: lp:~thumper/launchpad/send-mail-job-logging
Merge into: lp:launchpad
Diff against target: 59 lines (+25/-1)
2 files modified
lib/lp/code/model/branchjob.py (+14/-0)
lib/lp/code/model/tests/test_branchjob.py (+11/-1)
To merge this branch: bzr merge lp:~thumper/launchpad/send-mail-job-logging
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+25939@code.launchpad.net

Commit message

Provide a repr method for derived branch job.

Description of the change

Add a repr method for the derived branch jobs. This will be emitted in the log files by the job runner class at the DEBUG level. This will help a lot with the debugging of branch job related issues (like bug 585126).

tests:
  TestRevisionMailJob

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Argh, fixed the docstrings.

=== modified file 'lib/lp/code/model/tests/test_branchjob.py'
--- lib/lp/code/model/tests/test_branchjob.py 2010-05-25 05:10:57 +0000
+++ lib/lp/code/model/tests/test_branchjob.py 2010-05-25 05:19:13 +0000
@@ -303,14 +303,14 @@
     layer = LaunchpadZopelessLayer

     def test_providesInterface(self):
- """Ensure that BranchDiffJob implements IBranchDiffJob."""
+ """Ensure that RevisionMailJob implements IRevisionMailJob."""
         branch = self.factory.makeAnyBranch()
         job = RevisionMailJob.create(
             branch, 0, '<email address hidden>', 'hello', False, 'subject')
         verifyObject(IRevisionMailJob, job)

     def test_repr(self):
- """Ensure that BranchDiffJob implements IBranchDiffJob."""
+ """Ensure that the revision mail job as a reasonable repr."""
         branch = self.factory.makeAnyBranch()
         job = RevisionMailJob.create(
             branch, 0, '<email address hidden>', 'hello', False, 'subject')

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Looks fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/branchjob.py'
2--- lib/lp/code/model/branchjob.py 2010-04-23 05:29:30 +0000
3+++ lib/lp/code/model/branchjob.py 2010-05-26 23:18:37 +0000
4@@ -183,6 +183,14 @@
5 def __init__(self, branch_job):
6 self.context = branch_job
7
8+ def __repr__(self):
9+ branch = self.branch
10+ return '<%(job_type)s branch job (%(id)s) for %(branch)s>' % {
11+ 'job_type': self.context.job_type.name,
12+ 'id': self.context.id,
13+ 'branch': branch.unique_name,
14+ }
15+
16 # XXX: henninge 2009-02-20 bug=331919: These two standard operators
17 # should be implemented by delegates().
18 def __eq__(self, other):
19@@ -929,6 +937,12 @@
20
21 class_job_type = BranchJobType.RECLAIM_BRANCH_SPACE
22
23+ def __repr__(self):
24+ return '<RECLAIM_BRANCH_SPACE branch job (%(id)s) for %(branch)s>' % {
25+ 'id': self.context.id,
26+ 'branch': self.branch_id,
27+ }
28+
29 @classmethod
30 def create(cls, branch_id):
31 """See `IBranchDiffJobSource`."""
32
33=== modified file 'lib/lp/code/model/tests/test_branchjob.py'
34--- lib/lp/code/model/tests/test_branchjob.py 2010-04-27 09:05:44 +0000
35+++ lib/lp/code/model/tests/test_branchjob.py 2010-05-26 23:18:37 +0000
36@@ -303,12 +303,22 @@
37 layer = LaunchpadZopelessLayer
38
39 def test_providesInterface(self):
40- """Ensure that BranchDiffJob implements IBranchDiffJob."""
41+ """Ensure that RevisionMailJob implements IRevisionMailJob."""
42 branch = self.factory.makeAnyBranch()
43 job = RevisionMailJob.create(
44 branch, 0, 'from@example.com', 'hello', False, 'subject')
45 verifyObject(IRevisionMailJob, job)
46
47+ def test_repr(self):
48+ """Ensure that the revision mail job as a reasonable repr."""
49+ branch = self.factory.makeAnyBranch()
50+ job = RevisionMailJob.create(
51+ branch, 0, 'from@example.com', 'hello', False, 'subject')
52+ self.assertEqual(
53+ '<REVISION_MAIL branch job (%s) for %s>'
54+ % (job.context.id, branch.unique_name),
55+ repr(job))
56+
57 def test_run_sends_mail(self):
58 """Ensure RevisionMailJob.run sends mail with correct values."""
59 branch = self.factory.makeAnyBranch()