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