1
# Copyright 2009 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Tests for Job-running facilities."""
6
from canonical.config import config
7
from canonical.testing.layers import LaunchpadZopelessLayer
8
from lp.code.enums import (
9
BranchSubscriptionDiffSize,
10
BranchSubscriptionNotificationLevel,
11
CodeReviewNotificationLevel,
13
from lp.code.model.branchjob import RevisionMailJob
14
from lp.code.model.diff import StaticDiff
15
from lp.services.job.runner import JobRunner
16
from lp.services.osutils import override_environ
17
from lp.testing import TestCaseWithFactory
20
class TestRevisionMailJob(TestCaseWithFactory):
21
"""Ensure RevisionMailJob behaves as expected."""
23
layer = LaunchpadZopelessLayer
25
def test_runJob_generates_diff(self):
26
"""Ensure that a diff is actually generated in this environment."""
27
self.useBzrBranches(direct_database=True)
28
branch, tree = self.create_branch_and_tree()
29
branch.subscribe(branch.registrant,
30
BranchSubscriptionNotificationLevel.FULL,
31
BranchSubscriptionDiffSize.WHOLEDIFF,
32
CodeReviewNotificationLevel.FULL, branch.registrant)
33
tree_transport = tree.bzrdir.root_transport
34
tree_transport.put_bytes("hello.txt", "Hello World\n")
36
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
37
# required to generate the revision-id.
38
with override_environ(BZR_EMAIL='me@example.com'):
39
to_revision_id = tree.commit('rev1', timestamp=1e9, timezone=0)
40
job = RevisionMailJob.create(
41
branch, 1, 'from@example.org', 'body', True, 'subject')
42
LaunchpadZopelessLayer.txn.commit()
43
LaunchpadZopelessLayer.switchDbUser(config.sendbranchmail.dbuser)
44
runner = JobRunner(job)
46
existing_diff = StaticDiff.selectOneBy(
47
from_revision_id='null:', to_revision_id=to_revision_id)
48
self.assertIsNot(None, existing_diff)