~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/tests/test_bug.py

[r=gmb][bug=772609] The mute link will now appear for members of
        teams that are structurally subscribed to a bug or its duplicates

Show diffs side-by-side

added added

removed removed

Lines of Context:
249
249
            subscriber not in duplicate_subscribers,
250
250
            "Subscriber should not be in duplicate_subscribers.")
251
251
 
 
252
    def test_subscribers_from_dupes_includes_structural_subscribers(self):
 
253
        # getSubscribersFromDuplicates() also returns subscribers
 
254
        # from structural subscriptions.
 
255
        product = self.factory.makeProduct()
 
256
        bug = self.factory.makeBug()
 
257
        duplicate_bug = self.factory.makeBug(product=product)
 
258
        with person_logged_in(duplicate_bug.owner):
 
259
            duplicate_bug.markAsDuplicate(bug)
 
260
            # We unsubscribe the owner of the duplicate to avoid muddling
 
261
            # the results retuned by getSubscribersFromDuplicates()
 
262
            duplicate_bug.unsubscribe(
 
263
                duplicate_bug.owner, duplicate_bug.owner)
 
264
 
 
265
        subscriber = self.factory.makePerson()
 
266
        with person_logged_in(subscriber):
 
267
            product.addSubscription(subscriber, subscriber)
 
268
 
 
269
        self.assertEqual(
 
270
            (subscriber,),
 
271
            bug.getSubscribersFromDuplicates())
 
272
 
252
273
    def test_getSubscriptionInfo(self):
253
274
        # getSubscriptionInfo() returns a BugSubscriptionInfo object.
254
275
        bug = self.factory.makeBug()
261
282
        with person_logged_in(bug.owner):
262
283
            info = bug.getSubscriptionInfo(BugNotificationLevel.METADATA)
263
284
        self.assertEqual(BugNotificationLevel.METADATA, info.level)
 
285
 
 
286
    def test_personIsAlsoNotifiedSubscriber_direct_subscriber(self):
 
287
        # personIsAlsoNotifiedSubscriber() returns false for
 
288
        # direct subscribers.
 
289
        product = self.factory.makeProduct()
 
290
        bug = self.factory.makeBug()
 
291
 
 
292
        subscriber = self.factory.makePerson()
 
293
        with person_logged_in(subscriber):
 
294
            bug.subscribe(subscriber, subscriber)
 
295
 
 
296
        self.assertFalse(
 
297
            bug.personIsAlsoNotifiedSubscriber(subscriber))
 
298
 
 
299
    def test_personIsAlsoNotifiedSubscriber_direct_subscriber_team(self):
 
300
        # personIsAlsoNotifiedSubscriber() returns true for
 
301
        # direct subscribers even if a team they are a member of
 
302
        # is the direct subscriber to the bug.
 
303
        product = self.factory.makeProduct()
 
304
        bug = self.factory.makeBug()
 
305
 
 
306
        person = self.factory.makePerson()
 
307
        subscriber = self.factory.makeTeam(members=[person])
 
308
 
 
309
        with person_logged_in(subscriber.teamowner):
 
310
            bug.subscribe(subscriber, subscriber.teamowner)
 
311
 
 
312
        self.assertTrue(
 
313
            bug.personIsAlsoNotifiedSubscriber(person))
 
314
 
 
315
    def test_personIsAlsoNotifiedSubscriber_duplicate_subscriber(self):
 
316
        # personIsAlsoNotifiedSubscriber() returns false for
 
317
        # duplicate subscribers.
 
318
        product = self.factory.makeProduct()
 
319
        bug = self.factory.makeBug()
 
320
        duplicate_bug = self.factory.makeBug(product=product)
 
321
        with person_logged_in(duplicate_bug.owner):
 
322
            duplicate_bug.markAsDuplicate(bug)
 
323
            # We unsubscribe the owner of the duplicate to avoid muddling
 
324
            # the results retuned by getSubscribersFromDuplicates()
 
325
            duplicate_bug.unsubscribe(
 
326
                duplicate_bug.owner, duplicate_bug.owner)
 
327
 
 
328
        subscriber = self.factory.makePerson()
 
329
        with person_logged_in(subscriber):
 
330
            duplicate_bug.subscribe(subscriber, subscriber)
 
331
 
 
332
        self.assertFalse(
 
333
            bug.personIsAlsoNotifiedSubscriber(subscriber))
 
334
 
 
335
    def test_personIsAlsoNotifiedSubscriber_duplicate_subscriber_team(self):
 
336
        # personIsAlsoNotifiedSubscriber() returns true for
 
337
        # duplicate subscribers even if a team they are a member of
 
338
        # is the direct subscriber to the duplicate bug.
 
339
        product = self.factory.makeProduct()
 
340
        bug = self.factory.makeBug()
 
341
        duplicate_bug = self.factory.makeBug(product=product)
 
342
        with person_logged_in(duplicate_bug.owner):
 
343
            duplicate_bug.markAsDuplicate(bug)
 
344
            # We unsubscribe the owner of the duplicate to avoid muddling
 
345
            # the results retuned by getSubscribersFromDuplicates()
 
346
            duplicate_bug.unsubscribe(
 
347
                duplicate_bug.owner, duplicate_bug.owner)
 
348
 
 
349
        person = self.factory.makePerson()
 
350
        subscriber = self.factory.makeTeam(members=[person])
 
351
 
 
352
        with person_logged_in(subscriber.teamowner):
 
353
            duplicate_bug.subscribe(subscriber, subscriber.teamowner)
 
354
 
 
355
        self.assertTrue(
 
356
            bug.personIsAlsoNotifiedSubscriber(person))