1
# Copyright 2010 Canonical Ltd. This software is licensed under the
1
# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
4
"""Tests for bug nomination views."""
11
from testtools.matchers import Not
8
12
from zope.component import getUtility
10
from canonical.testing.layers import DatabaseFunctionalLayer
11
14
from canonical.launchpad.webapp.interaction import get_current_principal
12
15
from canonical.launchpad.webapp.interfaces import (
13
16
BrowserNotificationLevel,
16
19
from canonical.launchpad.webapp.publisher import canonical_url
20
from canonical.testing.layers import DatabaseFunctionalLayer
17
21
from lp.registry.interfaces.series import SeriesStatus
18
22
from lp.testing import (
145
149
self.assertEqual(0, len(view.request.notifications))
152
class TestBugEditLinks(TestCaseWithFactory):
154
layer = DatabaseFunctionalLayer
156
edit_link_matcher = soupmatchers.HTMLContains(
159
attrs={'class': 'assignee-edit',
160
'href': re.compile('\+editstatus$')}))
162
def _createBug(self, bug_task_number=1):
163
series = self.factory.makeProductSeries()
164
bug = self.factory.makeBug(series=series)
165
for i in range(bug_task_number):
166
self.factory.makeBugTask(bug=bug)
167
launchbag = getUtility(ILaunchBag)
168
launchbag.add(series.product)
170
launchbag.add(bug.default_bugtask)
173
def test_assignee_edit_link_with_many_bugtasks(self):
174
# When the number of bug tasks is >= 10, a link should be
175
# displayed to edit the assignee.
176
bug = self._createBug(11)
177
with person_logged_in(bug.owner):
178
page = create_initialized_view(
179
bug, name='+bugtasks-and-nominations-table',
180
principal=bug.owner).render()
181
self.assertThat(page, self.edit_link_matcher)
183
def test_assignee_edit_link_with_only_a_few_bugtasks(self):
184
# When the number of bug tasks is < 10, editing the assignee is
185
# done with a js picker.
186
bug = self._createBug(3)
187
with person_logged_in(bug.owner):
188
page = create_initialized_view(
189
bug, name='+bugtasks-and-nominations-table',
190
principal=bug.owner).render()
191
self.assertThat(page, Not(self.edit_link_matcher))
193
def test_assignee_edit_link_no_user_no_link(self):
194
# No link is displayed when the request is from an anonymous
196
bug = self._createBug(11)
197
page = create_initialized_view(
198
bug, name='+bugtasks-and-nominations-table').render()
199
self.assertThat(page, Not(self.edit_link_matcher))
148
202
class TestBugNominationEditView(TestCaseWithFactory):
149
203
"""Tests for BugNominationEditView."""