示例#1
0
    def test_nonMainlineRevisionsDontMakeBugBranches(self):
        """Don't add BugBranches based on non-mainline revisions."""
        # Make the base revision.
        author = self.factory.getUniqueString()
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        with override_environ(BZR_EMAIL="*****@*****.**"):
            self.bzr_tree.commit(u"common parent", committer=author, rev_id="r1", allow_pointless=True)

            # Branch from the base revision.
            new_tree = self.make_branch_and_tree("bzr_branch_merged")
            new_tree.pull(self.bzr_branch)

            # Commit to both branches
            self.bzr_tree.commit(u"commit one", committer=author, rev_id="r2", allow_pointless=True)
            new_tree.commit(
                u"commit two",
                committer=author,
                rev_id="r1.1.1",
                allow_pointless=True,
                revprops={"bugs": "%s fixed" % self.getBugURL(self.bug1)},
            )

            # Merge and commit.
            self.bzr_tree.merge_from_branch(new_tree.branch)
            self.bzr_tree.commit(u"merge", committer=author, rev_id="r3", allow_pointless=True)

        self.syncBazaarBranchToDatabase(self.bzr_branch, self.db_branch)
        self.assertEqual(
            getUtility(IBugBranchSet).getBugBranch(self.bug1, self.db_branch), None, "Should not create a BugBranch."
        )
 def test_stderr(self):
     with override_environ(LP_DEBUG_SQL='1'):
         tracer = da.LaunchpadStatementTracer()
     with person_logged_in(self.person):
         with stderr() as file:
             tracer.connection_raw_execute(
                 self.connection, None, 'SELECT * FROM bar WHERE bing = 42',
                 ())
             timeline = get_request_timeline(get_current_browser_request())
             action = timeline.actions[-1]
             self.assertEqual('SELECT * FROM bar WHERE bing = 42',
                              action.detail)
             self.assertEqual('SQL-stub-database', action.category)
             self.assertIs(None, action.duration)
             # Now we change the detail to verify that the action is the
             # source of the final log.
             action.detail = 'SELECT * FROM surprise'
             tracer.connection_raw_execute_success(
                 self.connection, None, 'SELECT * FROM bar WHERE bing = 42',
                 ())
             self.assertIsNot(None, action.duration)
             self.assertEndsWith(
                 file.getvalue(),
                 '@SQL-stub-database SELECT * FROM surprise\n' + "-" * 70 +
                 "\n")
 def test_revision_added_job(self):
     """RevisionsAddedJobs are run by sendbranchmail."""
     self.useBzrBranches()
     branch, tree = self.createBranch()
     tree.bzrdir.root_transport.put_bytes('foo', 'baz')
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         tree.commit('Added foo.', rev_id='rev2')
     job = RevisionsAddedJob.create(
         branch, 'rev1', 'rev2', '*****@*****.**')
     transaction.commit()
     retcode, stdout, stderr = run_script(
         'cronscripts/process-job-source.py', ['IRevisionsAddedJobSource'])
     self.assertTextMatchesExpressionIgnoreWhitespace(
         'INFO    '
         'Creating lockfile: /var/lock/launchpad-process-job-source-'
         'IRevisionsAddedJobSource.lock\n'
         'INFO    Running synchronously.\n'
         'INFO    Running <REVISIONS_ADDED_MAIL branch job \(\d+\) '
         'for .*?> \(ID %d\) in status Waiting\n'
         'INFO    Ran 1 RevisionsAddedJob jobs.\n' % job.job.id,
         stderr)
     self.assertEqual('', stdout)
     self.assertEqual(0, retcode)
 def test_stderr(self):
     with override_environ(LP_DEBUG_SQL='1'):
         tracer = da.LaunchpadStatementTracer()
     with person_logged_in(self.person):
         with stderr() as file:
             tracer.connection_raw_execute(
                 self.connection, None, 'SELECT * FROM bar WHERE bing = 42',
                 ())
             timeline = get_request_timeline(get_current_browser_request())
             action = timeline.actions[-1]
             self.assertEqual('SELECT * FROM bar WHERE bing = 42',
                              action.detail)
             self.assertEqual('SQL-stub-database', action.category)
             self.assertIs(None, action.duration)
             # Now we change the detail to verify that the action is the
             # source of the final log.
             action.detail = 'SELECT * FROM surprise'
             tracer.connection_raw_execute_success(
                 self.connection, None, 'SELECT * FROM bar WHERE bing = 42',
                 ())
             self.assertIsNot(None, action.duration)
             self.assertEndsWith(
                 file.getvalue(),
                 '@SQL-stub-database SELECT * FROM surprise\n' + "-" * 70 +
                 "\n")
示例#5
0
 def commitRevision(
     self,
     message=None,
     committer=None,
     extra_parents=None,
     rev_id=None,
     timestamp=None,
     timezone=None,
     revprops=None,
 ):
     if message is None:
         message = self.LOG
     if committer is None:
         committer = self.factory.getUniqueString()
     if extra_parents is not None:
         self.bzr_tree.add_pending_merge(*extra_parents)
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL="*****@*****.**"):
         return self.bzr_tree.commit(
             message,
             committer=committer,
             rev_id=rev_id,
             timestamp=timestamp,
             timezone=timezone,
             allow_pointless=True,
             revprops=revprops,
         )
    def makeBranchWithMerge(self, base_rev_id, trunk_rev_id, branch_rev_id,
                            merge_rev_id):
        """Make a branch that has had another branch merged into it.

        Creates two Bazaar branches and two database branches associated with
        them. The first branch has three commits: the base revision, the
        'trunk' revision and the 'merged' revision.

        The second branch is branched from the base revision, has the 'branch'
        revision committed to it and is then merged into the first branch.

        Or, in other words::

               merge
                 |  \
                 |   \
                 |    \
               trunk   branch
                 |    /
                 |   /
                 |  /
                base

        :param base_rev_id: The revision ID of the initial commit.
        :param trunk_rev_id: The revision ID of the mainline commit.
        :param branch_rev_id: The revision ID of the revision committed to
            the branch that is merged into the mainline.
        :param merge_rev_id: The revision ID of the revision that merges the
            branch into the mainline branch.
        :return: (db_trunk, trunk_tree), (db_branch, branch_tree).
        """

        with lp_dbuser():
            # Make the base revision.
            db_branch = self.makeDatabaseBranch()
            db_branch, trunk_tree = self.create_branch_and_tree(
                db_branch=db_branch)
            # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
            # required to generate the revision-id.
            with override_environ(BZR_EMAIL='*****@*****.**'):
                trunk_tree.commit(u'base revision', rev_id=base_rev_id)

                # Branch from the base revision.
                new_db_branch = self.makeDatabaseBranch(
                    product=db_branch.product)
                new_db_branch, branch_tree = self.create_branch_and_tree(
                    db_branch=new_db_branch)
                branch_tree.pull(trunk_tree.branch)

                # Commit to both branches.
                trunk_tree.commit(u'trunk revision', rev_id=trunk_rev_id)
                branch_tree.commit(u'branch revision', rev_id=branch_rev_id)

                # Merge branch into trunk.
                trunk_tree.merge_from_branch(branch_tree.branch)
                trunk_tree.commit(u'merge revision', rev_id=merge_rev_id)

        return (db_branch, trunk_tree), (new_db_branch, branch_tree)
 def execute(self, statement=None, params=None, **environ):
     with override_environ(**environ):
         tracer = da.LaunchpadStatementTracer()
     if statement is None:
         statement = 'SELECT * FROM bar WHERE bing = 42'
     tracer.connection_raw_execute(self.connection, self.cursor, statement,
                                   params)
     tracer.connection_raw_execute_success(self.connection, self.cursor,
                                           statement, params)
 def execute(self, statement=None, params=None, **environ):
     with override_environ(**environ):
         tracer = da.LaunchpadStatementTracer()
     if statement is None:
         statement = 'SELECT * FROM bar WHERE bing = 42'
     tracer.connection_raw_execute(self.connection, self.cursor, statement,
                                   params)
     tracer.connection_raw_execute_success(self.connection, self.cursor,
                                           statement, params)
 def make_branch_with_commits_and_scan_job(self, db_branch):
     """Create a branch from a db_branch, make commits and a scan job."""
     target, target_tree = self.create_branch_and_tree(db_branch=db_branch)
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         target_tree.commit('First commit', rev_id='rev1')
         target_tree.commit('Second commit', rev_id='rev2')
         target_tree.commit('Third commit', rev_id='rev3')
     BranchScanJob.create(db_branch)
     transaction.commit()
示例#10
0
    def makeBranchWithMerge(self, base_rev_id, trunk_rev_id, branch_rev_id, merge_rev_id):
        """Make a branch that has had another branch merged into it.

        Creates two Bazaar branches and two database branches associated with
        them. The first branch has three commits: the base revision, the
        'trunk' revision and the 'merged' revision.

        The second branch is branched from the base revision, has the 'branch'
        revision committed to it and is then merged into the first branch.

        Or, in other words::

               merge
                 |  \
                 |   \
                 |    \
               trunk   branch
                 |    /
                 |   /
                 |  /
                base

        :param base_rev_id: The revision ID of the initial commit.
        :param trunk_rev_id: The revision ID of the mainline commit.
        :param branch_rev_id: The revision ID of the revision committed to
            the branch that is merged into the mainline.
        :param merge_rev_id: The revision ID of the revision that merges the
            branch into the mainline branch.
        :return: (db_trunk, trunk_tree), (db_branch, branch_tree).
        """

        with lp_dbuser():
            # Make the base revision.
            db_branch = self.makeDatabaseBranch()
            db_branch, trunk_tree = self.create_branch_and_tree(db_branch=db_branch)
            # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
            # required to generate the revision-id.
            with override_environ(BZR_EMAIL="*****@*****.**"):
                trunk_tree.commit(u"base revision", rev_id=base_rev_id)

                # Branch from the base revision.
                new_db_branch = self.makeDatabaseBranch(product=db_branch.product)
                new_db_branch, branch_tree = self.create_branch_and_tree(db_branch=new_db_branch)
                branch_tree.pull(trunk_tree.branch)

                # Commit to both branches.
                trunk_tree.commit(u"trunk revision", rev_id=trunk_rev_id)
                branch_tree.commit(u"branch revision", rev_id=branch_rev_id)

                # Merge branch into trunk.
                trunk_tree.merge_from_branch(branch_tree.branch)
                trunk_tree.commit(u"merge revision", rev_id=merge_rev_id)

        return (db_branch, trunk_tree), (new_db_branch, branch_tree)
示例#11
0
 def createProposalWithEmptyBranches(self):
     target_branch, tree = self.create_branch_and_tree()
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         tree.commit('test')
     source_branch = self.factory.makeProductBranch(
         product=target_branch.product)
     self.createBzrBranch(source_branch, tree.branch)
     return self.factory.makeBranchMergeProposal(
         source_branch=source_branch, target_branch=target_branch)
 def make_branch_with_commits_and_scan_job(self, db_branch):
     """Create a branch from a db_branch, make commits and a scan job."""
     target, target_tree = self.create_branch_and_tree(db_branch=db_branch)
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         target_tree.commit('First commit', rev_id='rev1')
         target_tree.commit('Second commit', rev_id='rev2')
         target_tree.commit('Third commit', rev_id='rev3')
     BranchScanJob.create(db_branch)
     transaction.commit()
示例#13
0
 def setUp(self, spew=False, umask=None):
     # setUp() watches the logfile to determine when the daemon has fully
     # started. If it sees an old logfile, then it will find the
     # readyservice.LOG_MAGIC string and return immediately, provoking
     # hard-to-diagnose race conditions. Delete the logfile to make sure
     # this does not happen.
     self.removeLog()
     with override_environ(LP_DEBUG_SQL=None):
         TacTestFixture.setUp(self,
                              python_path=sys.executable,
                              twistd_script=twistd_script)
示例#14
0
 def test_python_fixture_reload_in_html(self):
     # The reload is specifically when we load HTML pages only.
     test_yuixhr_fixture._fixtures_['extra_scribble'] = 42
     with override_environ(INTERACTIVE_TESTS='1'):
         view = create_traversed_view(
             path_info='/+yuitest/lp/testing/tests/'
             'test_yuixhr_fixture',
             form=dict(reload='1'))
         view.initialize()
         # After a render of the html view, the module is reloaded.
         view.renderHTML()
         self.assertEquals(
             None, test_yuixhr_fixture._fixtures_.get('extra_scribble'))
示例#15
0
 def test_python_fixture_reload_in_html(self):
     # The reload is specifically when we load HTML pages only.
     test_yuixhr_fixture._fixtures_['extra_scribble'] = 42
     with override_environ(INTERACTIVE_TESTS='1'):
         view = create_traversed_view(
             path_info='/+yuitest/lp/testing/tests/'
             'test_yuixhr_fixture', form=dict(reload='1'))
         view.initialize()
         # After a render of the html view, the module is reloaded.
         view.renderHTML()
         self.assertEquals(
             None,
             test_yuixhr_fixture._fixtures_.get('extra_scribble'))
 def createBranch(self):
     branch, tree = self.create_branch_and_tree()
     branch.subscribe(branch.registrant,
                      BranchSubscriptionNotificationLevel.FULL,
                      BranchSubscriptionDiffSize.WHOLEDIFF,
                      CodeReviewNotificationLevel.FULL, branch.registrant)
     transport = tree.bzrdir.root_transport
     transport.put_bytes('foo', 'bar')
     tree.add('foo')
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         tree.commit('Added foo.', rev_id='rev1')
     return branch, tree
示例#17
0
    def test_debug_sql(self):
        """TacTestSetup works even under LP_DEBUG_SQL=1."""
        tempdir = self.useFixture(TempDir()).path
        fixture = SimpleTac("okay", tempdir)

        # Fire up the fixture, capturing warnings.
        with override_environ(LP_DEBUG_SQL="1"):
            with warnings.catch_warnings(record=True) as warnings_log:
                with fixture:
                    self.assertThat(fixture, IsRunning())
                self.assertThat(fixture, Not(IsRunning()))

        # No warnings are emitted.
        self.assertEqual([], warnings_log)
示例#18
0
    def test_switch_branches(self):
        # switch_branches moves a branch to the new location and places a
        # branch (with no revisions) stacked on the new branch in the old
        # location.

        chroot_server = ChrootServer(self.get_transport())
        chroot_server.start_server()
        self.addCleanup(chroot_server.stop_server)
        scheme = chroot_server.get_url().rstrip('/:')

        old_branch = FakeBranch(1)
        self.get_transport(old_branch.unique_name).create_prefix()
        tree = self.make_branch_and_tree(old_branch.unique_name)
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        with override_environ(BZR_EMAIL='*****@*****.**'):
            tree.commit(message='.')

        new_branch = FakeBranch(2)

        switch_branches('.', scheme, old_branch, new_branch)

        # Post conditions:
        # 1. unstacked branch in new_branch's location
        # 2. stacked branch with no revisions in repo at old_branch
        # 3. last_revision() the same for two branches

        old_location_bzrdir = BzrDir.open(
            str(URI(scheme=scheme, host='',
                    path='/' + old_branch.unique_name)))
        new_location_bzrdir = BzrDir.open(
            str(URI(scheme=scheme, host='',
                    path='/' + new_branch.unique_name)))

        old_location_branch = old_location_bzrdir.open_branch()
        new_location_branch = new_location_bzrdir.open_branch()

        # 1. unstacked branch in new_branch's location
        self.assertRaises(NotStacked, new_location_branch.get_stacked_on_url)

        # 2. stacked branch with no revisions in repo at old_branch
        self.assertEqual('/' + new_branch.unique_name,
                         old_location_branch.get_stacked_on_url())
        self.assertEqual(
            [],
            old_location_bzrdir.open_repository().all_revision_ids())

        # 3. last_revision() the same for two branches
        self.assertEqual(old_location_branch.last_revision(),
                         new_location_branch.last_revision())
示例#19
0
 def test_MergeProposalCreateJob_with_sourcepackage_branch(self):
     """Jobs for merge proposals with sourcepackage branches work."""
     self.useBzrBranches(direct_database=True)
     bmp = self.factory.makeBranchMergeProposal(
         target_branch=self.factory.makePackageBranch())
     tree = self.create_branch_and_tree(db_branch=bmp.target_branch)[1]
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         tree.commit('Initial commit')
     self.createBzrBranch(bmp.source_branch, tree.branch)
     self.factory.makeRevisionsForBranch(bmp.source_branch, count=1)
     job = MergeProposalNeedsReviewEmailJob.create(bmp)
     with dbuser("merge-proposal-jobs"):
         job.run()
 def test_checkOneBranch_old_has_revisions(self):
     # checkOneBranch returns False when the bzr branch for the database
     # branch in old distroseries has a repository that contains revisions.
     db_branch = self.makeOfficialPackageBranch()
     brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
     brancher.makeOneNewBranch(db_branch)
     url = "lp-internal:///" + db_branch.unique_name
     old_bzr_branch = Branch.open(url)
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL="*****@*****.**"):
         old_bzr_branch.create_checkout(self.factory.getUniqueString()).commit("")
     ok = brancher.checkOneBranch(db_branch)
     self.assertLogMessages(["^WARNING Repository at lp-internal:///.*/.*/.*/.* has 1 " "revisions."])
     self.assertFalse(ok)
 def createBranch(self):
     branch, tree = self.create_branch_and_tree()
     branch.subscribe(
         branch.registrant,
         BranchSubscriptionNotificationLevel.FULL,
         BranchSubscriptionDiffSize.WHOLEDIFF,
         CodeReviewNotificationLevel.FULL,
         branch.registrant)
     transport = tree.bzrdir.root_transport
     transport.put_bytes('foo', 'bar')
     tree.add('foo')
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         tree.commit('Added foo.', rev_id='rev1')
     return branch, tree
示例#22
0
 def test_got_new_revision_subscribed(self):
     """got_new_revision is subscribed to NewRevision."""
     self.useBzrBranches(direct_database=True)
     db_branch, tree = self.create_branch_and_tree()
     bug = self.factory.makeBug()
     switch_dbuser("branchscanner")
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL="*****@*****.**"):
         revision_id = tree.commit("fix revision", revprops={"bugs": "https://launchpad.net/bugs/%d fixed" % bug.id})
     bzr_revision = tree.branch.repository.get_revision(revision_id)
     revision_set = getUtility(IRevisionSet)
     revision_set.newFromBazaarRevisions([bzr_revision])
     notify(events.NewMainlineRevisions(db_branch, tree.branch, [bzr_revision]))
     bug_branch = getUtility(IBugBranchSet).getBugBranch(bug, db_branch)
     self.assertIsNot(None, bug_branch)
示例#23
0
 def commitRevision(self, message=None, committer=None,
                    extra_parents=None, rev_id=None,
                    timestamp=None, timezone=None, revprops=None):
     if message is None:
         message = self.LOG
     if committer is None:
         committer = self.factory.getUniqueString()
     if extra_parents is not None:
         self.bzr_tree.add_pending_merge(*extra_parents)
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         return self.bzr_tree.commit(
             message, committer=committer, rev_id=rev_id,
             timestamp=timestamp, timezone=timezone, allow_pointless=True,
             revprops=revprops)
示例#24
0
 def test_python_fixture_resets_fixtures(self):
     # When we reload, we also clear out _fixtures_.  This means
     # that if you rename or delete something, it won't be hanging
     # around confusing you into thinking everything is fine after
     # the reload.
     test_yuixhr_fixture._fixtures_['extra_scribble'] = 42
     with override_environ(INTERACTIVE_TESTS='1'):
         view = create_traversed_view(
             path_info='/+yuitest/lp/testing/tests/'
             'test_yuixhr_fixture',
             form=dict(reload='1'))
         view.initialize()
         # After a render of the html view, the module is reloaded.
         view.render()
         self.assertEquals(
             None, test_yuixhr_fixture._fixtures_.get('extra_scribble'))
示例#25
0
 def test_python_fixture_resets_fixtures(self):
     # When we reload, we also clear out _fixtures_.  This means
     # that if you rename or delete something, it won't be hanging
     # around confusing you into thinking everything is fine after
     # the reload.
     test_yuixhr_fixture._fixtures_['extra_scribble'] = 42
     with override_environ(INTERACTIVE_TESTS='1'):
         view = create_traversed_view(
             path_info='/+yuitest/lp/testing/tests/'
             'test_yuixhr_fixture', form=dict(reload='1'))
         view.initialize()
         # After a render of the html view, the module is reloaded.
         view.render()
         self.assertEquals(
             None,
             test_yuixhr_fixture._fixtures_.get('extra_scribble'))
    def makeOfficialPackageBranch(self, distroseries=None, make_revisions=True):
        """Make an official package branch with an underlying bzr branch."""
        db_branch = self.factory.makePackageBranch(distroseries=distroseries)
        db_branch.sourcepackage.setBranch(RELEASE, db_branch, db_branch.owner)
        if make_revisions:
            self.factory.makeRevisionsForBranch(db_branch, count=1)

        transaction.commit()

        _, tree = self.create_branch_and_tree(tree_location=self.factory.getUniqueString(), db_branch=db_branch)
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        if make_revisions:
            with override_environ(BZR_EMAIL="*****@*****.**"):
                tree.commit("")

        return db_branch
 def _setup_series_branch(self, pot_path):
     self.useBzrBranches()
     pot_content = self.factory.getUniqueString()
     branch, tree = self.create_branch_and_tree()
     tree.bzrdir.root_transport.put_bytes(pot_path, pot_content)
     tree.add(pot_path)
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         revision_id = tree.commit("first commit")
     branch.last_scanned_id = revision_id
     branch.last_mirrored_id = revision_id
     series = self.factory.makeProductSeries()
     series.branch = branch
     series.translations_autoimport_mode = (
         TranslationsBranchImportMode.IMPORT_TEMPLATES)
     return branch
 def _setup_series_branch(self, pot_path):
     self.useBzrBranches()
     pot_content = self.factory.getUniqueString()
     branch, tree = self.create_branch_and_tree()
     tree.bzrdir.root_transport.put_bytes(pot_path, pot_content)
     tree.add(pot_path)
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         revision_id = tree.commit("first commit")
     branch.last_scanned_id = revision_id
     branch.last_mirrored_id = revision_id
     series = self.factory.makeProductSeries()
     series.branch = branch
     series.translations_autoimport_mode = (
         TranslationsBranchImportMode.IMPORT_TEMPLATES)
     return branch
    def test_auto_merge_proposals_not_merged_with_updated_source(self):
        # If there is a merge proposal where the tip of the source is not in
        # the ancestry of the target it is not marked as merged.

        proposal, db_trunk, db_branch, branch_tree = (
            self._createBranchesAndProposal())

        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        with override_environ(BZR_EMAIL='*****@*****.**'):
            branch_tree.commit(u'another revision', rev_id='another-rev')
        current_proposal_status = proposal.queue_status
        self.assertNotEqual(current_proposal_status,
                            BranchMergeProposalStatus.MERGED)

        self._scanTheBranches(db_trunk, db_branch)

        # The proposal should stay in the same state.
        self.assertEqual(current_proposal_status, proposal.queue_status)
    def commit(self, commit_message, txn=None):
        """Commit to branch.

        :param commit_message: Message for branch's commit log.
        :param txn: Transaction to commit.  Can be helpful in avoiding
            long idle times in database transactions.  May be committed
            more than once.
        """
        assert self.is_open, "Committing closed DirectBranchCommit."
        assert self.is_locked, "Not locked at commit time."

        try:
            self._checkForRace()

            if txn:
                txn.commit()

            rev_id = self.revision_tree.get_revision_id()
            if rev_id == NULL_REVISION:
                if list(self.transform_preview.iter_changes()) == []:
                    return
            committer_id = self.getBzrCommitterID()
            # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
            # required to generate the revision-id.
            with override_environ(BZR_EMAIL=committer_id):
                new_rev_id = self.transform_preview.commit(
                    self.bzrbranch, commit_message, self.merge_parents, committer=committer_id
                )
            IMasterObject(self.db_branch).branchChanged(
                get_stacked_on_url(self.bzrbranch),
                new_rev_id,
                self.db_branch.control_format,
                self.db_branch.branch_format,
                self.db_branch.repository_format,
            )

            if txn:
                txn.commit()

        finally:
            self.unlock()
            self.is_open = False
        return new_rev_id
示例#31
0
 def test_checkOneBranch_old_has_revisions(self):
     # checkOneBranch returns False when the bzr branch for the database
     # branch in old distroseries has a repository that contains revisions.
     db_branch = self.makeOfficialPackageBranch()
     brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
     brancher.makeOneNewBranch(db_branch)
     url = 'lp-internal:///' + db_branch.unique_name
     old_bzr_branch = Branch.open(url)
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         old_bzr_branch.create_checkout(
             self.factory.getUniqueString()).commit('')
     ok = brancher.checkOneBranch(db_branch)
     self.assertLogMessages([
         '^WARNING Repository at lp-internal:///.*/.*/.*/.* has 1 '
         'revisions.'
     ])
     self.assertFalse(ok)
    def test_switch_branches(self):
        # switch_branches moves a branch to the new location and places a
        # branch (with no revisions) stacked on the new branch in the old
        # location.

        chroot_server = ChrootServer(self.get_transport())
        chroot_server.start_server()
        self.addCleanup(chroot_server.stop_server)
        scheme = chroot_server.get_url().rstrip("/:")

        old_branch = FakeBranch(1)
        self.get_transport(old_branch.unique_name).create_prefix()
        tree = self.make_branch_and_tree(old_branch.unique_name)
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        with override_environ(BZR_EMAIL="*****@*****.**"):
            tree.commit(message=".")

        new_branch = FakeBranch(2)

        switch_branches(".", scheme, old_branch, new_branch)

        # Post conditions:
        # 1. unstacked branch in new_branch's location
        # 2. stacked branch with no revisions in repo at old_branch
        # 3. last_revision() the same for two branches

        old_location_bzrdir = BzrDir.open(str(URI(scheme=scheme, host="", path="/" + old_branch.unique_name)))
        new_location_bzrdir = BzrDir.open(str(URI(scheme=scheme, host="", path="/" + new_branch.unique_name)))

        old_location_branch = old_location_bzrdir.open_branch()
        new_location_branch = new_location_bzrdir.open_branch()

        # 1. unstacked branch in new_branch's location
        self.assertRaises(NotStacked, new_location_branch.get_stacked_on_url)

        # 2. stacked branch with no revisions in repo at old_branch
        self.assertEqual("/" + new_branch.unique_name, old_location_branch.get_stacked_on_url())
        self.assertEqual([], old_location_bzrdir.open_repository().all_revision_ids())

        # 3. last_revision() the same for two branches
        self.assertEqual(old_location_branch.last_revision(), new_location_branch.last_revision())
示例#33
0
 def test_python_fixture_can_reload(self):
     # Now we will turn reloading fully on, with the environmental
     # variable and the query string..
     test_yuixhr_fixture._fixtures_['baseline'].scribble = 'hello'
     with override_environ(INTERACTIVE_TESTS='1'):
         view = create_traversed_view(
             path_info='/+yuitest/lp/testing/tests/'
             'test_yuixhr_fixture',
             form=dict(reload='1'))
         # reloading only happens at render time, so the scribble is
         # still there for now.
         view.initialize()
         self.assertEquals(
             'hello', test_yuixhr_fixture._fixtures_['baseline'].scribble)
         # After a render of the html view, the module is reloaded.
         view.render()
         self.assertEquals(
             None,
             getattr(test_yuixhr_fixture._fixtures_['baseline'], 'scribble',
                     None))
    def test_auto_merge_proposals_not_merged_with_updated_source(self):
        # If there is a merge proposal where the tip of the source is not in
        # the ancestry of the target it is not marked as merged.

        proposal, db_trunk, db_branch, branch_tree = (
            self._createBranchesAndProposal())

        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        with override_environ(BZR_EMAIL='*****@*****.**'):
            branch_tree.commit(u'another revision', rev_id='another-rev')
        current_proposal_status = proposal.queue_status
        self.assertNotEqual(
            current_proposal_status,
            BranchMergeProposalStatus.MERGED)

        self._scanTheBranches(db_trunk, db_branch)

        # The proposal should stay in the same state.
        self.assertEqual(current_proposal_status, proposal.queue_status)
示例#35
0
    def makeOfficialPackageBranch(self,
                                  distroseries=None,
                                  make_revisions=True):
        """Make an official package branch with an underlying bzr branch."""
        db_branch = self.factory.makePackageBranch(distroseries=distroseries)
        db_branch.sourcepackage.setBranch(RELEASE, db_branch, db_branch.owner)
        if make_revisions:
            self.factory.makeRevisionsForBranch(db_branch, count=1)

        transaction.commit()

        _, tree = self.create_branch_and_tree(
            tree_location=self.factory.getUniqueString(), db_branch=db_branch)
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        if make_revisions:
            with override_environ(BZR_EMAIL='*****@*****.**'):
                tree.commit('')

        return db_branch
示例#36
0
 def test_python_fixture_can_reload(self):
     # Now we will turn reloading fully on, with the environmental
     # variable and the query string..
     test_yuixhr_fixture._fixtures_['baseline'].scribble = 'hello'
     with override_environ(INTERACTIVE_TESTS='1'):
         view = create_traversed_view(
             path_info='/+yuitest/lp/testing/tests/'
             'test_yuixhr_fixture', form=dict(reload='1'))
         # reloading only happens at render time, so the scribble is
         # still there for now.
         view.initialize()
         self.assertEquals(
             'hello', test_yuixhr_fixture._fixtures_['baseline'].scribble)
         # After a render of the html view, the module is reloaded.
         view.render()
         self.assertEquals(
             None,
             getattr(test_yuixhr_fixture._fixtures_['baseline'],
                     'scribble',
                     None))
    def commit(self, commit_message, txn=None):
        """Commit to branch.

        :param commit_message: Message for branch's commit log.
        :param txn: Transaction to commit.  Can be helpful in avoiding
            long idle times in database transactions.  May be committed
            more than once.
        """
        assert self.is_open, "Committing closed DirectBranchCommit."
        assert self.is_locked, "Not locked at commit time."

        try:
            self._checkForRace()

            if txn:
                txn.commit()

            rev_id = self.revision_tree.get_revision_id()
            if rev_id == NULL_REVISION:
                if list(self.transform_preview.iter_changes()) == []:
                    return
            committer_id = self.getBzrCommitterID()
            # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
            # required to generate the revision-id.
            with override_environ(BZR_EMAIL=committer_id):
                new_rev_id = self.transform_preview.commit(
                    self.bzrbranch, commit_message, self.merge_parents,
                    committer=committer_id)
            IMasterObject(self.db_branch).branchChanged(
                get_stacked_on_url(self.bzrbranch), new_rev_id,
                self.db_branch.control_format, self.db_branch.branch_format,
                self.db_branch.repository_format)

            if txn:
                txn.commit()

        finally:
            self.unlock()
            self.is_open = False
        return new_rev_id
示例#38
0
    def test_nonMainlineRevisionsDontMakeBugBranches(self):
        """Don't add BugBranches based on non-mainline revisions."""
        # Make the base revision.
        author = self.factory.getUniqueString()
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        with override_environ(BZR_EMAIL='*****@*****.**'):
            self.bzr_tree.commit(u'common parent',
                                 committer=author,
                                 rev_id='r1',
                                 allow_pointless=True)

            # Branch from the base revision.
            new_tree = self.make_branch_and_tree('bzr_branch_merged')
            new_tree.pull(self.bzr_branch)

            # Commit to both branches
            self.bzr_tree.commit(u'commit one',
                                 committer=author,
                                 rev_id='r2',
                                 allow_pointless=True)
            new_tree.commit(
                u'commit two',
                committer=author,
                rev_id='r1.1.1',
                allow_pointless=True,
                revprops={'bugs': '%s fixed' % self.getBugURL(self.bug1)})

            # Merge and commit.
            self.bzr_tree.merge_from_branch(new_tree.branch)
            self.bzr_tree.commit(u'merge',
                                 committer=author,
                                 rev_id='r3',
                                 allow_pointless=True)

        self.syncBazaarBranchToDatabase(self.bzr_branch, self.db_branch)
        self.assertEqual(
            getUtility(IBugBranchSet).getBugBranch(self.bug1, self.db_branch),
            None, "Should not create a BugBranch.")
示例#39
0
 def test_got_new_revision_subscribed(self):
     """got_new_revision is subscribed to NewRevision."""
     self.useBzrBranches(direct_database=True)
     db_branch, tree = self.create_branch_and_tree()
     bug = self.factory.makeBug()
     switch_dbuser("branchscanner")
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         revision_id = tree.commit(
             'fix revision',
             revprops={
                 'bugs': 'https://launchpad.net/bugs/%d fixed' % bug.id
             })
     bzr_revision = tree.branch.repository.get_revision(revision_id)
     revision_set = getUtility(IRevisionSet)
     revision_set.newFromBazaarRevisions([bzr_revision])
     notify(
         events.NewMainlineRevisions(db_branch, tree.branch,
                                     [bzr_revision]))
     bug_branch = getUtility(IBugBranchSet).getBugBranch(bug, db_branch)
     self.assertIsNot(None, bug_branch)
 def test_revision_added_job(self):
     """RevisionsAddedJobs are run by sendbranchmail."""
     self.useBzrBranches()
     branch, tree = self.createBranch()
     tree.bzrdir.root_transport.put_bytes('foo', 'baz')
     # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
     # required to generate the revision-id.
     with override_environ(BZR_EMAIL='*****@*****.**'):
         tree.commit('Added foo.', rev_id='rev2')
     job = RevisionsAddedJob.create(branch, 'rev1', 'rev2',
                                    '*****@*****.**')
     transaction.commit()
     retcode, stdout, stderr = run_script(
         'cronscripts/process-job-source.py', ['IRevisionsAddedJobSource'])
     self.assertTextMatchesExpressionIgnoreWhitespace(
         'INFO    '
         'Creating lockfile: /var/lock/launchpad-process-job-source-'
         'IRevisionsAddedJobSource.lock\n'
         'INFO    Running synchronously.\n'
         'INFO    Running <REVISIONS_ADDED_MAIL branch job \(\d+\) '
         'for .*?> \(ID %d\) in status Waiting\n'
         'INFO    Ran 1 RevisionsAddedJob jobs.\n' % job.job.id, stderr)
     self.assertEqual('', stdout)
     self.assertEqual(0, retcode)