~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/browser/tests/test_bugnomination.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-11-03 19:00:42 UTC
  • mfrom: (14213.6.2 assign-bug-843415)
  • Revision ID: launchpad@pqm.canonical.com-20111103190042-xa780iyekx8b91bx
[r=jcsackett][bug=843415] Add an edit button next to the assignee of
        each bugtask when a bug has more than 10 bugtasks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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).
3
3
 
4
4
"""Tests for bug nomination views."""
5
5
 
6
6
__metaclass__ = type
7
7
 
 
8
import re
 
9
 
 
10
import soupmatchers
 
11
from testtools.matchers import Not
8
12
from zope.component import getUtility
9
13
 
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,
14
17
    ILaunchBag,
15
18
    )
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 (
19
23
    login_person,
145
149
        self.assertEqual(0, len(view.request.notifications))
146
150
 
147
151
 
 
152
class TestBugEditLinks(TestCaseWithFactory):
 
153
 
 
154
    layer = DatabaseFunctionalLayer
 
155
 
 
156
    edit_link_matcher = soupmatchers.HTMLContains(
 
157
        soupmatchers.Tag(
 
158
            'Edit link', 'a',
 
159
            attrs={'class': 'assignee-edit',
 
160
                   'href': re.compile('\+editstatus$')}))
 
161
 
 
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)
 
169
        launchbag.add(bug)
 
170
        launchbag.add(bug.default_bugtask)
 
171
        return bug
 
172
 
 
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)
 
182
 
 
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))
 
192
 
 
193
    def test_assignee_edit_link_no_user_no_link(self):
 
194
        # No link is displayed when the request is from an anonymous
 
195
        # user.
 
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))
 
200
 
 
201
 
148
202
class TestBugNominationEditView(TestCaseWithFactory):
149
203
    """Tests for BugNominationEditView."""
150
204