13779.3.4
by Steve Kowalik
Update copyright years, and fix more test failures for dead things. |
1 |
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
|
8687.15.17
by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/. |
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
6805.19.8
by Aaron Bentley
Add script to run code emails |
3 |
|
6805.19.42
by Aaron Bentley
Initial work on running mail jobs |
4 |
"""Test the sendbranchmail script"""
|
6805.19.8
by Aaron Bentley
Add script to run code emails |
5 |
|
6805.19.46
by Aaron Bentley
Get sendbranchmail under test. |
6 |
import transaction |
7 |
||
14565.2.12
by Curtis Hovey
Moved run_script to lp.services.scripts.tests |
8 |
from lp.services.scripts.tests import run_script |
14604.1.1
by Curtis Hovey
Separate test-authoring classes from test-running classes. |
9 |
from lp.testing.layers import ZopelessAppServerLayer |
8555.2.5
by Tim Penhey
Move the branch subscription enums. |
10 |
from lp.code.enums import ( |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
11 |
BranchSubscriptionDiffSize, |
12 |
BranchSubscriptionNotificationLevel, |
|
13 |
CodeReviewNotificationLevel, |
|
14 |
)
|
|
8138.1.2
by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing. |
15 |
from lp.code.model.branchjob import ( |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
16 |
RevisionMailJob, |
17 |
RevisionsAddedJob, |
|
18 |
)
|
|
13463.2.1
by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways). |
19 |
from lp.services.osutils import override_environ |
8555.2.5
by Tim Penhey
Move the branch subscription enums. |
20 |
from lp.testing import TestCaseWithFactory |
6805.19.46
by Aaron Bentley
Get sendbranchmail under test. |
21 |
|
22 |
||
23 |
class TestSendbranchmail(TestCaseWithFactory): |
|
24 |
||
7646.1.1
by Aaron Bentley
Get test failing due to missing branch. |
25 |
layer = ZopelessAppServerLayer |
6805.19.46
by Aaron Bentley
Get sendbranchmail under test. |
26 |
|
7797.1.12
by Aaron Bentley
Get sendbranchmail doing RevisionsAddedJobs |
27 |
def createBranch(self): |
9590.1.124
by Michael Hudson
yessssss i defeat the alcohol haze |
28 |
branch, tree = self.create_branch_and_tree() |
7675.708.3
by Tim Penhey
Add subscribed_by and unsubscribed_by to the subscribe and unsubscribe branch methods. |
29 |
branch.subscribe( |
30 |
branch.registrant, |
|
6805.19.46
by Aaron Bentley
Get sendbranchmail under test. |
31 |
BranchSubscriptionNotificationLevel.FULL, |
32 |
BranchSubscriptionDiffSize.WHOLEDIFF, |
|
7675.708.3
by Tim Penhey
Add subscribed_by and unsubscribed_by to the subscribe and unsubscribe branch methods. |
33 |
CodeReviewNotificationLevel.FULL, |
34 |
branch.registrant) |
|
7646.1.3
by Aaron Bentley
Get tests passing with diff generation |
35 |
transport = tree.bzrdir.root_transport |
36 |
transport.put_bytes('foo', 'bar') |
|
37 |
tree.add('foo') |
|
11040.1.12
by Aaron Bentley
Ensure commits work when username is unset. |
38 |
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
|
39 |
# required to generate the revision-id.
|
|
13463.2.1
by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways). |
40 |
with override_environ(BZR_EMAIL='me@example.com'): |
41 |
tree.commit('Added foo.', rev_id='rev1') |
|
7797.1.12
by Aaron Bentley
Get sendbranchmail doing RevisionsAddedJobs |
42 |
return branch, tree |
43 |
||
44 |
def test_sendbranchmail(self): |
|
45 |
"""Ensure sendbranchmail runs and sends email."""
|
|
9590.1.124
by Michael Hudson
yessssss i defeat the alcohol haze |
46 |
self.useBzrBranches() |
7797.1.12
by Aaron Bentley
Get sendbranchmail doing RevisionsAddedJobs |
47 |
branch, tree = self.createBranch() |
13626.4.5
by Danilo Segan
Fix failed tests. |
48 |
mail_job = RevisionMailJob.create( |
13779.3.1
by Steve Kowalik
Consign StaticDiff and all that supported it to a watery grave. |
49 |
branch, 1, 'from@example.org', 'body', 'foo') |
6805.19.46
by Aaron Bentley
Get sendbranchmail under test. |
50 |
transaction.commit() |
6805.19.42
by Aaron Bentley
Initial work on running mail jobs |
51 |
retcode, stdout, stderr = run_script( |
52 |
'cronscripts/sendbranchmail.py', []) |
|
7675.624.74
by Tim Penhey
Some more lock files, some more job runs. |
53 |
self.assertEqual( |
13463.2.1
by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways). |
54 |
'INFO Creating lockfile: /var/lock/launchpad-sendbranchmail.lock\n' |
13626.4.5
by Danilo Segan
Fix failed tests. |
55 |
'INFO Running RevisionMailJob (ID %d) in status Waiting\n' |
56 |
'INFO Ran 1 RevisionMailJobs.\n' % mail_job.job.id, stderr) |
|
7797.1.18
by Aaron Bentley
Output via logger instead of stdout |
57 |
self.assertEqual('', stdout) |
7675.29.1
by Guilherme Salgado
merge from mainline |
58 |
self.assertEqual(0, retcode) |
59 |
||
9314.2.1
by Aaron Bentley
Ensure oops processing works for branch jobs. |
60 |
def test_sendbranchmail_handles_oops(self): |
61 |
"""Ensure sendbranchmail runs and sends email."""
|
|
62 |
self.useTempBzrHome() |
|
63 |
branch = self.factory.makeBranch() |
|
13779.3.4
by Steve Kowalik
Update copyright years, and fix more test failures for dead things. |
64 |
RevisionsAddedJob.create( |
65 |
branch, 'rev1', 'rev2', 'from@example.org') |
|
9314.2.1
by Aaron Bentley
Ensure oops processing works for branch jobs. |
66 |
transaction.commit() |
67 |
retcode, stdout, stderr = run_script( |
|
68 |
'cronscripts/sendbranchmail.py', []) |
|
7675.624.74
by Tim Penhey
Some more lock files, some more job runs. |
69 |
self.assertIn( |
13463.2.1
by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways). |
70 |
'INFO Creating lockfile: /var/lock/launchpad-sendbranchmail.lock\n', |
7675.624.74
by Tim Penhey
Some more lock files, some more job runs. |
71 |
stderr) |
9314.1.6
by Aaron Bentley
Log oopses for sendbranchmail. |
72 |
self.assertIn('INFO Job resulted in OOPS:', stderr) |
73 |
self.assertIn('INFO Ran 0 RevisionMailJobs.\n', stderr) |
|
9314.2.1
by Aaron Bentley
Ensure oops processing works for branch jobs. |
74 |
self.assertEqual('', stdout) |
75 |
self.assertEqual(0, retcode) |
|
76 |
||
7797.1.12
by Aaron Bentley
Get sendbranchmail doing RevisionsAddedJobs |
77 |
def test_revision_added_job(self): |
7797.1.16
by Aaron Bentley
Clean ups |
78 |
"""RevisionsAddedJobs are run by sendbranchmail."""
|
9590.1.124
by Michael Hudson
yessssss i defeat the alcohol haze |
79 |
self.useBzrBranches() |
7797.1.12
by Aaron Bentley
Get sendbranchmail doing RevisionsAddedJobs |
80 |
branch, tree = self.createBranch() |
81 |
tree.bzrdir.root_transport.put_bytes('foo', 'baz') |
|
13463.2.1
by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways). |
82 |
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
|
83 |
# required to generate the revision-id.
|
|
84 |
with override_environ(BZR_EMAIL='me@example.com'): |
|
85 |
tree.commit('Added foo.', rev_id='rev2') |
|
13626.4.5
by Danilo Segan
Fix failed tests. |
86 |
job = RevisionsAddedJob.create( |
7797.1.12
by Aaron Bentley
Get sendbranchmail doing RevisionsAddedJobs |
87 |
branch, 'rev1', 'rev2', 'from@example.org') |
88 |
transaction.commit() |
|
89 |
retcode, stdout, stderr = run_script( |
|
90 |
'cronscripts/sendbranchmail.py', []) |
|
7675.624.74
by Tim Penhey
Some more lock files, some more job runs. |
91 |
self.assertEqual( |
13463.2.1
by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways). |
92 |
'INFO Creating lockfile: /var/lock/launchpad-sendbranchmail.lock\n' |
13626.4.5
by Danilo Segan
Fix failed tests. |
93 |
'INFO Running RevisionsAddedJob (ID %d) in status Waiting\n' |
94 |
'INFO Ran 1 RevisionMailJobs.\n' % job.job.id, |
|
7675.624.74
by Tim Penhey
Some more lock files, some more job runs. |
95 |
stderr) |
7797.1.18
by Aaron Bentley
Output via logger instead of stdout |
96 |
self.assertEqual('', stdout) |
7797.1.12
by Aaron Bentley
Get sendbranchmail doing RevisionsAddedJobs |
97 |
self.assertEqual(0, retcode) |