~launchpad-pqm/launchpad/devel

13597.1.1 by Jeroen Vermeulen
Get rid of factory.make[Ubuntu]DistroRelease. And some lint.
1
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
9636.4.2 by Michael Hudson
add some boilerplate
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
9636.4.30 by Michael Hudson
little more
4
"""Tests for making new source package branches just after a distro release.
9636.4.26 by Michael Hudson
i think all tests finally pass
5
"""
9636.4.2 by Michael Hudson
add some boilerplate
6
7
__metaclass__ = type
8
9636.4.33 by Michael Hudson
failing scripty tests
9
import os
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
10
import re
11
from StringIO import StringIO
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
12
from subprocess import (
13
    PIPE,
14
    Popen,
15
    STDOUT,
16
    )
9636.4.37 by Michael Hudson
dear <deity> please let this be it
17
import textwrap
9636.4.2 by Michael Hudson
add some boilerplate
18
import unittest
19
9636.4.20 by Michael Hudson
more tests, fixes
20
from bzrlib.branch import Branch
9636.4.6 by Michael Hudson
not very unitty but a test case
21
from bzrlib.bzrdir import BzrDir
22
from bzrlib.errors import NotStacked
23
from bzrlib.tests import TestCaseWithTransport
9636.4.19 by Michael Hudson
moar tests
24
from bzrlib.transport import get_transport
9636.4.6 by Michael Hudson
not very unitty but a test case
25
from bzrlib.transport.chroot import ChrootServer
9636.4.28 by Michael Hudson
address some comments from jml
26
from lazr.uri import URI
9636.4.8 by Michael Hudson
happy case test passes
27
import transaction
11573.7.1 by Tim Penhey
The test that I'm reasonably sure is enough to indicate that newly created distro branches won't need a scan.
28
from zope.component import getUtility
11573.7.3 by Tim Penhey
Avoid the scan.
29
from zope.security.proxy import removeSecurityProxy
9636.4.8 by Michael Hudson
happy case test passes
30
9636.4.33 by Michael Hudson
failing scripty tests
31
from canonical.config import config
9719.2.14 by Michael Hudson
grr
32
from canonical.testing.layers import LaunchpadZopelessLayer
11573.5.1 by Tim Penhey
Check the lifecycle status of the branches.
33
from lp.code.enums import BranchLifecycleStatus
11573.7.1 by Tim Penhey
The test that I'm reasonably sure is enough to indicate that newly created distro branches won't need a scan.
34
from lp.code.interfaces.branchjob import IBranchScanJobSource
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
35
from lp.codehosting.branchdistro import (
36
    DistroBrancher,
37
    switch_branches,
38
    )
9636.4.6 by Michael Hudson
not very unitty but a test case
39
from lp.codehosting.vfs import branch_id_to_path
9636.4.7 by Michael Hudson
start testing clone branch
40
from lp.registry.interfaces.pocket import PackagePublishingPocket
12070.1.4 by Tim Penhey
Move FakeLogger and BufferLogger to lp.services.log.logging and delete the QuietFakeLogger.
41
from lp.services.log.logger import (
13597.1.1 by Jeroen Vermeulen
Get rid of factory.make[Ubuntu]DistroRelease. And some lint.
42
    BufferLogger,
12070.1.4 by Tim Penhey
Move FakeLogger and BufferLogger to lp.services.log.logging and delete the QuietFakeLogger.
43
    FakeLogger,
44
    )
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
45
from lp.services.osutils import override_environ
9636.4.7 by Michael Hudson
start testing clone branch
46
from lp.testing import TestCaseWithFactory
9636.4.26 by Michael Hudson
i think all tests finally pass
47
48
# We say "RELEASE" often enough to not want to say "PackagePublishingPocket."
49
# each time.
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
50
RELEASE = PackagePublishingPocket.RELEASE
51
9636.4.6 by Michael Hudson
not very unitty but a test case
52
53
class FakeBranch:
9636.4.26 by Michael Hudson
i think all tests finally pass
54
    """Just enough of a Branch to pass `test_switch_branches`."""
55
9636.4.6 by Michael Hudson
not very unitty but a test case
56
    def __init__(self, id):
57
        self.id = id
9636.4.26 by Michael Hudson
i think all tests finally pass
58
9636.4.6 by Michael Hudson
not very unitty but a test case
59
    @property
60
    def unique_name(self):
61
        return branch_id_to_path(self.id)
62
63
64
class TestSwitchBranches(TestCaseWithTransport):
9636.4.30 by Michael Hudson
little more
65
    """Tests for `switch_branches`."""
9636.4.6 by Michael Hudson
not very unitty but a test case
66
67
    def test_switch_branches(self):
9636.4.30 by Michael Hudson
little more
68
        # switch_branches moves a branch to the new location and places a
69
        # branch (with no revisions) stacked on the new branch in the old
70
        # location.
9636.4.6 by Michael Hudson
not very unitty but a test case
71
72
        chroot_server = ChrootServer(self.get_transport())
10197.5.9 by Michael Hudson
even more
73
        chroot_server.start_server()
74
        self.addCleanup(chroot_server.stop_server)
9636.4.28 by Michael Hudson
address some comments from jml
75
        scheme = chroot_server.get_url().rstrip('/:')
9636.4.6 by Michael Hudson
not very unitty but a test case
76
77
        old_branch = FakeBranch(1)
78
        self.get_transport(old_branch.unique_name).create_prefix()
79
        tree = self.make_branch_and_tree(old_branch.unique_name)
11040.1.12 by Aaron Bentley
Ensure commits work when username is unset.
80
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
81
        # required to generate the revision-id.
82
        with override_environ(BZR_EMAIL='me@example.com'):
83
            tree.commit(message='.')
9636.4.6 by Michael Hudson
not very unitty but a test case
84
85
        new_branch = FakeBranch(2)
86
87
        switch_branches('.', scheme, old_branch, new_branch)
88
89
        # Post conditions:
90
        # 1. unstacked branch in new_branch's location
91
        # 2. stacked branch with no revisions in repo at old_branch
92
        # 3. last_revision() the same for two branches
93
9636.4.28 by Michael Hudson
address some comments from jml
94
        old_location_bzrdir = BzrDir.open(str(URI(
95
            scheme=scheme, host='', path='/' + old_branch.unique_name)))
96
        new_location_bzrdir = BzrDir.open(str(URI(
97
            scheme=scheme, host='', path='/' + new_branch.unique_name)))
9636.4.6 by Michael Hudson
not very unitty but a test case
98
99
        old_location_branch = old_location_bzrdir.open_branch()
100
        new_location_branch = new_location_bzrdir.open_branch()
101
102
        # 1. unstacked branch in new_branch's location
103
        self.assertRaises(NotStacked, new_location_branch.get_stacked_on_url)
104
105
        # 2. stacked branch with no revisions in repo at old_branch
106
        self.assertEqual(
107
            '/' + new_branch.unique_name,
108
            old_location_branch.get_stacked_on_url())
109
        self.assertEqual(
110
            [], old_location_bzrdir.open_repository().all_revision_ids())
111
112
        # 3. last_revision() the same for two branches
113
        self.assertEqual(
114
            old_location_branch.last_revision(),
115
            new_location_branch.last_revision())
9636.4.2 by Michael Hudson
add some boilerplate
116
117
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
118
class TestDistroBrancher(TestCaseWithFactory):
9636.4.31 by Michael Hudson
thrumpty million test comments
119
    """Tests for `DistroBrancher`."""
9636.4.7 by Michael Hudson
start testing clone branch
120
9719.2.14 by Michael Hudson
grr
121
    layer = LaunchpadZopelessLayer
9636.4.7 by Michael Hudson
start testing clone branch
122
9636.4.16 by Michael Hudson
update existing tests to new structure. need to write a boatload more though
123
    def setUp(self):
124
        TestCaseWithFactory.setUp(self)
9590.1.114 by Michael Hudson
getting close
125
        self.useBzrBranches(direct_database=True)
9636.4.16 by Michael Hudson
update existing tests to new structure. need to write a boatload more though
126
13046.1.1 by Aaron Bentley
branch-distro.py works with empty branches.
127
    def makeOfficialPackageBranch(self, distroseries=None,
128
                                  make_revisions=True):
9636.4.30 by Michael Hudson
little more
129
        """Make an official package branch with an underlying bzr branch."""
9636.4.16 by Michael Hudson
update existing tests to new structure. need to write a boatload more though
130
        db_branch = self.factory.makePackageBranch(distroseries=distroseries)
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
131
        db_branch.sourcepackage.setBranch(RELEASE, db_branch, db_branch.owner)
13046.1.1 by Aaron Bentley
branch-distro.py works with empty branches.
132
        if make_revisions:
133
            self.factory.makeRevisionsForBranch(db_branch, count=1)
9636.4.16 by Michael Hudson
update existing tests to new structure. need to write a boatload more though
134
135
        transaction.commit()
136
137
        _, tree = self.create_branch_and_tree(
9590.1.82 by Michael Hudson
start fixing the branch-distro tests
138
            tree_location=self.factory.getUniqueString(), db_branch=db_branch)
11040.1.12 by Aaron Bentley
Ensure commits work when username is unset.
139
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
140
        # required to generate the revision-id.
13046.1.1 by Aaron Bentley
branch-distro.py works with empty branches.
141
        if make_revisions:
142
            with override_environ(BZR_EMAIL='me@example.com'):
143
                tree.commit('')
9636.4.16 by Michael Hudson
update existing tests to new structure. need to write a boatload more though
144
145
        return db_branch
146
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
147
    def makeNewSeriesAndBrancher(self, distroseries=None):
9636.4.30 by Michael Hudson
little more
148
        """Make a DistroBrancher.
149
150
        Any messages logged by this DistroBrancher can be checked by calling
151
        `assertLogMessages` below.
152
        """
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
153
        if distroseries is None:
13597.1.1 by Jeroen Vermeulen
Get rid of factory.make[Ubuntu]DistroRelease. And some lint.
154
            distroseries = self.factory.makeDistroSeries()
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
155
        self._log_file = StringIO()
13597.1.1 by Jeroen Vermeulen
Get rid of factory.make[Ubuntu]DistroRelease. And some lint.
156
        new_distroseries = self.factory.makeDistroSeries(
9772.5.1 by Michael Hudson
test in fix
157
            distribution=distroseries.distribution)
9636.4.34 by Michael Hudson
begin testing as the db user
158
        transaction.commit()
159
        self.layer.switchDbUser('branch-distro')
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
160
        return DistroBrancher(
9636.4.32 by Michael Hudson
XXX reduction
161
            FakeLogger(self._log_file), distroseries, new_distroseries)
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
162
9636.4.18 by Michael Hudson
test and inevitable fixes
163
    def clearLogMessages(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
164
        """Forget about all logged messages seen so far."""
9636.4.18 by Michael Hudson
test and inevitable fixes
165
        self._log_file.seek(0, 0)
166
        self._log_file.truncate()
167
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
168
    def assertLogMessages(self, patterns):
9636.4.31 by Michael Hudson
thrumpty million test comments
169
        """Assert that the messages logged meet expectations.
170
171
        :param patterns: A list of regular expressions.  The length must match
172
            the number of messages logged, and then each pattern must match
173
            the messages logged in order.
174
        """
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
175
        log_messages = self._log_file.getvalue().splitlines()
176
        if len(log_messages) > len(patterns):
177
            self.fail(
178
                "More log messages (%s) than expected (%s)" %
9636.4.18 by Michael Hudson
test and inevitable fixes
179
                (log_messages, patterns))
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
180
        elif len(log_messages) < len(patterns):
181
            self.fail(
182
                "Fewer log messages (%s) than expected (%s)" %
9636.4.18 by Michael Hudson
test and inevitable fixes
183
                (log_messages, patterns))
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
184
        for pattern, message in zip(patterns, log_messages):
185
            if not re.match(pattern, message):
9636.4.19 by Michael Hudson
moar tests
186
                self.fail("%r does not match %r" % (pattern, message))
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
187
9636.4.32 by Michael Hudson
XXX reduction
188
    def test_DistroBrancher_same_distro_check(self):
189
        # DistroBrancher.__init__ raises AssertionError if the two
190
        # distroseries passed are not from the same distribution.
191
        self.assertRaises(
192
            AssertionError, DistroBrancher, None,
13597.1.1 by Jeroen Vermeulen
Get rid of factory.make[Ubuntu]DistroRelease. And some lint.
193
            self.factory.makeDistroSeries(),
194
            self.factory.makeDistroSeries())
9636.4.32 by Michael Hudson
XXX reduction
195
196
    def test_DistroBrancher_same_distroseries_check(self):
197
        # DistroBrancher.__init__ raises AssertionError if passed the same
198
        # distroseries twice.
13597.1.1 by Jeroen Vermeulen
Get rid of factory.make[Ubuntu]DistroRelease. And some lint.
199
        distroseries = self.factory.makeDistroSeries()
9636.4.32 by Michael Hudson
XXX reduction
200
        self.assertRaises(
201
            AssertionError, DistroBrancher, None, distroseries, distroseries)
202
203
    def test_fromNames(self):
9636.4.41 by Michael Hudson
address review comments
204
        # DistroBrancher.fromNames constructs a DistroBrancher from the names
205
        # of a distribution and two distroseries within it.
9636.4.32 by Michael Hudson
XXX reduction
206
        distribution = self.factory.makeDistribution()
13597.1.1 by Jeroen Vermeulen
Get rid of factory.make[Ubuntu]DistroRelease. And some lint.
207
        distroseries1 = self.factory.makeDistroSeries(
9636.4.32 by Michael Hudson
XXX reduction
208
            distribution=distribution)
13597.1.1 by Jeroen Vermeulen
Get rid of factory.make[Ubuntu]DistroRelease. And some lint.
209
        distroseries2 = self.factory.makeDistroSeries(
9636.4.32 by Michael Hudson
XXX reduction
210
            distribution=distribution)
211
        brancher = DistroBrancher.fromNames(
9636.4.36 by Michael Hudson
er, hooray unit tests
212
            None, distribution.name, distroseries1.name, distroseries2.name)
9636.4.32 by Michael Hudson
XXX reduction
213
        self.assertEqual(
214
            [distroseries1, distroseries2],
215
            [brancher.old_distroseries, brancher.new_distroseries])
216
9636.4.31 by Michael Hudson
thrumpty million test comments
217
    # A word on testing strategy: we don't directly test the post conditions
218
    # of makeOneNewBranch, but we do test that it satisfies checkOneBranch and
219
    # the tests for checkOneBranch verify that this function rejects various
220
    # ways in which makeOneNewBranch could conceivably fail.
221
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
222
    def test_makeOneNewBranch(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
223
        # makeOneNewBranch creates an official package branch in the new
224
        # distroseries.
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
225
        db_branch = self.makeOfficialPackageBranch()
226
9636.4.26 by Michael Hudson
i think all tests finally pass
227
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
228
        brancher.makeOneNewBranch(db_branch)
229
9636.4.26 by Michael Hudson
i think all tests finally pass
230
        new_branch = brancher.new_distroseries.getSourcePackage(
231
            db_branch.sourcepackage.name).getBranch(RELEASE)
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
232
9636.4.41 by Michael Hudson
address review comments
233
        self.assertIsNot(None, new_branch)
9772.5.1 by Michael Hudson
test in fix
234
        # The branch owner is the same, the source package name is the same,
235
        # the distroseries is the new one and the branch name is the name of
236
        # the new distroseries.
9636.4.41 by Michael Hudson
address review comments
237
        self.assertEqual(
238
            [db_branch.owner, db_branch.distribution,
9772.5.1 by Michael Hudson
test in fix
239
             db_branch.sourcepackagename, brancher.new_distroseries.name],
9636.4.41 by Michael Hudson
address review comments
240
            [new_branch.owner, new_branch.distribution,
241
             new_branch.sourcepackagename, new_branch.name])
11573.5.1 by Tim Penhey
Check the lifecycle status of the branches.
242
        # The new branch is set in the development state, and the old one is
243
        # mature.
244
        self.assertEqual(
245
            BranchLifecycleStatus.DEVELOPMENT, new_branch.lifecycle_status)
246
        self.assertEqual(
247
            BranchLifecycleStatus.MATURE, db_branch.lifecycle_status)
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
248
11573.7.1 by Tim Penhey
The test that I'm reasonably sure is enough to indicate that newly created distro branches won't need a scan.
249
    def test_makeOneNewBranch_avoids_need_for_scan(self):
250
        # makeOneNewBranch sets the appropriate properties of the new branch
251
        # so a scan is unnecessary.  This can be done because we are making a
252
        # copy of the source branch.
253
        db_branch = self.makeOfficialPackageBranch()
254
        self.factory.makeRevisionsForBranch(db_branch, count=10)
255
        tip_revision_id = db_branch.last_mirrored_id
256
        self.assertIsNot(None, tip_revision_id)
11573.7.3 by Tim Penhey
Avoid the scan.
257
        # The makeRevisionsForBranch will create a scan job for the db_branch.
258
        # We don't really care about that, but what we do care about is that
259
        # no new jobs are created.
260
        existing_scan_job_count = len(
261
            list(getUtility(IBranchScanJobSource).iterReady()))
11573.7.1 by Tim Penhey
The test that I'm reasonably sure is enough to indicate that newly created distro branches won't need a scan.
262
11573.7.3 by Tim Penhey
Avoid the scan.
263
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
264
        brancher.makeOneNewBranch(db_branch)
11573.7.1 by Tim Penhey
The test that I'm reasonably sure is enough to indicate that newly created distro branches won't need a scan.
265
        new_branch = brancher.new_distroseries.getSourcePackage(
266
            db_branch.sourcepackage.name).getBranch(RELEASE)
267
268
        self.assertEqual(tip_revision_id, new_branch.last_mirrored_id)
269
        self.assertEqual(tip_revision_id, new_branch.last_scanned_id)
270
        # Make sure that the branch revisions have been copied.
11573.7.3 by Tim Penhey
Avoid the scan.
271
        old_ancestry, old_history = removeSecurityProxy(
272
            db_branch).getScannerData()
273
        new_ancestry, new_history = removeSecurityProxy(
274
            new_branch).getScannerData()
11573.7.1 by Tim Penhey
The test that I'm reasonably sure is enough to indicate that newly created distro branches won't need a scan.
275
        self.assertEqual(old_ancestry, new_ancestry)
276
        self.assertEqual(old_history, new_history)
11573.7.3 by Tim Penhey
Avoid the scan.
277
        self.assertFalse(new_branch.pending_writes)
11573.7.7 by Tim Penhey
Test the expected stacking.
278
        self.assertIs(None, new_branch.stacked_on)
279
        self.assertEqual(new_branch, db_branch.stacked_on)
11573.7.3 by Tim Penhey
Avoid the scan.
280
        # The script doesn't have permission to create branch jobs, but just
281
        # to be insanely paradoid.
282
        transaction.commit()
283
        self.layer.switchDbUser('launchpad')
284
        scan_jobs = list(getUtility(IBranchScanJobSource).iterReady())
285
        self.assertEqual(existing_scan_job_count, len(scan_jobs))
11573.7.1 by Tim Penhey
The test that I'm reasonably sure is enough to indicate that newly created distro branches won't need a scan.
286
9636.4.26 by Michael Hudson
i think all tests finally pass
287
    def test_makeOneNewBranch_inconsistent_branch(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
288
        # makeOneNewBranch skips over an inconsistent official package branch
289
        # (see `checkConsistentOfficialPackageBranch` for precisely what an
290
        # "inconsistent official package branch" is).
9636.4.36 by Michael Hudson
er, hooray unit tests
291
        unofficial_branch = self.factory.makePackageBranch()
9636.4.40 by Michael Hudson
lint
292
        brancher = self.makeNewSeriesAndBrancher(
293
            unofficial_branch.distroseries)
9636.4.36 by Michael Hudson
er, hooray unit tests
294
        brancher.makeOneNewBranch(unofficial_branch)
9636.4.26 by Michael Hudson
i think all tests finally pass
295
296
        new_branch = brancher.new_distroseries.getSourcePackage(
9636.4.36 by Michael Hudson
er, hooray unit tests
297
            unofficial_branch.sourcepackage.name).getBranch(RELEASE)
9636.4.41 by Michael Hudson
address review comments
298
        self.assertIs(None, new_branch)
9636.4.26 by Michael Hudson
i think all tests finally pass
299
        self.assertLogMessages(
9636.4.41 by Michael Hudson
address review comments
300
            ['^WARNING .* is not an official branch$',
301
             '^WARNING Skipping branch$'])
9636.4.26 by Michael Hudson
i think all tests finally pass
302
13046.1.1 by Aaron Bentley
branch-distro.py works with empty branches.
303
    def test_makeOnewNewBranch_empty_branch(self):
304
        # Branches with no commits work.
305
        db_branch = self.makeOfficialPackageBranch(make_revisions=False)
306
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
13046.1.2 by Aaron Bentley
Fix lint.
307
        brancher.makeOneNewBranch(db_branch)
13046.1.1 by Aaron Bentley
branch-distro.py works with empty branches.
308
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
309
    def test_makeNewBranches(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
310
        # makeNewBranches calls makeOneNewBranch for each official branch in
311
        # the old distroseries.
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
312
        db_branch = self.makeOfficialPackageBranch()
313
        db_branch2 = self.makeOfficialPackageBranch(
314
            distroseries=db_branch.distroseries)
315
13597.1.1 by Jeroen Vermeulen
Get rid of factory.make[Ubuntu]DistroRelease. And some lint.
316
        new_distroseries = self.factory.makeDistroSeries(
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
317
            distribution=db_branch.distribution)
318
319
        brancher = DistroBrancher(
12070.1.4 by Tim Penhey
Move FakeLogger and BufferLogger to lp.services.log.logging and delete the QuietFakeLogger.
320
            BufferLogger(), db_branch.distroseries, new_distroseries)
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
321
322
        brancher.makeNewBranches()
323
9636.4.32 by Michael Hudson
XXX reduction
324
        new_sourcepackage = new_distroseries.getSourcePackage(
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
325
            db_branch.sourcepackage.name)
326
        new_branch = new_sourcepackage.getBranch(RELEASE)
9636.4.32 by Michael Hudson
XXX reduction
327
        new_sourcepackage2 = new_distroseries.getSourcePackage(
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
328
            db_branch2.sourcepackage.name)
329
        new_branch2 = new_sourcepackage2.getBranch(RELEASE)
330
9636.4.41 by Michael Hudson
address review comments
331
        self.assertIsNot(None, new_branch)
332
        self.assertIsNot(None, new_branch2)
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
333
9636.4.28 by Michael Hudson
address some comments from jml
334
    def test_makeNewBranches_idempotent(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
335
        # makeNewBranches is idempotent in the sense that if a branch in the
336
        # old distroseries already has a counterpart in the new distroseries,
337
        # it is silently ignored.
9636.4.26 by Michael Hudson
i think all tests finally pass
338
        db_branch = self.makeOfficialPackageBranch()
339
340
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
341
        brancher.makeNewBranches()
342
        brancher.makeNewBranches()
343
344
        new_branch = brancher.new_distroseries.getSourcePackage(
345
            db_branch.sourcepackage.name).getBranch(RELEASE)
346
347
        self.assertIsNot(new_branch, None)
348
9636.4.31 by Michael Hudson
thrumpty million test comments
349
    def test_makeOneNewBranch_checks_ok(self):
350
        # After calling makeOneNewBranch for a branch, calling checkOneBranch
351
        # returns True for that branch.
9636.4.18 by Michael Hudson
test and inevitable fixes
352
        db_branch = self.makeOfficialPackageBranch()
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
353
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.18 by Michael Hudson
test and inevitable fixes
354
        brancher.makeOneNewBranch(db_branch)
355
        self.clearLogMessages()
356
        ok = brancher.checkOneBranch(db_branch)
357
        self.assertLogMessages([])
358
        self.assertTrue(ok)
359
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
360
    def test_checkConsistentOfficialPackageBranch_product_branch(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
361
        # checkConsistentOfficialPackageBranch returns False when passed a
362
        # product branch.
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
363
        db_branch = self.factory.makeProductBranch()
364
        brancher = self.makeNewSeriesAndBrancher()
365
        ok = brancher.checkConsistentOfficialPackageBranch(db_branch)
366
        self.assertLogMessages([
367
            '^WARNING Encountered unexpected product branch .*/.*/.*$'])
368
        self.assertFalse(ok)
369
370
    def test_checkConsistentOfficialPackageBranch_personal_branch(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
371
        # checkConsistentOfficialPackageBranch returns False when passed a
372
        # personal branch.
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
373
        db_branch = self.factory.makePersonalBranch()
374
        brancher = self.makeNewSeriesAndBrancher()
375
        ok = brancher.checkConsistentOfficialPackageBranch(db_branch)
376
        self.assertLogMessages([
377
            '^WARNING Encountered unexpected personal branch .*/.*/.*$'])
378
        self.assertFalse(ok)
379
380
    def test_checkConsistentOfficialPackageBranch_no_official_branch(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
381
        # checkConsistentOfficialPackageBranch returns False when passed a
382
        # branch which is not official for any package.
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
383
        db_branch = self.factory.makePackageBranch()
384
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
385
        ok = brancher.checkConsistentOfficialPackageBranch(db_branch)
386
        self.assertLogMessages(
9636.4.41 by Michael Hudson
address review comments
387
            ['^WARNING .*/.*/.* is not an official branch$'])
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
388
        self.assertFalse(ok)
389
9636.4.26 by Michael Hudson
i think all tests finally pass
390
    def test_checkConsistentOfficialPackageBranch_official_elsewhere(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
391
        # checkConsistentOfficialPackageBranch returns False when passed a
392
        # branch which is official for a sourcepackage that it is not a branch
393
        # for.
9636.4.26 by Michael Hudson
i think all tests finally pass
394
        db_branch = self.factory.makePackageBranch()
395
        self.factory.makeSourcePackage().setBranch(
396
            RELEASE, db_branch, db_branch.owner)
397
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
398
        ok = brancher.checkConsistentOfficialPackageBranch(db_branch)
399
        self.assertLogMessages(
400
            ['^WARNING .*/.*/.* is the official branch for .*/.*/.* but not '
401
             'its sourcepackage$'])
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
402
        self.assertFalse(ok)
403
9636.4.25 by Michael Hudson
more tests, including for branches official multiple times
404
    def test_checkConsistentOfficialPackageBranch_official_twice(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
405
        # checkConsistentOfficialPackageBranch returns False when passed a
406
        # branch that is official for two sourcepackages.
9636.4.25 by Michael Hudson
more tests, including for branches official multiple times
407
        db_branch = self.factory.makePackageBranch()
408
        db_branch.sourcepackage.setBranch(RELEASE, db_branch, db_branch.owner)
409
        self.factory.makeSourcePackage().setBranch(
410
            RELEASE, db_branch, db_branch.owner)
9636.4.34 by Michael Hudson
begin testing as the db user
411
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.25 by Michael Hudson
more tests, including for branches official multiple times
412
        ok = brancher.checkConsistentOfficialPackageBranch(db_branch)
9636.4.31 by Michael Hudson
thrumpty million test comments
413
        self.assertLogMessages([
414
            '^WARNING .*/.*/.* is official for multiple series: .*/.*/.*, '
415
            '.*/.*/.*$'])
9636.4.25 by Michael Hudson
more tests, including for branches official multiple times
416
        self.assertFalse(ok)
417
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
418
    def test_checkConsistentOfficialPackageBranch_ok(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
419
        # checkConsistentOfficialPackageBranch returns True when passed a
420
        # branch that is official for its sourcepackage and no other.
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
421
        db_branch = self.factory.makePackageBranch()
422
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
423
        db_branch.sourcepackage.setBranch(RELEASE, db_branch, db_branch.owner)
424
        ok = brancher.checkConsistentOfficialPackageBranch(db_branch)
425
        self.assertLogMessages([])
426
        self.assertTrue(ok)
427
9636.4.25 by Michael Hudson
more tests, including for branches official multiple times
428
    def test_checkOneBranch_inconsistent_old_package_branch(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
429
        # checkOneBranch returns False when passed a branch that is not a
430
        # consistent official package branch.
9636.4.34 by Michael Hudson
begin testing as the db user
431
        db_branch = self.factory.makePackageBranch()
9636.4.26 by Michael Hudson
i think all tests finally pass
432
        brancher = self.makeNewSeriesAndBrancher()
433
        ok = brancher.checkOneBranch(db_branch)
434
        self.assertFalse(ok)
435
        self.assertLogMessages(
436
            ['^WARNING .*/.*/.* is not an official branch$'])
437
438
    def test_checkOneBranch_no_new_official_branch(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
439
        # checkOneBranch returns False when there is no corresponding official
440
        # package branch in the new distroseries.
9636.4.25 by Michael Hudson
more tests, including for branches official multiple times
441
        db_branch = self.makeOfficialPackageBranch()
442
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
443
        ok = brancher.checkOneBranch(db_branch)
444
        self.assertFalse(ok)
445
        self.assertLogMessages(
446
            ['^WARNING No official branch found for .*/.*/.*$'])
447
9636.4.25 by Michael Hudson
more tests, including for branches official multiple times
448
    def test_checkOneBranch_inconsistent_new_package_branch(self):
9636.4.31 by Michael Hudson
thrumpty million test comments
449
        # checkOneBranch returns False when the corresponding official package
450
        # branch in the new distroseries is not consistent.
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
451
        db_branch = self.makeOfficialPackageBranch()
452
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.25 by Michael Hudson
more tests, including for branches official multiple times
453
        new_db_branch = brancher.makeOneNewBranch(db_branch)
9636.4.34 by Michael Hudson
begin testing as the db user
454
        self.layer.switchDbUser('launchpad')
9636.4.26 by Michael Hudson
i think all tests finally pass
455
        new_db_branch.setTarget(
456
            new_db_branch.owner,
457
            source_package=self.factory.makeSourcePackage())
9636.4.34 by Michael Hudson
begin testing as the db user
458
        transaction.commit()
459
        self.layer.switchDbUser('branch-distro')
9636.4.26 by Michael Hudson
i think all tests finally pass
460
        ok = brancher.checkOneBranch(new_db_branch)
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
461
        self.assertFalse(ok)
9636.4.18 by Michael Hudson
test and inevitable fixes
462
        self.assertLogMessages(
9636.4.26 by Michael Hudson
i think all tests finally pass
463
            ['^WARNING .*/.*/.* is the official branch for .*/.*/.* but not '
464
             'its sourcepackage$'])
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
465
9590.1.82 by Michael Hudson
start fixing the branch-distro tests
466
    def test_checkOneBranch_new_branch_missing(self):
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
467
        # checkOneBranch returns False when there is no bzr branch for the
468
        # database branch in the new distroseries.
469
        db_branch = self.makeOfficialPackageBranch()
470
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
471
        new_db_branch = brancher.makeOneNewBranch(db_branch)
9590.1.82 by Michael Hudson
start fixing the branch-distro tests
472
        url = 'lp-internal:///' + new_db_branch.unique_name
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
473
        get_transport(url).delete_tree('.bzr')
474
        ok = brancher.checkOneBranch(db_branch)
475
        self.assertFalse(ok)
476
        # Deleting the new branch will break the old branch, as that's stacked
477
        # on the new one.
478
        self.assertLogMessages([
9590.1.82 by Michael Hudson
start fixing the branch-distro tests
479
            '^WARNING No bzr branch at new location '
480
            'lp-internal:///.*/.*/.*/.*$',
481
            '^WARNING No bzr branch at old location '
482
            'lp-internal:///.*/.*/.*/.*$',
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
483
            ])
9636.4.31 by Michael Hudson
thrumpty million test comments
484
9590.1.83 by Michael Hudson
indentation screwup
485
    def test_checkOneBranch_old_branch_missing(self):
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
486
        # checkOneBranch returns False when there is no bzr branchfor the
487
        # database branch in old distroseries.
9636.4.19 by Michael Hudson
moar tests
488
        db_branch = self.makeOfficialPackageBranch()
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
489
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
490
        brancher.makeOneNewBranch(db_branch)
9590.1.83 by Michael Hudson
indentation screwup
491
        url = 'lp-internal:///' + db_branch.unique_name
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
492
        get_transport(url).delete_tree('.bzr')
9636.4.19 by Michael Hudson
moar tests
493
        ok = brancher.checkOneBranch(db_branch)
494
        self.assertFalse(ok)
495
        self.assertLogMessages([
9590.1.83 by Michael Hudson
indentation screwup
496
            '^WARNING No bzr branch at old location '
497
            'lp-internal:///.*/.*/.*/.*$'
9636.4.19 by Michael Hudson
moar tests
498
            ])
499
9590.1.83 by Michael Hudson
indentation screwup
500
    def test_checkOneBranch_new_stacked(self):
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
501
        # checkOneBranch returns False when the bzr branch for the database
502
        # branch in new distroseries is stacked.
9636.4.19 by Michael Hudson
moar tests
503
        db_branch = self.makeOfficialPackageBranch()
9590.1.83 by Michael Hudson
indentation screwup
504
        b, _ = self.create_branch_and_tree(self.factory.getUniqueString())
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
505
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
506
        new_db_branch = brancher.makeOneNewBranch(db_branch)
9590.1.83 by Michael Hudson
indentation screwup
507
        url = 'lp-internal:///' + new_db_branch.unique_name
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
508
        Branch.open(url).set_stacked_on_url('/' + b.unique_name)
9636.4.19 by Michael Hudson
moar tests
509
        ok = brancher.checkOneBranch(db_branch)
510
        self.assertFalse(ok)
511
        self.assertLogMessages([
9590.1.83 by Michael Hudson
indentation screwup
512
            '^WARNING New branch at lp-internal:///.*/.*/.*/.* is stacked on '
513
            '/.*/.*/.*, should be unstacked.$',
9636.4.19 by Michael Hudson
moar tests
514
            ])
515
9590.1.83 by Michael Hudson
indentation screwup
516
    def test_checkOneBranch_old_unstacked(self):
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
517
        # checkOneBranch returns False when the bzr branch for the database
518
        # branch in old distroseries is not stacked.
9636.4.20 by Michael Hudson
more tests, fixes
519
        db_branch = self.makeOfficialPackageBranch()
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
520
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
521
        brancher.makeOneNewBranch(db_branch)
9590.1.83 by Michael Hudson
indentation screwup
522
        url = 'lp-internal:///' + db_branch.unique_name
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
523
        old_bzr_branch = Branch.open(url)
524
        old_bzr_branch.set_stacked_on_url(None)
9636.4.20 by Michael Hudson
more tests, fixes
525
        ok = brancher.checkOneBranch(db_branch)
526
        self.assertLogMessages([
9590.1.83 by Michael Hudson
indentation screwup
527
            '^WARNING Old branch at lp-internal:///.*/.*/.*/.* is not '
528
            'stacked, should be stacked on /.*/.*/.*.$',
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
529
            '^.*has .* revisions.*$',
9636.4.20 by Michael Hudson
more tests, fixes
530
            ])
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
531
        self.assertFalse(ok)
9636.4.20 by Michael Hudson
more tests, fixes
532
9590.1.83 by Michael Hudson
indentation screwup
533
    def test_checkOneBranch_old_misstacked(self):
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
534
        # checkOneBranch returns False when the bzr branch for the database
535
        # branch in old distroseries stacked on some other branch than the
536
        # branch in the new distroseries.
9636.4.21 by Michael Hudson
more tests and fixes
537
        db_branch = self.makeOfficialPackageBranch()
9590.1.83 by Michael Hudson
indentation screwup
538
        b, _ = self.create_branch_and_tree(self.factory.getUniqueString())
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
539
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.21 by Michael Hudson
more tests and fixes
540
        brancher.makeOneNewBranch(db_branch)
9590.1.83 by Michael Hudson
indentation screwup
541
        url = 'lp-internal:///' + db_branch.unique_name
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
542
        Branch.open(url).set_stacked_on_url('/' + b.unique_name)
9636.4.21 by Michael Hudson
more tests and fixes
543
        ok = brancher.checkOneBranch(db_branch)
544
        self.assertLogMessages([
9590.1.83 by Michael Hudson
indentation screwup
545
            '^WARNING Old branch at lp-internal:///.*/.*/.*/.* is stacked on '
546
            '/.*/.*/.*, should be stacked on /.*/.*/.*.$',
9636.4.21 by Michael Hudson
more tests and fixes
547
            ])
548
        self.assertFalse(ok)
549
9590.1.83 by Michael Hudson
indentation screwup
550
    def test_checkOneBranch_old_has_revisions(self):
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
551
        # checkOneBranch returns False when the bzr branch for the database
552
        # branch in old distroseries has a repository that contains revisions.
9636.4.21 by Michael Hudson
more tests and fixes
553
        db_branch = self.makeOfficialPackageBranch()
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
554
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.21 by Michael Hudson
more tests and fixes
555
        brancher.makeOneNewBranch(db_branch)
9590.1.83 by Michael Hudson
indentation screwup
556
        url = 'lp-internal:///' + db_branch.unique_name
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
557
        old_bzr_branch = Branch.open(url)
11040.1.12 by Aaron Bentley
Ensure commits work when username is unset.
558
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
559
        # required to generate the revision-id.
560
        with override_environ(BZR_EMAIL='me@example.com'):
561
            old_bzr_branch.create_checkout(
562
                self.factory.getUniqueString()).commit('')
9636.4.21 by Michael Hudson
more tests and fixes
563
        ok = brancher.checkOneBranch(db_branch)
564
        self.assertLogMessages([
9590.1.83 by Michael Hudson
indentation screwup
565
            '^WARNING Repository at lp-internal:///.*/.*/.*/.* has 1 '
566
            'revisions.'
9636.4.21 by Michael Hudson
more tests and fixes
567
            ])
568
        self.assertFalse(ok)
569
9590.1.83 by Michael Hudson
indentation screwup
570
    def test_checkOneBranch_old_has_null_tip(self):
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
571
        # checkOneBranch returns False when the bzr branch for the database
572
        # branch in old distroseries has tip revision of 'null:'.
9636.4.21 by Michael Hudson
more tests and fixes
573
        db_branch = self.makeOfficialPackageBranch()
9636.4.24 by Michael Hudson
tests for checkConsistentOfficialPackageBranch
574
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.21 by Michael Hudson
more tests and fixes
575
        brancher.makeOneNewBranch(db_branch)
9590.1.83 by Michael Hudson
indentation screwup
576
        url = 'lp-internal:///' + db_branch.unique_name
9636.4.42 by Michael Hudson
refactor checkOneBranch tests to have less mirrored/hosted duplication
577
        old_bzr_branch = Branch.open(url)
578
        old_bzr_branch.set_last_revision_info(0, 'null:')
9636.4.21 by Michael Hudson
more tests and fixes
579
        ok = brancher.checkOneBranch(db_branch)
580
        self.assertLogMessages([
9590.1.83 by Michael Hudson
indentation screwup
581
            '^WARNING Old branch at lp-internal:///.*/.*/.*/.* has null tip '
582
            'revision.'
9636.4.21 by Michael Hudson
more tests and fixes
583
            ])
584
        self.assertFalse(ok)
585
9636.4.37 by Michael Hudson
dear <deity> please let this be it
586
    def runBranchDistroScript(self, args):
587
        """Run the branch-distro.py script with the given arguments.
588
589
        ;param args: The arguments to pass to the branch-distro.py script.
590
        :return: A tuple (returncode, output).  stderr and stdout are both
591
            contained in the output.
592
        """
593
        script_path = os.path.join(config.root, 'scripts', 'branch-distro.py')
594
        process = Popen([script_path] + args, stdout=PIPE, stderr=STDOUT)
595
        output, error = process.communicate()
596
        return process.returncode, output
597
9636.4.33 by Michael Hudson
failing scripty tests
598
    def test_makeNewBranches_script(self):
9636.4.37 by Michael Hudson
dear <deity> please let this be it
599
        # Running the script with the arguments 'distro old-series new-series'
600
        # makes new branches in the new series.
9636.4.33 by Michael Hudson
failing scripty tests
601
        db_branch = self.makeOfficialPackageBranch()
602
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.37 by Michael Hudson
dear <deity> please let this be it
603
        returncode, output = self.runBranchDistroScript(
604
            ['-v', db_branch.distribution.name,
9636.4.33 by Michael Hudson
failing scripty tests
605
             brancher.old_distroseries.name, brancher.new_distroseries.name])
606
        self.assertEqual(0, returncode)
9636.4.37 by Michael Hudson
dear <deity> please let this be it
607
        self.assertEqual(
608
            'DEBUG   Processing ' + db_branch.unique_name + '\n', output)
9636.4.33 by Michael Hudson
failing scripty tests
609
        brancher.checkOneBranch(db_branch)
610
9636.4.35 by Michael Hudson
tweaks
611
    def test_checkNewBranches_script_success(self):
9636.4.37 by Michael Hudson
dear <deity> please let this be it
612
        # Running the script with the arguments '--check distro old-series
613
        # new-series' checks that the branches in the new series are as
614
        # expected.
9636.4.33 by Michael Hudson
failing scripty tests
615
        db_branch = self.makeOfficialPackageBranch()
616
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
617
        brancher.makeNewBranches()
9636.4.37 by Michael Hudson
dear <deity> please let this be it
618
        returncode, output = self.runBranchDistroScript(
619
            ['-v', '--check', db_branch.distribution.name,
9636.4.35 by Michael Hudson
tweaks
620
             brancher.old_distroseries.name, brancher.new_distroseries.name])
9636.4.33 by Michael Hudson
failing scripty tests
621
        self.assertEqual(0, returncode)
9636.4.37 by Michael Hudson
dear <deity> please let this be it
622
        self.assertEqual(
623
            'DEBUG   Checking ' + db_branch.unique_name + '\n', output)
9636.4.33 by Michael Hudson
failing scripty tests
624
        brancher.checkOneBranch(db_branch)
625
9636.4.35 by Michael Hudson
tweaks
626
    def test_checkNewBranches_script_failure(self):
9636.4.37 by Michael Hudson
dear <deity> please let this be it
627
        # Running the script with the arguments '--check distro old-series
628
        # new-series' checks that the branches in the new series are as
629
        # expected and logs warnings and exits with code 1 is things are not
630
        # as expected.
9636.4.33 by Michael Hudson
failing scripty tests
631
        db_branch = self.makeOfficialPackageBranch()
632
        brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
9636.4.37 by Michael Hudson
dear <deity> please let this be it
633
        returncode, output = self.runBranchDistroScript(
634
            ['-v', '--check', db_branch.distribution.name,
9636.4.35 by Michael Hudson
tweaks
635
             brancher.old_distroseries.name, brancher.new_distroseries.name])
9636.4.38 by Michael Hudson
no of course it wasn't
636
        sp_path = brancher.new_distroseries.getSourcePackage(
637
            db_branch.sourcepackagename).path
11300.2.37 by Stuart Bishop
Revert unnecessary test_branchdistro changes
638
        expected = '''\
639
        DEBUG   Checking %(branch_name)s
640
        WARNING No official branch found for %(sp_path)s
641
        ERROR   Check failed
642
        ''' % {'branch_name': db_branch.unique_name, 'sp_path': sp_path}
643
        self.assertEqual(
644
            textwrap.dedent(expected), output)
9636.4.33 by Michael Hudson
failing scripty tests
645
        self.assertEqual(1, returncode)
646
9636.4.17 by Michael Hudson
first test of $N for checkOneBranch
647
9636.4.2 by Michael Hudson
add some boilerplate
648
def test_suite():
649
    return unittest.TestLoader().loadTestsFromName(__name__)