~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

Merge stable r13828, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
from email.utils import formataddr
9
9
from storm.store import Store
 
10
from textwrap import dedent
10
11
from zope.component import getUtility
11
12
from zope.security.proxy import removeSecurityProxy
12
13
 
168
169
        expected_email = email.format(package_name=spr.sourcepackagename.name)
169
170
        self.assertIn(expected_email, bcc_address)
170
171
 
 
172
    def test_fetch_information_spr_multiple_changelogs(self):
 
173
        # If previous_version is passed the "changelog" entry in the
 
174
        # returned dict should contain the changelogs for all SPRs *since*
 
175
        # that version and up to and including the passed SPR.
 
176
        changelog = self.factory.makeChangelog(
 
177
            spn="foo", versions=["1.2",  "1.1",  "1.0"])
 
178
        spph = self.factory.makeSourcePackagePublishingHistory(
 
179
            sourcepackagename="foo", version="1.3", changelog=changelog)
 
180
        self.layer.txn.commit()  # Yay, librarian.
 
181
 
 
182
        spr = spph.sourcepackagerelease
 
183
        info = fetch_information(spr, None, None, previous_version="1.0")
 
184
 
 
185
        self.assertIn("foo (1.1)", info['changelog'])
 
186
        self.assertIn("foo (1.2)", info['changelog'])
 
187
 
 
188
    def test_notify_bpr_rejected(self):
 
189
        # If we notify about a rejected bpr with no source, a notification is
 
190
        # sent.
 
191
        bpr = self.factory.makeBinaryPackageRelease()
 
192
        changelog = self.factory.makeChangelog(spn="foo", versions=["1.1"])
 
193
        removeSecurityProxy(
 
194
            bpr.build.source_package_release).changelog = changelog
 
195
        self.layer.txn.commit()
 
196
        archive = self.factory.makeArchive()
 
197
        pocket = self.factory.getAnyPocket()
 
198
        distroseries = self.factory.makeDistroSeries()
 
199
        person = self.factory.makePerson()
 
200
        notify(
 
201
            person, None, [bpr], [], archive, distroseries, pocket,
 
202
            action='rejected')
 
203
        [notification] = pop_notifications()
 
204
        body = notification.get_payload()[0].get_payload()
 
205
        self.assertEqual(person_to_email(person), notification['To'])
 
206
        expected_body = dedent("""\
 
207
            Rejected:
 
208
            Rejected by archive administrator.
 
209
 
 
210
            foo (1.1) unstable; urgency=3Dlow
 
211
 
 
212
              * 1.1.
 
213
 
 
214
            =3D=3D=3D
 
215
 
 
216
            If you don't understand why your files were rejected please send an email
 
217
            to launchpad-users@lists.launchpad.net for help (requires membership).
 
218
 
 
219
            -- =
 
220
 
 
221
            You are receiving this email because you are the uploader of the above
 
222
            PPA package.
 
223
            """)
 
224
        self.assertEqual(expected_body, body)
 
225
 
171
226
 
172
227
class TestNotification(TestCaseWithFactory):
173
228
 
183
238
        info = fetch_information(
184
239
            None, None, changes)
185
240
        self.assertEqual('2001-01-01', info['date'])
186
 
        self.assertEqual(' * Foo!', info['changesfile'])
 
241
        self.assertEqual(' * Foo!', info['changelog'])
187
242
        fields = [
188
243
            info['changedby'],
189
244
            info['maintainer'],
200
255
            creator=creator, maintainer=maintainer)
201
256
        info = fetch_information(spr, None, None)
202
257
        self.assertEqual(info['date'], spr.dateuploaded)
203
 
        self.assertEqual(info['changesfile'], spr.changelog_entry)
 
258
        self.assertEqual(info['changelog'], spr.changelog_entry)
204
259
        self.assertEqual(
205
260
            info['changedby'], format_address_for_person(spr.creator))
206
261
        self.assertEqual(
217
272
        info = fetch_information(None, [bpr], None)
218
273
        spr = bpr.build.source_package_release
219
274
        self.assertEqual(info['date'], spr.dateuploaded)
220
 
        self.assertEqual(info['changesfile'], spr.changelog_entry)
 
275
        self.assertEqual(info['changelog'], spr.changelog_entry)
221
276
        self.assertEqual(
222
277
            info['changedby'], format_address_for_person(spr.creator))
223
278
        self.assertEqual(
270
325
        notifications = pop_notifications()
271
326
        self.assertEqual(0, len(notifications))
272
327
 
273
 
    def test_notify_bpr_rejected(self):
274
 
        # If we notify about a rejected bpr with no source, a notification is
275
 
        # sent.
276
 
        bpr = self.factory.makeBinaryPackageRelease()
277
 
        removeSecurityProxy(
278
 
            bpr.build.source_package_release).changelog_entry = '* Foo!'
279
 
        archive = self.factory.makeArchive()
280
 
        pocket = self.factory.getAnyPocket()
281
 
        distroseries = self.factory.makeDistroSeries()
282
 
        person = self.factory.makePerson()
283
 
        notify(
284
 
            person, None, [bpr], [], archive, distroseries, pocket,
285
 
            action='rejected')
286
 
        [notification] = pop_notifications()
287
 
        body = notification.as_string()
288
 
        self.assertEqual(person_to_email(person), notification['To'])
289
 
        self.assertIn('Rejected by archive administrator.\n\n* Foo!\n', body)
290
 
 
291
328
    def test_reject_changes_file_no_email(self):
292
329
        # If we are rejecting a mail, and the person to notify has no
293
330
        # preferred email, we should return early.