~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/tests/test_bugnotification.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
239
239
    def test_getRecipientFilterData_empty(self):
240
240
        # When there is empty input, there is empty output.
241
241
        self.assertEqual(
242
 
            BugNotificationSet().getRecipientFilterData({}, []),
 
242
            BugNotificationSet().getRecipientFilterData(self.bug, {}, []),
243
243
            {})
244
244
        self.assertEqual(
245
245
            BugNotificationSet().getRecipientFilterData(
246
 
                {}, [self.notification]),
 
246
                self.bug, {}, [self.notification]),
247
247
            {})
248
248
 
249
249
    def test_getRecipientFilterData_other_persons(self):
265
265
             subscriber2: {'sources': sources2,
266
266
                           'filter descriptions': [u'Special Filter!']}},
267
267
            BugNotificationSet().getRecipientFilterData(
268
 
                {self.subscriber: sources, subscriber2: sources2},
 
268
                self.bug, {self.subscriber: sources, subscriber2: sources2},
269
269
                [self.notification, notification2]))
270
270
 
271
271
    def test_getRecipientFilterData_match(self):
277
277
            {self.subscriber: {'sources': sources,
278
278
             'filter descriptions': ['Special Filter!']}},
279
279
            BugNotificationSet().getRecipientFilterData(
280
 
                {self.subscriber: sources}, [self.notification]))
 
280
                self.bug, {self.subscriber: sources}, [self.notification]))
281
281
 
282
282
    def test_getRecipientFilterData_multiple_notifications_match(self):
283
283
        # When there are bug filters for the recipient for multiple
291
291
            {self.subscriber: {'sources': sources,
292
292
             'filter descriptions': ['Another Filter!', 'Special Filter!']}},
293
293
            BugNotificationSet().getRecipientFilterData(
294
 
                {self.subscriber: sources},
 
294
                self.bug, {self.subscriber: sources},
295
295
                [self.notification, self.notification2]))
296
296
 
297
297
    def test_getRecipientFilterData_mute(self):
306
306
        self.assertEqual(
307
307
            {},
308
308
            BugNotificationSet().getRecipientFilterData(
309
 
                {self.subscriber: sources}, [self.notification]))
 
309
                self.bug, {self.subscriber: sources}, [self.notification]))
310
310
 
311
311
    def test_getRecipientFilterData_mute_one_person_of_two(self):
312
312
        self.includeFilterInNotification()
327
327
            {subscriber2: {'sources': sources2,
328
328
                           'filter descriptions': [u'Special Filter!']}},
329
329
            BugNotificationSet().getRecipientFilterData(
330
 
                {self.subscriber: sources, subscriber2: sources2},
 
330
                self.bug, {self.subscriber: sources, subscriber2: sources2},
331
331
                [self.notification, notification2]))
332
332
 
333
333
    def test_getRecipientFilterData_mute_one_filter_of_two(self):
343
343
            {self.subscriber: {'sources': sources,
344
344
             'filter descriptions': ['Another Filter!']}},
345
345
            BugNotificationSet().getRecipientFilterData(
346
 
                {self.subscriber: sources},
 
346
                self.bug, {self.subscriber: sources},
347
347
                [self.notification, self.notification2]))
348
348
 
349
349
    def test_getRecipientFilterData_mute_both_filters_mutes(self):
362
362
        self.assertEqual(
363
363
            {},
364
364
            BugNotificationSet().getRecipientFilterData(
365
 
                {self.subscriber: sources},
 
365
                self.bug, {self.subscriber: sources},
366
366
                [self.notification, self.notification2]))
367
367
 
 
368
    def test_getRecipientFilterData_mute_bug_mutes(self):
 
369
        # Mute the bug for the subscriber.
 
370
        self.team = self.factory.makeTeam()
 
371
        self.subscriber.join(self.team)
 
372
 
 
373
        self.bug.mute(self.subscriber, self.subscriber)
 
374
        sources = list(self.notification.recipients)
 
375
        # Perform the test.
 
376
        self.assertEqual(
 
377
            {},
 
378
            BugNotificationSet().getRecipientFilterData(
 
379
                self.bug, {self.subscriber: sources}, [self.notification]))
 
380
 
 
381
    def test_getRecipientFilterData_mute_bug_mutes_only_themselves(self):
 
382
        # Mute the bug for the subscriber.
 
383
        self.bug.mute(self.subscriber, self.subscriber)
 
384
 
 
385
        # Notification for the other person still goes through.
 
386
        person = self.factory.makePerson(name='other')
 
387
        self.addNotificationRecipient(self.notification, person)
 
388
 
 
389
        sources = list(self.notification.recipients)
 
390
 
 
391
        # Perform the test.
 
392
        self.assertEqual(
 
393
            {person: {'filter descriptions': [],
 
394
                      'sources': sources}},
 
395
            BugNotificationSet().getRecipientFilterData(
 
396
                self.bug, {self.subscriber: sources,
 
397
                           person: sources},
 
398
                [self.notification]))
 
399
 
 
400
    def test_getRecipientFilterData_mute_bug_mutes_filter(self):
 
401
        # Mute the bug for the subscriber.
 
402
        self.bug.mute(self.subscriber, self.subscriber)
 
403
        self.includeFilterInNotification(description=u'Special Filter!')
 
404
        sources = list(self.notification.recipients)
 
405
        self.assertEqual(
 
406
            {},
 
407
            BugNotificationSet().getRecipientFilterData(
 
408
                self.bug, {self.subscriber: sources}, [self.notification]))
 
409
 
368
410
 
369
411
class TestNotificationProcessingWithoutRecipients(TestCaseWithFactory):
370
412
    """Adding notificatons without any recipients does not cause any harm.
596
638
                'filter descriptions': [],
597
639
                'sources': [notification.recipients[1]]}},
598
640
            BugNotificationSet().getRecipientFilterData(
 
641
            bug,
599
642
            {team.teamowner: [notification.recipients[0]],
600
643
             team: [notification.recipients[1]]},
601
644
            [notification]))