launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #02825
[Merge] lp:~danilo/launchpad/drop-dead-dead-code into lp:launchpad
Данило Шеган has proposed merging lp:~danilo/launchpad/drop-dead-dead-code into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~danilo/launchpad/drop-dead-dead-code/+merge/51899
= Summary =
BugNotificationRecipientReason is unused, albeit nicely tested, class that
duplicates functionality from BugNotificationRecipients.
Since we are not going to use it anytime soon (if ever), let's just drop it.
= Launchpad lint =
Checking for conflicts and issues in changed files.
Linting changed files:
lib/lp/bugs/mail/bugnotificationrecipients.py
lib/lp/bugs/configure.zcml
--
https://code.launchpad.net/~danilo/launchpad/drop-dead-dead-code/+merge/51899
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~danilo/launchpad/drop-dead-dead-code into lp:launchpad.
=== modified file 'lib/lp/bugs/configure.zcml'
--- lib/lp/bugs/configure.zcml 2011-03-01 01:43:33 +0000
+++ lib/lp/bugs/configure.zcml 2011-03-02 14:11:42 +0000
@@ -1099,14 +1099,6 @@
<allow interface="lp.bugs.interfaces.bug.IFileBugData" />
</class>
- <class class="lp.bugs.mail.bugnotificationrecipients.BugNotificationRecipientReason">
- <allow attributes="
- bug
- getReason
- mail_header
- recipient"/>
- </class>
-
<!-- StructuralSubscription -->
<class
=== modified file 'lib/lp/bugs/mail/bugnotificationrecipients.py'
--- lib/lp/bugs/mail/bugnotificationrecipients.py 2010-12-07 16:43:39 +0000
+++ lib/lp/bugs/mail/bugnotificationrecipients.py 2011-03-02 14:11:42 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd. This software is licensed under the
+# Copyright 2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Code for handling bug notification recipients in bug mail."""
@@ -11,110 +11,9 @@
from zope.interface import implements
from canonical.launchpad.interfaces.launchpad import INotificationRecipientSet
-from lp.services.mail.basemailer import RecipientReason
from lp.services.mail.notificationrecipientset import NotificationRecipientSet
-class BugNotificationRecipientReason(RecipientReason):
- """A `RecipientReason` subsclass specifically for `BugNotification`s."""
-
- def _getTemplateValues(self):
- template_values = (
- super(BugNotificationRecipientReason, self)._getTemplateValues())
- if self.recipient != self.subscriber or self.subscriber.is_team:
- template_values['entity_is'] = (
- 'You are a member of %s, which is' %
- self.subscriber.displayname)
- template_values['lc_entity_is'] = (
- 'you are a member of %s, which is' %
- self.subscriber.displayname)
- return template_values
-
- @classmethod
- def makeRationale(cls, rationale, person, duplicate_bug=None):
- """See `RecipientReason.makeRationale`."""
- rationale = RecipientReason.makeRationale(rationale, person)
- if duplicate_bug is not None:
- rationale = "%s via Bug %s" % (rationale, duplicate_bug.id)
-
- return rationale
-
- @classmethod
- def _getReasonTemplate(cls, reason_string, duplicate_bug=None):
- """Return a reason template to pass to __init__()."""
- if duplicate_bug is not None:
- reason_suffix = " (via bug %s)." % duplicate_bug.id
- else:
- reason_suffix = "."
-
- reason_parts = {
- 'prefix':
- "You received this bug notification because %(lc_entity_is)s",
- 'reason': reason_string,
- 'suffix': reason_suffix,
- }
- return "%(prefix)s %(reason)s%(suffix)s" % reason_parts
-
- @classmethod
- def forDupeSubscriber(cls, person, duplicate_bug):
- """Return a `BugNotificationRecipientReason` for a dupe subscriber.
- """
- header = cls.makeRationale(
- 'Subscriber of Duplicate', person, duplicate_bug)
-
- reason = cls._getReasonTemplate(
- "a direct subscriber of a duplicate bug (via bug %s)" %
- duplicate_bug.id)
- return cls(person, person, header, reason)
-
- @classmethod
- def forDirectSubscriber(cls, person, duplicate_bug=None):
- """Return a `BugNotificationRecipientReason` for a direct subscriber.
- """
- header = cls.makeRationale("Subscriber", person, duplicate_bug)
- reason = cls._getReasonTemplate(
- "a direct subscriber of the bug", duplicate_bug)
- return cls(person, person, header, reason)
-
- @classmethod
- def forAssignee(cls, person, duplicate_bug=None):
- """Return a `BugNotificationRecipientReason` for a bug assignee."""
- header = cls.makeRationale("Assignee", person, duplicate_bug)
- reason = cls._getReasonTemplate("a bug assignee", duplicate_bug)
- return cls(person, person, header, reason)
-
- @classmethod
- def forBugSupervisor(cls, person, target, duplicate_bug=None):
- """Return a `BugNotificationRecipientReason` for a bug supervisor."""
- # All displaynames in these reasons should be changed to bugtargetname
- # (as part of bug 113262) once bugtargetname is finalized for packages
- # (bug 113258). Changing it before then would be excessively
- # disruptive.
- header = cls.makeRationale(
- "Bug Supervisor (%s)" % target.displayname, person, duplicate_bug)
- reason = cls._getReasonTemplate(
- "the bug supervisor for %s" % target.displayname, duplicate_bug)
- return cls(person, person, header, reason)
-
- @classmethod
- def forStructuralSubscriber(cls, person, target, duplicate_bug=None):
- """Return a recipient reason for a structural subscriber."""
- header = cls.makeRationale(
- "Subscriber (%s)" % target.displayname, person, duplicate_bug)
- reason = cls._getReasonTemplate(
- "subscribed to %s" % target.displayname, duplicate_bug)
- return cls(person, person, header, reason)
-
- @classmethod
- def forRegistrant(cls, person, target, duplicate_bug=None):
- """Return a recipient reason for a registrant."""
- header = cls.makeRationale(
- "Registrant (%s)" % target.displayname, person, duplicate_bug)
- reason = cls._getReasonTemplate(
- "the registrant for %s" % target.displayname, duplicate_bug)
- return cls(person, person, header, reason)
-
-
class BugNotificationRecipients(NotificationRecipientSet):
"""A set of emails and rationales notified for a bug change.
=== removed file 'lib/lp/bugs/mail/tests/test_bugnotificationrecipients.py'
--- lib/lp/bugs/mail/tests/test_bugnotificationrecipients.py 2010-10-04 19:50:45 +0000
+++ lib/lp/bugs/mail/tests/test_bugnotificationrecipients.py 1970-01-01 00:00:00 +0000
@@ -1,189 +0,0 @@
-# Copyright 2010 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Tests for the bugnotificationrecipients module."""
-
-__metaclass__ = type
-
-import unittest
-
-from canonical.testing.layers import DatabaseFunctionalLayer
-from lp.bugs.mail.bugnotificationrecipients import (
- BugNotificationRecipientReason,
- )
-from lp.testing import TestCaseWithFactory
-
-
-class BugNotificationRecipientReasonTestCase(TestCaseWithFactory):
- """A TestCase for the `BugNotificationRecipientReason` class."""
-
- layer = DatabaseFunctionalLayer
-
- def setUp(self):
- super(BugNotificationRecipientReasonTestCase, self).setUp()
- self.person = self.factory.makePerson()
- self.team = self.factory.makeTeam(owner=self.person)
-
- def _assertReasonAndHeaderAreCorrect(self, recipient_reason,
- expected_reason, expected_header):
- self.assertEqual(expected_header, recipient_reason.mail_header)
- self.assertEqual(expected_reason, recipient_reason.getReason())
-
- def test_forDupeSubscriber(self):
- duplicate_bug = self.factory.makeBug()
- reason = BugNotificationRecipientReason.forDupeSubscriber(
- self.person, duplicate_bug)
-
- expected_header = (
- 'Subscriber of Duplicate via Bug %s' % duplicate_bug.id)
- expected_reason = (
- 'You received this bug notification because you are a direct '
- 'subscriber of a duplicate bug (via bug %s).' % duplicate_bug.id)
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forDupeSubscriber_for_team(self):
- duplicate_bug = self.factory.makeBug()
- reason = BugNotificationRecipientReason.forDupeSubscriber(
- self.team, duplicate_bug)
-
- expected_header = 'Subscriber of Duplicate @%s via Bug %s' % (
- self.team.name, duplicate_bug.id)
- expected_reason = (
- 'You received this bug notification because you are a member of '
- '%s, which is a direct subscriber of a duplicate bug (via bug '
- '%s).' %
- (self.team.displayname, duplicate_bug.id))
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forDirectSubscriber(self):
- reason = BugNotificationRecipientReason.forDirectSubscriber(
- self.person)
-
- expected_header = "Subscriber"
- expected_reason = (
- "You received this bug notification because you are a direct "
- "subscriber of the bug.")
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forDirectSubscriber_for_team(self):
- reason = BugNotificationRecipientReason.forDirectSubscriber(
- self.team)
-
- expected_header = "Subscriber @%s" % self.team.name
- expected_reason = (
- "You received this bug notification because you are a member "
- "of %s, which is a direct subscriber of the bug." %
- self.team.displayname)
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forAssignee(self):
- reason = BugNotificationRecipientReason.forAssignee(self.person)
-
- expected_header = "Assignee"
- expected_reason = (
- "You received this bug notification because you are a bug "
- "assignee.")
-
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forAssignee_for_team(self):
- reason = BugNotificationRecipientReason.forAssignee(self.team)
-
- expected_header = "Assignee @%s" % self.team.name
- expected_reason = (
- "You received this bug notification because you are a member "
- "of %s, which is a bug assignee." % self.team.displayname)
-
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forBugSupervisor(self):
- distro = self.factory.makeDistribution()
- reason = BugNotificationRecipientReason.forBugSupervisor(
- self.person, distro)
-
- expected_header = "Bug Supervisor (%s)" % distro.displayname
- expected_reason = (
- "You received this bug notification because you are the bug "
- "supervisor for %s." % distro.displayname)
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forBugSupervisor_for_team(self):
- distro = self.factory.makeDistribution()
- reason = BugNotificationRecipientReason.forBugSupervisor(
- self.team, distro)
-
- expected_header = "Bug Supervisor (%s) @%s" % (
- distro.displayname, self.team.name)
- expected_reason = (
- "You received this bug notification because you are a member "
- "of %s, which is the bug supervisor for %s." %
- (self.team.displayname, distro.displayname))
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forStructuralSubscriber(self):
- target = self.factory.makeProduct()
- reason = BugNotificationRecipientReason.forStructuralSubscriber(
- self.person, target)
-
- expected_header = "Subscriber (%s)" % target.displayname
- expected_reason = (
- "You received this bug notification because you are subscribed "
- "to %s." % target.displayname)
-
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forStructuralSubscriber_for_team(self):
- target = self.factory.makeProduct()
- reason = BugNotificationRecipientReason.forStructuralSubscriber(
- self.team, target)
-
- expected_header = "Subscriber (%s) @%s" % (
- target.displayname, self.team.name)
- expected_reason = (
- "You received this bug notification because you are a member "
- "of %s, which is subscribed to %s." %
- (self.team.displayname, target.displayname))
-
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forRegistrant(self):
- target = self.factory.makeProduct()
- reason = BugNotificationRecipientReason.forRegistrant(
- self.person, target)
-
- expected_header = "Registrant (%s)" % target.displayname
- expected_reason = (
- "You received this bug notification because you are the "
- "registrant for %s." % target.displayname)
-
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
- def test_forRegistrant_for_team(self):
- target = self.factory.makeProduct()
- reason = BugNotificationRecipientReason.forRegistrant(
- self.team, target)
-
- expected_header = "Registrant (%s) @%s" % (
- target.displayname, self.team.name)
- expected_reason = (
- "You received this bug notification because you are a member "
- "of %s, which is the registrant for %s." % (
- self.team.displayname, target.displayname))
-
- self._assertReasonAndHeaderAreCorrect(
- reason, expected_reason, expected_header)
-
-
-def test_suite():
- return unittest.TestLoader().loadTestsFromName(__name__)