12098.2.5
by Curtis Hovey
Revise the UI for +nominate. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
12098.2.7
by Curtis Hovey
Fixed grammar. |
4 |
"""Tests for bug nomination views."""
|
12098.2.5
by Curtis Hovey
Revise the UI for +nominate. |
5 |
|
6 |
__metaclass__ = type |
|
7 |
||
8 |
from zope.component import getUtility |
|
9 |
||
10 |
from canonical.testing.layers import DatabaseFunctionalLayer |
|
13025.1.4
by William Grant
Test that approving/declining an approved nomination doesn't crash. |
11 |
from canonical.launchpad.webapp.interaction import get_current_principal |
13060.1.1
by Ian Booth
Redirect back to bug target with error message if insufficient permissions |
12 |
from canonical.launchpad.webapp.interfaces import ( |
13 |
BrowserNotificationLevel, |
|
14 |
ILaunchBag, |
|
15 |
)
|
|
16 |
from canonical.launchpad.webapp.publisher import canonical_url |
|
12098.2.5
by Curtis Hovey
Revise the UI for +nominate. |
17 |
from lp.testing import ( |
18 |
login_person, |
|
19 |
person_logged_in, |
|
20 |
TestCaseWithFactory, |
|
21 |
)
|
|
13025.1.4
by William Grant
Test that approving/declining an approved nomination doesn't crash. |
22 |
from lp.testing.matchers import Contains |
12098.2.5
by Curtis Hovey
Revise the UI for +nominate. |
23 |
from lp.testing.views import create_initialized_view |
24 |
||
25 |
||
26 |
class TestBugNominationView(TestCaseWithFactory): |
|
27 |
"""Tests for BugNominationView."""
|
|
28 |
||
29 |
layer = DatabaseFunctionalLayer |
|
30 |
||
31 |
def setUp(self): |
|
32 |
super(TestBugNominationView, self).setUp() |
|
33 |
self.distribution = self.factory.makeDistribution() |
|
34 |
owner = self.distribution.owner |
|
35 |
bug_team = self.factory.makeTeam(owner=owner) |
|
36 |
self.bug_worker = self.factory.makePerson() |
|
37 |
with person_logged_in(owner): |
|
38 |
bug_team.addMember(self.bug_worker, owner) |
|
39 |
self.distribution.setBugSupervisor(bug_team, owner) |
|
40 |
self.distribution.driver = self.factory.makePerson() |
|
41 |
self.bug_task = self.factory.makeBugTask(target=self.distribution) |
|
42 |
launchbag = getUtility(ILaunchBag) |
|
43 |
launchbag.add(self.distribution) |
|
44 |
launchbag.add(self.bug_task) |
|
45 |
||
46 |
def test_submit_action_bug_supervisor(self): |
|
47 |
# A bug supervisor sees the Nominate action label.
|
|
48 |
login_person(self.bug_worker) |
|
49 |
view = create_initialized_view(self.bug_task, name='+nominate') |
|
50 |
action = view.__class__.actions.byname['actions.submit'] |
|
51 |
self.assertEqual('Nominate', action.label) |
|
52 |
||
53 |
def test_submit_action_driver(self): |
|
54 |
# A driver sees the Target action label.
|
|
55 |
login_person(self.distribution.driver) |
|
56 |
view = create_initialized_view(self.bug_task, name='+nominate') |
|
57 |
action = view.__class__.actions.byname['actions.submit'] |
|
58 |
self.assertEqual('Target', action.label) |
|
13025.1.4
by William Grant
Test that approving/declining an approved nomination doesn't crash. |
59 |
|
13060.1.1
by Ian Booth
Redirect back to bug target with error message if insufficient permissions |
60 |
def test_submit_action_unauthorised(self): |
61 |
# An unauthorised user sees an error on the bug target page.
|
|
62 |
login_person(None) |
|
63 |
view = create_initialized_view(self.bug_task, name='+nominate') |
|
64 |
self.assertEqual( |
|
65 |
canonical_url(self.bug_task), |
|
66 |
view.request.response.getHeader('Location')) |
|
67 |
notifications = view.request.notifications |
|
68 |
self.assertEqual(1, len(notifications)) |
|
69 |
self.assertEqual( |
|
70 |
BrowserNotificationLevel.ERROR, notifications[0].level) |
|
71 |
self.assertEqual( |
|
72 |
"You do not have permission to nominate this bug.", |
|
73 |
notifications[0].message) |
|
74 |
||
13025.1.4
by William Grant
Test that approving/declining an approved nomination doesn't crash. |
75 |
|
76 |
class TestBugNominationEditView(TestCaseWithFactory): |
|
77 |
"""Tests for BugNominationEditView."""
|
|
78 |
||
79 |
layer = DatabaseFunctionalLayer |
|
80 |
||
13025.1.6
by William Grant
Refactor the tests. |
81 |
def getNomination(self): |
82 |
nomination = self.factory.makeBugNomination( |
|
83 |
target=self.factory.makeProductSeries()) |
|
84 |
login_person(nomination.productseries.product.owner) |
|
85 |
return nomination |
|
86 |
||
87 |
def getNominationEditView(self, nomination, form): |
|
88 |
getUtility(ILaunchBag).add(nomination.bug.default_bugtask) |
|
89 |
view = create_initialized_view( |
|
90 |
nomination, name='+editstatus', |
|
91 |
current_request=True, |
|
92 |
principal=get_current_principal(), |
|
93 |
form=form) |
|
94 |
return view |
|
95 |
||
96 |
def assertApproves(self, nomination): |
|
97 |
self.assertEquals( |
|
98 |
302, |
|
99 |
self.getNominationEditView( |
|
100 |
nomination, |
|
101 |
{'field.actions.approve': 'Approve'}, |
|
102 |
).request.response.getStatus()) |
|
103 |
self.assertTrue(nomination.isApproved()) |
|
104 |
||
13025.1.4
by William Grant
Test that approving/declining an approved nomination doesn't crash. |
105 |
def test_approving_twice_is_noop(self): |
13025.1.6
by William Grant
Refactor the tests. |
106 |
nomination = self.getNomination() |
107 |
self.assertApproves(nomination) |
|
13025.1.4
by William Grant
Test that approving/declining an approved nomination doesn't crash. |
108 |
self.assertThat( |
13025.1.6
by William Grant
Refactor the tests. |
109 |
self.getNominationEditView( |
110 |
nomination, |
|
111 |
{'field.actions.approve': 'Approve'}).render(), |
|
13025.1.4
by William Grant
Test that approving/declining an approved nomination doesn't crash. |
112 |
Contains("This nomination has already been approved.")) |
113 |
||
114 |
def test_declining_approved_is_noop(self): |
|
13025.1.6
by William Grant
Refactor the tests. |
115 |
nomination = self.getNomination() |
116 |
self.assertApproves(nomination) |
|
13025.1.4
by William Grant
Test that approving/declining an approved nomination doesn't crash. |
117 |
self.assertThat( |
13025.1.6
by William Grant
Refactor the tests. |
118 |
self.getNominationEditView( |
119 |
nomination, |
|
120 |
{'field.actions.decline': 'Decline'}).render(), |
|
13025.1.4
by William Grant
Test that approving/declining an approved nomination doesn't crash. |
121 |
Contains("This nomination has already been approved.")) |