~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/codehosting/tests/test_jobs.py

  • Committer: Brad Crittenden
  • Date: 2011-09-07 13:25:28 UTC
  • mfrom: (13893 devel)
  • mto: This revision was merged to the branch mainline in revision 13900.
  • Revision ID: bac@canonical.com-20110907132528-jh7tekyw2dfutcq0
MergeĀ fromĀ devel

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Tests for Job-running facilities."""
5
 
 
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,
12
 
    )
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
18
 
 
19
 
 
20
 
class TestRevisionMailJob(TestCaseWithFactory):
21
 
    """Ensure RevisionMailJob behaves as expected."""
22
 
 
23
 
    layer = LaunchpadZopelessLayer
24
 
 
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")
35
 
        tree.add('hello.txt')
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)
45
 
        runner.runJob(job)
46
 
        existing_diff = StaticDiff.selectOneBy(
47
 
            from_revision_id='null:', to_revision_id=to_revision_id)
48
 
        self.assertIsNot(None, existing_diff)