def _watch(self, identifier='123'):
     with lp_dbuser():
         # This actually creates a notification all by itself.  However,
         # it won't be sent out for another five minutes.  Therefore,
         # we send out separate change notifications.
         return self.bug.addWatch(
             self.tracker, identifier, self.product_owner)
 def test_changing_on_different_bugtasks_is_not_undoing(self):
     with lp_dbuser():
         product2 = self.factory.makeProduct(owner=self.product_owner)
         self.bug.addTask(self.product_owner, product2)
     self.change(self.old, self.new, index=0)
     self.change(self.new, self.old, index=1)
     message, body = self.get_messages().next()
     self.assertThat(body, Contains(self.unexpected_text))
 def _attachment(self):
     with lp_dbuser():
         # This actually creates a notification all by itself, via an
         # event subscriber.  However, it won't be sent out for
         # another five minutes.  Therefore, we send out separate
         # change notifications.
         return self.bug.addAttachment(
             self.person, 'content', 'a comment', 'stuff.txt')
    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 _makeProductSeries(self, mode=None):
     """Switch to the Launchpad db user to create and configure a
     product series that is linked to the branch.
     """
     with lp_dbuser():
         self.product_series = self.factory.makeProductSeries()
         self.product_series.branch = self.db_branch
         if mode is not None:
             self.product_series.translations_autoimport_mode = mode
Example #6
0
 def _makeProductSeries(self, mode=None):
     """Switch to the Launchpad db user to create and configure a
     product series that is linked to the branch.
     """
     with lp_dbuser():
         self.product_series = self.factory.makeProductSeries()
         self.product_series.branch = self.db_branch
         if mode is not None:
             self.product_series.translations_autoimport_mode = mode
Example #7
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)
 def test_appendExpandedFooter(self):
     """Check that expanded notification footers are sensible."""
     mailer, subscriber = self.makeMailer(as_reply=True)
     with lp_dbuser(), person_logged_in(subscriber):
         subscriber.expanded_notification_footers = True
     ctrl = mailer.generateEmail(subscriber.preferredemail.email,
                                 subscriber)
     source_branch = mailer.merge_proposal.source_branch
     rationale = mailer._recipients.getReason('*****@*****.**')[1]
     expected_footer = [
         '-- ',
         canonical_url(mailer.merge_proposal),
         'You are subscribed to branch %s.' % source_branch.bzr_identity,
         '',
         'Launchpad-Message-Rationale: %s' % rationale,
         'Launchpad-Message-For: %s' % subscriber.name,
         'Launchpad-Notification-Type: code-review',
         'Launchpad-Branch: %s' % source_branch.unique_name,
         'Launchpad-Project: %s' % source_branch.product.name,
     ]
     self.assertEqual(expected_footer,
                      ctrl.body.splitlines()[-len(expected_footer):])
 def remove(self, item):
     with lp_dbuser():
         self.bug.addChange(
             CveUnlinkedFromBug(
                 self.ten_minutes_ago, self.person, item))
 def add(self, item):
     with lp_dbuser():
         self.bug.addChange(
             CveLinkedToBug(
                 self.ten_minutes_ago, self.person, item))
 def _cve(self, sequence):
     with lp_dbuser():
         return self.factory.makeCVE(sequence)
 def _branch(self):
     with lp_dbuser():
         return self.factory.makeBranch()
 def remove(self, item):
     with lp_dbuser():
         self.bug.addChange(
             BugWatchRemoved(
                 self.ten_minutes_ago, self.product_owner, item))
Example #14
0
 def makePackageBranch(self):
     with lp_dbuser():
         branch = self.factory.makePackageBranch()
         branch.sourcepackage.setBranch(PackagePublishingPocket.RELEASE, branch, branch.owner)
     return branch
 def tracker(self):
     with lp_dbuser():
         return self.factory.makeBugTracker()
 def _bug(self):
     with lp_dbuser():
         return self.factory.makeBug()
Example #17
0
 def test_lp_dpuser(self):
     switch_dbuser(config.uploader.dbuser)
     self.assertEqual(config.uploader.dbuser, self.get_current_dbuser())
     with lp_dbuser():
         self.assertEqual('launchpad', self.get_current_dbuser())
     self.assertEqual(config.uploader.dbuser, self.get_current_dbuser())
    def testDeactivatingTokens(self):
        """Test that token deactivation happens properly."""
        data = self.setupSubscriptionsAndTokens()
        (team1, team2, parent_team, lonely_person, promiscuous_person,
            all_persons, persons1, persons2, tokens) = data
        team1_person = persons1[0]

        # Initially, nothing is eligible for deactivation.
        script = self.getScript()
        script.deactivateInvalidTokens()
        for person in tokens:
            self.assertNotDeactivated(tokens[person])

        # Now remove someone from team1, he will lose his token but
        # everyone else keeps theirs.
        with lp_dbuser():
            team1_person.leave(team1)
        # Clear out emails generated when leaving a team.
        pop_notifications()

        script.deactivateInvalidTokens(send_email=True)
        self.assertDeactivated(tokens[team1_person])
        del tokens[team1_person]
        for person in tokens:
            self.assertNotDeactivated(tokens[person])

        # Ensure that a cancellation email was sent.
        num_emails = len(stub.test_emails)
        self.assertEqual(
            num_emails, 1, "Expected 1 email, got %s" % num_emails)

        # Promiscuous_person now leaves team1, but does not lose his
        # token because he's also in team2. No other tokens are
        # affected.
        with lp_dbuser():
            promiscuous_person.leave(team1)
        # Clear out emails generated when leaving a team.
        pop_notifications()
        script.deactivateInvalidTokens(send_email=True)
        self.assertNotDeactivated(tokens[promiscuous_person])
        for person in tokens:
            self.assertNotDeactivated(tokens[person])

        # Ensure that a cancellation email was not sent.
        num_emails = len(stub.test_emails)
        self.assertEqual(
            num_emails, 0, "Expected no emails, got %s" % num_emails)

        # Team 2 now leaves parent_team, and all its members lose their
        # tokens.
        with lp_dbuser():
            name12 = getUtility(IPersonSet).getByName("name12")
            parent_team.setMembershipData(
                team2, TeamMembershipStatus.APPROVED, name12)
            parent_team.setMembershipData(
                team2, TeamMembershipStatus.DEACTIVATED, name12)
            self.assertFalse(team2.inTeam(parent_team))
        script.deactivateInvalidTokens()
        for person in persons2:
            self.assertDeactivated(tokens[person])

        # promiscuous_person also loses the token because he's not in
        # either team now.
        self.assertDeactivated(tokens[promiscuous_person])

        # lonely_person still has his token, he's not in any teams.
        self.assertNotDeactivated(tokens[lonely_person])
Example #19
0
 def test_lp_dpuser(self):
     switch_dbuser(config.uploader.dbuser)
     self.assertEqual(config.uploader.dbuser, self.get_current_dbuser())
     with lp_dbuser():
         self.assertEqual('launchpad', self.get_current_dbuser())
     self.assertEqual(config.uploader.dbuser, self.get_current_dbuser())
Example #20
0
    def testDeactivatingTokens(self):
        """Test that token deactivation happens properly."""
        data = self.setupSubscriptionsAndTokens()
        (team1, team2, parent_team, lonely_person, promiscuous_person,
            all_persons, persons1, persons2, tokens) = data
        team1_person = persons1[0]

        # Named tokens should be ignored for deactivation.
        self.ppa.newNamedAuthToken("tokenname1")
        named_token = self.ppa.newNamedAuthToken("tokenname2")
        named_token.deactivate()

        # Initially, nothing is eligible for deactivation.
        script = self.getScript()
        script.deactivateInvalidTokens()
        for person in tokens:
            self.assertNotDeactivated(tokens[person])

        # Now remove someone from team1. They will lose their token but
        # everyone else keeps theirs.
        with lp_dbuser():
            team1_person.leave(team1)
        # Clear out emails generated when leaving a team.
        pop_notifications()

        script.deactivateInvalidTokens(send_email=True)
        self.assertDeactivated(tokens[team1_person])
        del tokens[team1_person]
        for person in tokens:
            self.assertNotDeactivated(tokens[person])

        # Ensure that a cancellation email was sent.
        self.assertEmailQueueLength(1)

        # Promiscuous_person now leaves team1, but does not lose their
        # token because they're also in team2. No other tokens are
        # affected.
        with lp_dbuser():
            promiscuous_person.leave(team1)
        # Clear out emails generated when leaving a team.
        pop_notifications()
        script.deactivateInvalidTokens(send_email=True)
        self.assertNotDeactivated(tokens[promiscuous_person])
        for person in tokens:
            self.assertNotDeactivated(tokens[person])

        # Ensure that a cancellation email was not sent.
        self.assertEmailQueueLength(0)

        # Team 2 now leaves parent_team, and all its members lose their
        # tokens.
        with lp_dbuser():
            name12 = getUtility(IPersonSet).getByName("name12")
            parent_team.setMembershipData(
                team2, TeamMembershipStatus.APPROVED, name12)
            parent_team.setMembershipData(
                team2, TeamMembershipStatus.DEACTIVATED, name12)
            self.assertFalse(team2.inTeam(parent_team))
        script.deactivateInvalidTokens()
        for person in persons2:
            self.assertDeactivated(tokens[person])

        # promiscuous_person also loses the token because they're not in
        # either team now.
        self.assertDeactivated(tokens[promiscuous_person])

        # lonely_person still has their token; they're not in any teams.
        self.assertNotDeactivated(tokens[lonely_person])
Example #21
0
    def testDeactivatingTokens(self):
        """Test that token deactivation happens properly."""
        data = self.setupSubscriptionsAndTokens()
        (team1, team2, parent_team, lonely_person, promiscuous_person,
         all_persons, persons1, persons2, tokens) = data
        team1_person = persons1[0]

        # Initially, nothing is eligible for deactivation.
        script = self.getScript()
        script.deactivateInvalidTokens()
        for person in tokens:
            self.assertNotDeactivated(tokens[person])

        # Now remove someone from team1, he will lose his token but
        # everyone else keeps theirs.
        with lp_dbuser():
            team1_person.leave(team1)
        # Clear out emails generated when leaving a team.
        pop_notifications()

        script.deactivateInvalidTokens(send_email=True)
        self.assertDeactivated(tokens[team1_person])
        del tokens[team1_person]
        for person in tokens:
            self.assertNotDeactivated(tokens[person])

        # Ensure that a cancellation email was sent.
        num_emails = len(stub.test_emails)
        self.assertEqual(num_emails, 1,
                         "Expected 1 email, got %s" % num_emails)

        # Promiscuous_person now leaves team1, but does not lose his
        # token because he's also in team2. No other tokens are
        # affected.
        with lp_dbuser():
            promiscuous_person.leave(team1)
        # Clear out emails generated when leaving a team.
        pop_notifications()
        script.deactivateInvalidTokens(send_email=True)
        self.assertNotDeactivated(tokens[promiscuous_person])
        for person in tokens:
            self.assertNotDeactivated(tokens[person])

        # Ensure that a cancellation email was not sent.
        num_emails = len(stub.test_emails)
        self.assertEqual(num_emails, 0,
                         "Expected no emails, got %s" % num_emails)

        # Team 2 now leaves parent_team, and all its members lose their
        # tokens.
        with lp_dbuser():
            name12 = getUtility(IPersonSet).getByName("name12")
            parent_team.setMembershipData(team2, TeamMembershipStatus.APPROVED,
                                          name12)
            parent_team.setMembershipData(team2,
                                          TeamMembershipStatus.DEACTIVATED,
                                          name12)
            self.assertFalse(team2.inTeam(parent_team))
        script.deactivateInvalidTokens()
        for person in persons2:
            self.assertDeactivated(tokens[person])

        # promiscuous_person also loses the token because he's not in
        # either team now.
        self.assertDeactivated(tokens[promiscuous_person])

        # lonely_person still has his token, he's not in any teams.
        self.assertNotDeactivated(tokens[lonely_person])
 def remove(self, item):
     with lp_dbuser():
         self.bug.addChange(
             BugAttachmentChange(
                 self.ten_minutes_ago, self.person, 'attachment',
                 item, None))
 def makePackageBranch(self):
     with lp_dbuser():
         branch = self.factory.makePackageBranch()
         branch.sourcepackage.setBranch(PackagePublishingPocket.RELEASE,
                                        branch, branch.owner)
     return branch