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
12
13
from canonical.testing.layers import DatabaseFunctionalLayer
39
40
self.person = self.factory.makePerson()
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):
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))
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
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)
63
69
def test_mute_mutes_user(self):
64
# Bug.mute() adds a muted subscription for the user passed to
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)
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)
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))
82
87
def test_mute_mutes_user_with_existing_subscription(self):
83
# Bug.mute() will update an existing subscription so that it
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))
90
BugNotificationLevel.NOTHING,
96
BugNotificationLevel.METADATA,
91
97
subscription.bug_notification_level)
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))
108
def test_unmute_returns_direct_subscription(self):
109
# Bug.unmute() returns the previously muted direct subscription, if
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))
122
subscription, self.bug.unmute(self.person, self.person))
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