def test_change_level_metadata_description(self):
        # Changing a bug description is considered to have change_level
        # of BugNotificationLevel.METADATA.
        bug_delta = self.createDelta(description={"new": "new description", "old": self.bug.description})

        change = list(get_bug_changes(bug_delta))[0]
        self.assertTrue(isinstance(change, BugDescriptionChange))
        self.assertEquals(BugNotificationLevel.METADATA, change.change_level)
    def test_change_level_lifecycle_not_duplicate_of_resolved(self):
        # Un-marking a bug as a duplicate of a resolved bug is
        # a BugNotificationLevel.LIFECYCLE change.
        duplicate_of = self.factory.makeBug()
        duplicate_of.default_bugtask.transitionToStatus(BugTaskStatus.FIXRELEASED, self.user)
        bug_delta = self.createDelta(user=self.bug.owner, duplicateof={"new": None, "old": duplicate_of})

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEquals(BugNotificationLevel.LIFECYCLE, change.change_level)
    def test_change_level_metadata_not_duplicate_of_unresolved(self):
        # Un-marking a bug as a duplicate of an unresolved bug is a
        # simple BugNotificationLevel.METADATA change.
        duplicate_of = self.factory.makeBug()
        duplicate_of.default_bugtask.transitionToStatus(BugTaskStatus.NEW, self.user)
        bug_delta = self.createDelta(user=self.bug.owner, duplicateof={"new": None, "old": duplicate_of})

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEquals(BugNotificationLevel.METADATA, change.change_level)
    def test_change_level_metadata_status_stays_closed(self):
        # Changing a bug task status from OPINION to WONTFIX makes this
        # change a BugNotificationLevel.METADATA change.
        bugtask_delta = BugTaskDelta(
            bugtask=self.bugtask, status={"old": BugTaskStatus.OPINION, "new": BugTaskStatus.WONTFIX}
        )
        bug_delta = self.createDelta(bugtask_deltas=bugtask_delta)

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEquals(BugNotificationLevel.METADATA, change.change_level)
    def test_change_level_metadata_status_worked_on(self):
        # Changing a bug task status from TRIAGED to FIXCOMMITTED makes this
        # change a BugNotificationLevel.METADATA change.
        bugtask_delta = BugTaskDelta(
            bugtask=self.bugtask, status={"old": BugTaskStatus.TRIAGED, "new": BugTaskStatus.FIXCOMMITTED}
        )
        bug_delta = self.createDelta(bugtask_deltas=bugtask_delta)

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEquals(BugNotificationLevel.METADATA, change.change_level)
    def test_change_level_lifecycle_status_reopening(self):
        # Changing a bug task status from FIXRELEASED to TRIAGED makes this
        # change a BugNotificationLevel.LIFECYCLE change.
        bugtask_delta = BugTaskDelta(
            bugtask=self.bugtask, status={"old": BugTaskStatus.FIXRELEASED, "new": BugTaskStatus.TRIAGED}
        )
        bug_delta = self.createDelta(bugtask_deltas=bugtask_delta)

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEquals(BugNotificationLevel.LIFECYCLE, change.change_level)
Beispiel #7
0
    def test_change_level_metadata_description(self):
        # Changing a bug description is considered to have change_level
        # of BugNotificationLevel.METADATA.
        bug_delta = self.createDelta(description={
            'new': 'new description',
            'old': self.bug.description,
        })

        change = list(get_bug_changes(bug_delta))[0]
        self.assertTrue(isinstance(change, BugDescriptionChange))
        self.assertEquals(BugNotificationLevel.METADATA, change.change_level)
Beispiel #8
0
def add_bug_change_notifications(bug_delta,
                                 old_bugtask=None,
                                 new_subscribers=None):
    """Generate bug notifications and add them to the bug."""
    changes = get_bug_changes(bug_delta)
    recipients = bug_delta.bug.getBugNotificationRecipients(
        level=BugNotificationLevel.METADATA)
    if old_bugtask is not None:
        old_bugtask_recipients = BugNotificationRecipients()
        get_also_notified_subscribers(old_bugtask,
                                      recipients=old_bugtask_recipients,
                                      level=BugNotificationLevel.METADATA)
        recipients.update(old_bugtask_recipients)
    for change in changes:
        bug = bug_delta.bug
        if isinstance(change, BugDuplicateChange):
            no_dupe_master_recipients = bug.getBugNotificationRecipients(
                level=change.change_level)
            bug_delta.bug.addChange(change,
                                    recipients=no_dupe_master_recipients)
        elif (isinstance(change, BugTaskAssigneeChange)
              and new_subscribers is not None):
            for person in new_subscribers:
                # If this change involves multiple changes, other structural
                # subscribers will leak into new_subscribers, and they may
                # not be in the recipients list, due to having a LIFECYCLE
                # structural subscription.
                if person not in recipients:
                    continue
                # We are only interested in dropping the assignee out, since
                # we send assignment notifications separately.
                reason, rationale = recipients.getReason(person)
                if 'Assignee' in rationale:
                    recipients.remove(person)
            bug_delta.bug.addChange(change, recipients=recipients)
        else:
            if change.change_level == BugNotificationLevel.LIFECYCLE:
                # XXX: The level handling here is duplicated with the
                # start of this method and *really* needs refactoring.
                change_recipients = BugNotificationRecipients()
                change_recipients.update(recipients)
                change_recipients.update(
                    bug.getBugNotificationRecipients(
                        level=change.change_level))
                if old_bugtask is not None:
                    old_bugtask_recipients = BugNotificationRecipients()
                    get_also_notified_subscribers(
                        old_bugtask,
                        recipients=old_bugtask_recipients,
                        level=change.change_level)
                    change_recipients.update(old_bugtask_recipients)
            else:
                change_recipients = recipients
            bug_delta.bug.addChange(change, recipients=change_recipients)
Beispiel #9
0
    def test_change_level_metadata_status_worked_on(self):
        # Changing a bug task status from TRIAGED to FIXCOMMITTED makes this
        # change a BugNotificationLevel.METADATA change.
        bugtask_delta = BugTaskDelta(bugtask=self.bugtask,
                                     status={
                                         'old': BugTaskStatus.TRIAGED,
                                         'new': BugTaskStatus.FIXCOMMITTED,
                                     })
        bug_delta = self.createDelta(bugtask_deltas=bugtask_delta)

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEquals(BugNotificationLevel.METADATA, change.change_level)
Beispiel #10
0
    def test_change_level_lifecycle_status_reopening(self):
        # Changing a bug task status from FIXRELEASED to TRIAGED makes this
        # change a BugNotificationLevel.LIFECYCLE change.
        bugtask_delta = BugTaskDelta(bugtask=self.bugtask,
                                     status={
                                         'old': BugTaskStatus.FIXRELEASED,
                                         'new': BugTaskStatus.TRIAGED,
                                     })
        bug_delta = self.createDelta(bugtask_deltas=bugtask_delta)

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEquals(BugNotificationLevel.LIFECYCLE, change.change_level)
Beispiel #11
0
    def test_change_level_metadata_status_stays_closed(self):
        # Changing a bug task status from OPINION to WONTFIX makes this
        # change a BugNotificationLevel.METADATA change.
        bugtask_delta = BugTaskDelta(bugtask=self.bugtask,
                                     status={
                                         'old': BugTaskStatus.OPINION,
                                         'new': BugTaskStatus.WONTFIX,
                                     })
        bug_delta = self.createDelta(bugtask_deltas=bugtask_delta)

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEquals(BugNotificationLevel.METADATA, change.change_level)
    def test_change_level_lifecycle_not_duplicate_of_resolved(self):
        # Un-marking a bug as a duplicate of a resolved bug is
        # a BugNotificationLevel.LIFECYCLE change.
        duplicate_of = self.factory.makeBug()
        duplicate_of.default_bugtask.transitionToStatus(
            BugTaskStatus.FIXRELEASED, self.user)
        bug_delta = self.createDelta(
            user=self.bug.owner,
            duplicateof={
                'new': None,
                'old': duplicate_of})

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEqual(BugNotificationLevel.LIFECYCLE, change.change_level)
Beispiel #13
0
    def test_change_level_metadata_not_duplicate_of_unresolved(self):
        # Un-marking a bug as a duplicate of an unresolved bug is a
        # simple BugNotificationLevel.METADATA change.
        duplicate_of = self.factory.makeBug()
        duplicate_of.default_bugtask.transitionToStatus(
            BugTaskStatus.NEW, self.user)
        bug_delta = self.createDelta(user=self.bug.owner,
                                     duplicateof={
                                         'new': None,
                                         'old': duplicate_of,
                                     })

        change = list(get_bug_changes(bug_delta))[0]
        self.assertEquals(BugNotificationLevel.METADATA, change.change_level)
Beispiel #14
0
def add_bug_change_notifications(bug_delta, old_bugtask=None,
                                 new_subscribers=None):
    """Generate bug notifications and add them to the bug."""
    changes = get_bug_changes(bug_delta)
    recipients = bug_delta.bug.getBugNotificationRecipients(
        level=BugNotificationLevel.METADATA)
    if old_bugtask is not None:
        old_bugtask_recipients = BugNotificationRecipients()
        get_also_notified_subscribers(
            old_bugtask, recipients=old_bugtask_recipients,
            level=BugNotificationLevel.METADATA)
        recipients.update(old_bugtask_recipients)
    for change in changes:
        bug = bug_delta.bug
        if isinstance(change, BugDuplicateChange):
            no_dupe_master_recipients = bug.getBugNotificationRecipients(
                level=change.change_level)
            bug_delta.bug.addChange(
                change, recipients=no_dupe_master_recipients)
        elif (isinstance(change, BugTaskAssigneeChange) and
              new_subscribers is not None):
            for person in new_subscribers:
                # If this change involves multiple changes, other structural
                # subscribers will leak into new_subscribers, and they may
                # not be in the recipients list, due to having a LIFECYCLE
                # structural subscription.
                if person not in recipients:
                    continue
                # We are only interested in dropping the assignee out, since
                # we send assignment notifications separately.
                reason, rationale = recipients.getReason(person)
                if 'Assignee' in rationale:
                    recipients.remove(person)
            bug_delta.bug.addChange(change, recipients=recipients)
        else:
            if change.change_level == BugNotificationLevel.LIFECYCLE:
                change_recipients = bug.getBugNotificationRecipients(
                    level=change.change_level)
                recipients.update(change_recipients)
            bug_delta.bug.addChange(change, recipients=recipients)