~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/adapters/tests/test_notification.py

Merged pending-db-changes into db-cleanups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from lp.soyuz.model.distroseriessourcepackagerelease import (
39
39
    DistroSeriesSourcePackageRelease,
40
40
    )
41
 
from lp.testing import TestCaseWithFactory
 
41
from lp.testing import (
 
42
    person_logged_in,
 
43
    TestCaseWithFactory,
 
44
    )
42
45
from lp.testing.mail_helpers import pop_notifications
43
46
 
44
47
 
83
86
            'accepted')
84
87
        self.assertEqual(expected_subject, subject)
85
88
 
 
89
    def _setup_notification(self, from_person=None, distroseries=None,
 
90
                            spr=None):
 
91
        if spr is None:
 
92
            spr = self.factory.makeSourcePackageRelease()
 
93
        self.factory.makeSourcePackageReleaseFile(sourcepackagerelease=spr)
 
94
        archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
 
95
        pocket = PackagePublishingPocket.RELEASE
 
96
        if distroseries is None:
 
97
            distroseries = self.factory.makeDistroSeries()
 
98
        distroseries.changeslist = "blah@example.com"
 
99
        blamer = self.factory.makePerson()
 
100
        if from_person is None:
 
101
            from_person = self.factory.makePerson()
 
102
        notify(
 
103
            blamer, spr, [], [], archive, distroseries, pocket,
 
104
            action='accepted', announce_from_person=from_person)
 
105
 
86
106
    def test_notify_from_person_override(self):
87
107
        # notify() takes an optional from_person to override the calculated
88
108
        # From: address in announcement emails.
89
 
        spr = self.factory.makeSourcePackageRelease()
90
 
        self.factory.makeSourcePackageReleaseFile(sourcepackagerelease=spr)
91
 
        archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
92
 
        pocket = PackagePublishingPocket.RELEASE
93
 
        distroseries = self.factory.makeDistroSeries()
94
 
        distroseries.changeslist = "blah@example.com"
95
 
        blamer = self.factory.makePerson()
96
109
        from_person = self.factory.makePerson()
97
 
        notify(
98
 
            blamer, spr, [], [], archive, distroseries, pocket,
99
 
            action='accepted', announce_from_person=from_person)
 
110
        self._setup_notification(from_person=from_person)
100
111
        notifications = pop_notifications()
101
112
        self.assertEqual(2, len(notifications))
102
113
        # The first notification is to the blamer,
105
116
        self.assertEqual(
106
117
            from_person.preferredemail.email, notifications[1]["From"])
107
118
 
 
119
    def test_notify_bcc_to_derivatives_list(self):
 
120
        # notify() will BCC the announcement email to the address defined in
 
121
        # Distribution.package_derivatives_email if it's defined.
 
122
        email = "{package_name}_thing@foo.com"
 
123
        distroseries = self.factory.makeDistroSeries()
 
124
        with person_logged_in(distroseries.distribution.owner):
 
125
            distroseries.distribution.package_derivatives_email = email
 
126
        spr = self.factory.makeSourcePackageRelease()
 
127
        self._setup_notification(distroseries=distroseries, spr=spr)
 
128
 
 
129
        notifications = pop_notifications()
 
130
        self.assertEqual(2, len(notifications))
 
131
        bcc_address = notifications[1]["Bcc"]
 
132
        expected_email = email.format(package_name=spr.sourcepackagename.name)
 
133
        self.assertIn(expected_email, bcc_address)
 
134
 
108
135
 
109
136
class TestNotification(TestCaseWithFactory):
110
137