~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
from lazr.lifecycle.snapshot import Snapshot
9
9
from zope.component import getUtility
10
10
from zope.interface import providedBy
 
11
from zope.security.proxy import removeSecurityProxy
11
12
 
12
13
from canonical.testing.layers import DatabaseFunctionalLayer
13
14
 
39
40
        self.person = self.factory.makePerson()
40
41
 
41
42
    def test_is_muted_returns_true_for_muted_users(self):
42
 
        # Bug.isMuted() will return True if the passed to it has a
43
 
        # BugSubscription with a BugNotificationLevel of NOTHING.
 
43
        # Bug.isMuted() will return True if the person passed to it is muted.
44
44
        with person_logged_in(self.person):
45
 
            self.bug.subscribe(
46
 
                self.person, self.person, level=BugNotificationLevel.NOTHING)
 
45
            self.bug.mute(self.person, self.person)
47
46
            self.assertEqual(True, self.bug.isMuted(self.person))
48
47
 
49
48
    def test_is_muted_returns_false_for_direct_subscribers(self):
50
 
        # Bug.isMuted() will return False if the user has a subscription
51
 
        # with BugNotificationLevel that's not NOTHING.
 
49
        # Bug.isMuted() will return False if the user has a
 
50
        # regular subscription.
52
51
        with person_logged_in(self.person):
53
52
            self.bug.subscribe(
54
53
                self.person, self.person, level=BugNotificationLevel.METADATA)
60
59
        with person_logged_in(self.person):
61
60
            self.assertEqual(False, self.bug.isMuted(self.person))
62
61
 
 
62
    def test_mute_team_fails(self):
 
63
        # Muting a subscription for an entire team doesn't work.
 
64
        with person_logged_in(self.person):
 
65
            team = self.factory.makeTeam(owner=self.person)
 
66
            self.assertRaises(AssertionError,
 
67
                              self.bug.mute, team, team)
 
68
 
63
69
    def test_mute_mutes_user(self):
64
 
        # Bug.mute() adds a muted subscription for the user passed to
65
 
        # it.
 
70
        # Bug.mute() adds a BugMute record for the person passed to it.
66
71
        with person_logged_in(self.person):
67
 
            muted_subscription = self.bug.mute(
68
 
                self.person, self.person)
69
 
            self.assertEqual(
70
 
                BugNotificationLevel.NOTHING,
71
 
                muted_subscription.bug_notification_level)
 
72
            self.bug.mute(self.person, self.person)
 
73
            naked_bug = removeSecurityProxy(self.bug)
 
74
            bug_mute = naked_bug._getMutes(self.person).one()
 
75
            self.assertEqual(self.bug, bug_mute.bug)
 
76
            self.assertEqual(self.person, bug_mute.person)
72
77
 
73
78
    def test_mute_mutes_muter(self):
74
79
        # When exposed in the web API, the mute method regards the
80
85
            self.assertTrue(self.bug.isMuted(self.person))
81
86
 
82
87
    def test_mute_mutes_user_with_existing_subscription(self):
83
 
        # Bug.mute() will update an existing subscription so that it
84
 
        # becomes muted.
 
88
        # Bug.mute() will not touch the existing subscription.
85
89
        with person_logged_in(self.person):
86
 
            subscription = self.bug.subscribe(self.person, self.person)
87
 
            muted_subscription = self.bug.mute(self.person, self.person)
88
 
            self.assertEqual(subscription, muted_subscription)
 
90
            subscription = self.bug.subscribe(
 
91
                self.person, self.person,
 
92
                level=BugNotificationLevel.METADATA)
 
93
            self.bug.mute(self.person, self.person)
 
94
            self.assertTrue(self.bug.isMuted(self.person))
89
95
            self.assertEqual(
90
 
                BugNotificationLevel.NOTHING,
 
96
                BugNotificationLevel.METADATA,
91
97
                subscription.bug_notification_level)
92
98
 
93
99
    def test_unmute_unmutes_user(self):
99
105
            self.bug.unmute(self.person, self.person)
100
106
            self.assertFalse(self.bug.isMuted(self.person))
101
107
 
 
108
    def test_unmute_returns_direct_subscription(self):
 
109
        # Bug.unmute() returns the previously muted direct subscription, if
 
110
        # any.
 
111
        with person_logged_in(self.person):
 
112
            self.bug.mute(self.person, self.person)
 
113
            self.assertEqual(True, self.bug.isMuted(self.person))
 
114
            self.assertEqual(None, self.bug.unmute(self.person, self.person))
 
115
            self.assertEqual(False, self.bug.isMuted(self.person))
 
116
            subscription = self.bug.subscribe(
 
117
                self.person, self.person,
 
118
                level=BugNotificationLevel.METADATA)
 
119
            self.bug.mute(self.person, self.person)
 
120
            self.assertEqual(True, self.bug.isMuted(self.person))
 
121
            self.assertEqual(
 
122
                subscription, self.bug.unmute(self.person, self.person))
 
123
 
102
124
    def test_unmute_mutes_unmuter(self):
103
125
        # When exposed in the web API, the unmute method regards the
104
126
        # first, `person` argument as optional, and the second