Merge lp:~deryck/launchpad/better-testing-for-status-changes into lp:launchpad
- better-testing-for-status-changes
- Merge into devel
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Deryck Hodge | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 11754 | ||||
Proposed branch: | lp:~deryck/launchpad/better-testing-for-status-changes | ||||
Merge into: | lp:launchpad | ||||
Diff against target: |
534 lines (+366/-146) 2 files modified
lib/lp/bugs/doc/bugtask-status-changes.txt (+51/-131) lib/lp/bugs/tests/test_bugtask_status.py (+315/-15) |
||||
To merge this branch: | bzr merge lp:~deryck/launchpad/better-testing-for-status-changes | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Abel Deuring (community) | code | Approve | |
Review via email: mp+38552@code.launchpad.net |
Commit message
Refactor doctest for bugtask status changes into separate unit test and documentation.
Description of the change
This branch is the first toward a fix for Bug #126516, or more specifically for a fix to limit transitioning away from Fix Released status. Before this branch the tests for bugtask status changes was a mix of a unit test and doctest, both living under lp.bugs.tests.
The branch refactors that mess, opting to do a complete unit test of BugTask.
To test, run:
./bin/test -cvvt bugtask-
./bin/test -cvvt test_bugtask_status
Thanks for the review!
Abel Deuring (adeuring) wrote : | # |
Abel Deuring (adeuring) wrote : | # |
Hi Deryck,
thanks for the refactoring. r=me.
Just a few nitpicks:
could you add TestCases for the celebrities bug_watch_updater,
bug_importer, janitor?
> +class TestBugTaskStat
> + """Base class used to test privileged users and status transitions."""
> +
> + layer = LaunchpadFuncti
> +
> + def setUp(self):
> + super(TestBugTa
> + # Creation of task and target are deferred to subclasses.
> + self.task = None
> + self.person = None
> + self.makePerson
> +
> + def makePersonAndTa
> + """Create a bug task and privileged person for this task.
> +
> + This method is user by subclasses to correctly setup
> + each test.
> + """
I think this should be something like "is (overloaded|
subclasses"
cheers
Abel
Preview Diff
1 | === renamed file 'lib/lp/bugs/tests/test_bugtask_status.txt' => 'lib/lp/bugs/doc/bugtask-status-changes.txt' | |||
2 | --- lib/lp/bugs/tests/test_bugtask_status.txt 2010-10-09 16:36:22 +0000 | |||
3 | +++ lib/lp/bugs/doc/bugtask-status-changes.txt 2010-10-19 13:36:54 +0000 | |||
4 | @@ -1,137 +1,57 @@ | |||
9 | 1 | = Setting Bug Statuses = | 1 | Changing Bug Task Status |
10 | 2 | 2 | ======================== | |
11 | 3 | >>> from canonical.launchpad.interfaces import ( | 3 | |
12 | 4 | ... CreateBugParams, IPersonSet, IProductSet) | 4 | Restrictions |
13 | 5 | ------------ | ||
14 | 6 | |||
15 | 7 | There are a few simple rules around who can change the status of a | ||
16 | 8 | bug task. There are three statuses that can only be set by either | ||
17 | 9 | the project registrant or the bug supervisor: | ||
18 | 10 | |||
19 | 11 | * Won't Fix | ||
20 | 12 | * Expired | ||
21 | 13 | * Triaged | ||
22 | 14 | |||
23 | 15 | >>> owner = factory.makePerson() | ||
24 | 16 | >>> product = factory.makeProduct(owner=owner) | ||
25 | 17 | >>> bugtask = factory.makeBugTask(target=product) | ||
26 | 18 | >>> user = factory.makePerson() | ||
27 | 19 | |||
28 | 5 | >>> from lp.bugs.interfaces.bugtask import BugTaskStatus | 20 | >>> from lp.bugs.interfaces.bugtask import BugTaskStatus |
127 | 6 | 21 | >>> login_person(owner) | |
128 | 7 | >>> firefox = getUtility(IProductSet).getByName('firefox') | 22 | >>> bugtask.transitionToStatus(BugTaskStatus.WONTFIX, owner) |
129 | 8 | >>> nopriv_user = getUtility(IPersonSet).getByName('no-priv') | 23 | >>> print bugtask.status.title |
130 | 9 | >>> login('foo.bar@canonical.com') | 24 | Won't Fix |
131 | 10 | >>> firefox.setBugSupervisor(nopriv_user, nopriv_user) | 25 | |
132 | 11 | >>> login('no-priv@canonical.com') | 26 | Regular users of Launchpad cannot transition a bug task to any of |
133 | 12 | >>> bug_params = CreateBugParams( | 27 | these statuses. |
134 | 13 | ... nopriv_user, 'Test bug', 'Something') | 28 | |
135 | 14 | >>> firefox_bug = firefox.createBug(bug_params) | 29 | An additional restraint is added to Won't Fix. Only the product |
136 | 15 | 30 | registrant or bug supervisor can change from this status to any | |
137 | 16 | Bug Supervisors can transition bugs to the Won't Fix, Expired and | 31 | other status. |
138 | 17 | Triaged statuses. | 32 | |
139 | 18 | 33 | >>> login_person(user) | |
140 | 19 | >>> [firefox_bugtask] = firefox_bug.bugtasks | 34 | >>> bugtask.transitionToStatus(BugTaskStatus.CONFIRMED, user) |
141 | 20 | >>> firefox_bugtask.transitionToStatus( | 35 | Traceback (most recent call last): |
142 | 21 | ... BugTaskStatus.WONTFIX, nopriv_user) | 36 | ... |
143 | 22 | >>> print firefox_bugtask.status.title | 37 | UserCannotEditBugTaskStatus... |
144 | 23 | Won't Fix | 38 | |
145 | 24 | 39 | This is fully tested in | |
146 | 25 | >>> firefox_bugtask.transitionToStatus( | 40 | lp.bugs.tests.test_bugtask_status.TestBugTaskStatusSetting. |
147 | 26 | ... BugTaskStatus.EXPIRED, nopriv_user) | 41 | |
148 | 27 | >>> print firefox_bugtask.status.title | 42 | Testing for Permission |
149 | 28 | Expired | 43 | ---------------------- |
52 | 29 | |||
53 | 30 | >>> firefox_bugtask.transitionToStatus( | ||
54 | 31 | ... BugTaskStatus.TRIAGED, nopriv_user) | ||
55 | 32 | >>> print firefox_bugtask.status.title | ||
56 | 33 | Triaged | ||
57 | 34 | |||
58 | 35 | The product registrant can transition to the Won't Fix, Expired and | ||
59 | 36 | Triaged statuses too. | ||
60 | 37 | |||
61 | 38 | >>> firefox_bugtask.transitionToStatus( | ||
62 | 39 | ... BugTaskStatus.CONFIRMED, nopriv_user) | ||
63 | 40 | >>> print firefox_bugtask.status.title | ||
64 | 41 | Confirmed | ||
65 | 42 | |||
66 | 43 | >>> firefox.owner.inTeam(firefox.bug_supervisor) | ||
67 | 44 | False | ||
68 | 45 | |||
69 | 46 | >>> firefox_bugtask.transitionToStatus( | ||
70 | 47 | ... BugTaskStatus.WONTFIX, firefox.owner) | ||
71 | 48 | >>> print firefox_bugtask.status.title | ||
72 | 49 | Won't Fix | ||
73 | 50 | |||
74 | 51 | >>> firefox_bugtask.transitionToStatus( | ||
75 | 52 | ... BugTaskStatus.EXPIRED, firefox.owner) | ||
76 | 53 | >>> print firefox_bugtask.status.title | ||
77 | 54 | Expired | ||
78 | 55 | |||
79 | 56 | >>> firefox_bugtask.transitionToStatus( | ||
80 | 57 | ... BugTaskStatus.TRIAGED, firefox.owner) | ||
81 | 58 | >>> print firefox_bugtask.status.title | ||
82 | 59 | Triaged | ||
83 | 60 | |||
84 | 61 | Users who are not bug supervisors or product registrants cannot | ||
85 | 62 | transition the status to Won't Fix or Triaged. The option is not | ||
86 | 63 | exposed in the UI, but we also enforce this rule at the database level | ||
87 | 64 | to ensure that all call sites adhere to this. | ||
88 | 65 | |||
89 | 66 | >>> login('foo.bar@canonical.com') | ||
90 | 67 | >>> firefox.setBugSupervisor(None, None) | ||
91 | 68 | |||
92 | 69 | >>> login('no-priv@canonical.com') | ||
93 | 70 | |||
94 | 71 | >>> firefox_bugtask.transitionToStatus( | ||
95 | 72 | ... BugTaskStatus.WONTFIX, nopriv_user) | ||
96 | 73 | Traceback (most recent call last): | ||
97 | 74 | ... | ||
98 | 75 | UserCannotEditBugTaskStatus: Only Bug Supervisors may change status to Won't Fix. | ||
99 | 76 | |||
100 | 77 | >>> firefox_bugtask.transitionToStatus( | ||
101 | 78 | ... BugTaskStatus.EXPIRED, nopriv_user) | ||
102 | 79 | Traceback (most recent call last): | ||
103 | 80 | ... | ||
104 | 81 | UserCannotEditBugTaskStatus: Only Bug Supervisors may change status to Expired. | ||
105 | 82 | |||
106 | 83 | >>> firefox_bugtask.transitionToStatus( | ||
107 | 84 | ... BugTaskStatus.TRIAGED, nopriv_user) | ||
108 | 85 | Traceback (most recent call last): | ||
109 | 86 | ... | ||
110 | 87 | UserCannotEditBugTaskStatus: Only Bug Supervisors may change status to Triaged. | ||
111 | 88 | |||
112 | 89 | Users who are not bug supervisors or product registrants cannot | ||
113 | 90 | transition the status from Won't Fix to anything else. | ||
114 | 91 | |||
115 | 92 | >>> login('foo.bar@canonical.com') | ||
116 | 93 | >>> foo_bar = getUtility(ILaunchBag).user | ||
117 | 94 | >>> firefox.setBugSupervisor(foo_bar, foo_bar) | ||
118 | 95 | >>> firefox_bugtask.transitionToStatus( | ||
119 | 96 | ... BugTaskStatus.WONTFIX, foo_bar) | ||
120 | 97 | |||
121 | 98 | >>> login('no-priv@canonical.com') | ||
122 | 99 | >>> firefox_bugtask.transitionToStatus( | ||
123 | 100 | ... BugTaskStatus.NEW, nopriv_user) | ||
124 | 101 | Traceback (most recent call last): | ||
125 | 102 | ... | ||
126 | 103 | UserCannotEditBugTaskStatus: Only Bug Supervisors may change status to New. | ||
150 | 104 | 44 | ||
151 | 105 | The method IBugTask.canTransitionToStatus comes in handy here. It | 45 | The method IBugTask.canTransitionToStatus comes in handy here. It |
152 | 106 | tells us if a transition to a status is permitted. It is *not* a | 46 | tells us if a transition to a status is permitted. It is *not* a |
173 | 107 | dry-run of transitionToStatus, but is good enough and fast enough to | 47 | dry-run of IBugTask.transitionToStatus, but is good enough and fast |
174 | 108 | be used by UI code, e.g. to display only those statuses to which a | 48 | enough to be used by UI code, e.g. to display only those statuses to |
175 | 109 | user can transition a particular bugtask. | 49 | which a user can transition a particular bugtask. |
176 | 110 | 50 | ||
177 | 111 | >>> login('foo.bar@canonical.com') | 51 | >>> bugtask.canTransitionToStatus(BugTaskStatus.TRIAGED, owner) |
158 | 112 | >>> firefox_bugtask.transitionToStatus( | ||
159 | 113 | ... BugTaskStatus.TRIAGED, foo_bar) | ||
160 | 114 | |||
161 | 115 | >>> login('no-priv@canonical.com') | ||
162 | 116 | |||
163 | 117 | >>> firefox_bugtask.canTransitionToStatus( | ||
164 | 118 | ... BugTaskStatus.WONTFIX, nopriv_user) | ||
165 | 119 | False | ||
166 | 120 | |||
167 | 121 | >>> firefox_bugtask.canTransitionToStatus( | ||
168 | 122 | ... BugTaskStatus.TRIAGED, nopriv_user) | ||
169 | 123 | False | ||
170 | 124 | |||
171 | 125 | >>> firefox_bugtask.canTransitionToStatus( | ||
172 | 126 | ... BugTaskStatus.INCOMPLETE, nopriv_user) | ||
178 | 127 | True | 52 | True |
188 | 128 | 53 | >>> bugtask.canTransitionToStatus(BugTaskStatus.TRIAGED, user) | |
180 | 129 | >>> login('foo.bar@canonical.com') | ||
181 | 130 | >>> firefox_bugtask.transitionToStatus( | ||
182 | 131 | ... BugTaskStatus.WONTFIX, getUtility(ILaunchBag).user) | ||
183 | 132 | |||
184 | 133 | >>> login('no-priv@canonical.com') | ||
185 | 134 | |||
186 | 135 | >>> firefox_bugtask.canTransitionToStatus( | ||
187 | 136 | ... BugTaskStatus.NEW, nopriv_user) | ||
189 | 137 | False | 54 | False |
190 | 55 | |||
191 | 56 | This method is fully tested in | ||
192 | 57 | lp.bugs.tests.test_bugtask_status.TestCanTransitionToStatus. | ||
193 | 138 | 58 | ||
194 | === modified file 'lib/lp/bugs/tests/test_bugtask_status.py' | |||
195 | --- lib/lp/bugs/tests/test_bugtask_status.py 2010-10-04 19:50:45 +0000 | |||
196 | +++ lib/lp/bugs/tests/test_bugtask_status.py 2010-10-19 13:36:54 +0000 | |||
197 | @@ -1,22 +1,322 @@ | |||
198 | 1 | # Copyright 2009 Canonical Ltd. This software is licensed under the | 1 | # Copyright 2009 Canonical Ltd. This software is licensed under the |
199 | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). |
200 | 3 | 3 | ||
202 | 4 | """Test for choosing the request and publication.""" | 4 | """Tests for bug task status transitions.""" |
203 | 5 | 5 | ||
204 | 6 | __metaclass__ = type | 6 | __metaclass__ = type |
205 | 7 | 7 | ||
210 | 8 | from canonical.launchpad.testing.systemdocs import ( | 8 | from zope.component import getUtility |
211 | 9 | LayeredDocFileSuite, | 9 | from zope.security.proxy import removeSecurityProxy |
212 | 10 | setUp, | 10 | |
213 | 11 | tearDown, | 11 | from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities |
214 | 12 | from canonical.testing.layers import LaunchpadFunctionalLayer | ||
215 | 13 | from lp.bugs.interfaces.bugtask import UserCannotEditBugTaskStatus | ||
216 | 14 | from lp.bugs.model.bugtask import BugTaskStatus | ||
217 | 15 | from lp.testing import ( | ||
218 | 16 | person_logged_in, | ||
219 | 17 | TestCaseWithFactory, | ||
220 | 12 | ) | 18 | ) |
231 | 13 | from canonical.testing.layers import LaunchpadFunctionalLayer | 19 | |
232 | 14 | 20 | ||
233 | 15 | 21 | class TestBugTaskStatusTransitionForUser(TestCaseWithFactory): | |
234 | 16 | def test_suite(): | 22 | """Test bugtask status transitions for a regular logged in user.""" |
235 | 17 | suite = LayeredDocFileSuite( | 23 | |
236 | 18 | 'test_bugtask_status.txt', | 24 | layer = LaunchpadFunctionalLayer |
237 | 19 | layer=LaunchpadFunctionalLayer, setUp=setUp, tearDown=tearDown, | 25 | |
238 | 20 | ) | 26 | def setUp(self): |
239 | 21 | return suite | 27 | super(TestBugTaskStatusTransitionForUser, self).setUp() |
240 | 22 | 28 | self.user = self.factory.makePerson() | |
241 | 29 | self.task = self.factory.makeBugTask() | ||
242 | 30 | |||
243 | 31 | def test_user_transition_all_statuses(self): | ||
244 | 32 | # A regular user should not be able to set statuses in | ||
245 | 33 | # BUG_SUPERVISOR_BUGTASK_STATUSES, but can set any | ||
246 | 34 | # other status. | ||
247 | 35 | self.assertEqual(self.task.status, BugTaskStatus.NEW) | ||
248 | 36 | with person_logged_in(self.user): | ||
249 | 37 | self.assertRaises( | ||
250 | 38 | UserCannotEditBugTaskStatus, self.task.transitionToStatus, | ||
251 | 39 | BugTaskStatus.WONTFIX, self.user) | ||
252 | 40 | self.assertRaises( | ||
253 | 41 | UserCannotEditBugTaskStatus, self.task.transitionToStatus, | ||
254 | 42 | BugTaskStatus.EXPIRED, self.user) | ||
255 | 43 | self.assertRaises( | ||
256 | 44 | UserCannotEditBugTaskStatus, self.task.transitionToStatus, | ||
257 | 45 | BugTaskStatus.TRIAGED, self.user) | ||
258 | 46 | self.task.transitionToStatus(BugTaskStatus.NEW, self.user) | ||
259 | 47 | self.assertEqual(self.task.status, BugTaskStatus.NEW) | ||
260 | 48 | self.task.transitionToStatus( | ||
261 | 49 | BugTaskStatus.INCOMPLETE, self.user) | ||
262 | 50 | self.assertEqual(self.task.status, BugTaskStatus.INCOMPLETE) | ||
263 | 51 | self.task.transitionToStatus(BugTaskStatus.OPINION, self.user) | ||
264 | 52 | self.assertEqual(self.task.status, BugTaskStatus.OPINION) | ||
265 | 53 | self.task.transitionToStatus(BugTaskStatus.INVALID, self.user) | ||
266 | 54 | self.assertEqual(self.task.status, BugTaskStatus.INVALID) | ||
267 | 55 | self.task.transitionToStatus(BugTaskStatus.CONFIRMED, self.user) | ||
268 | 56 | self.assertEqual(self.task.status, BugTaskStatus.CONFIRMED) | ||
269 | 57 | self.task.transitionToStatus( | ||
270 | 58 | BugTaskStatus.INPROGRESS, self.user) | ||
271 | 59 | self.assertEqual(self.task.status, BugTaskStatus.INPROGRESS) | ||
272 | 60 | self.task.transitionToStatus( | ||
273 | 61 | BugTaskStatus.FIXCOMMITTED, self.user) | ||
274 | 62 | self.assertEqual(self.task.status, BugTaskStatus.FIXCOMMITTED) | ||
275 | 63 | self.task.transitionToStatus( | ||
276 | 64 | BugTaskStatus.FIXRELEASED, self.user) | ||
277 | 65 | self.assertEqual(self.task.status, BugTaskStatus.FIXRELEASED) | ||
278 | 66 | |||
279 | 67 | def test_user_cannot_unset_wont_fix_status(self): | ||
280 | 68 | # A regular user should not be able to transition a bug away | ||
281 | 69 | # from Won't Fix. | ||
282 | 70 | removeSecurityProxy(self.task).status = BugTaskStatus.WONTFIX | ||
283 | 71 | with person_logged_in(self.user): | ||
284 | 72 | self.assertRaises( | ||
285 | 73 | UserCannotEditBugTaskStatus, self.task.transitionToStatus, | ||
286 | 74 | BugTaskStatus.CONFIRMED, self.user) | ||
287 | 75 | |||
288 | 76 | def test_user_canTransitionToStatus(self): | ||
289 | 77 | # Regular user cannot transition to BUG_SUPERVISOR_BUGTASK_STATUSES, | ||
290 | 78 | # but can transition to any other status. | ||
291 | 79 | self.assertEqual( | ||
292 | 80 | self.task.canTransitionToStatus( | ||
293 | 81 | BugTaskStatus.WONTFIX, self.user), | ||
294 | 82 | False) | ||
295 | 83 | self.assertEqual( | ||
296 | 84 | self.task.canTransitionToStatus( | ||
297 | 85 | BugTaskStatus.EXPIRED, self.user), | ||
298 | 86 | False) | ||
299 | 87 | self.assertEqual( | ||
300 | 88 | self.task.canTransitionToStatus( | ||
301 | 89 | BugTaskStatus.TRIAGED, self.user), | ||
302 | 90 | False) | ||
303 | 91 | self.assertEqual( | ||
304 | 92 | self.task.canTransitionToStatus( | ||
305 | 93 | BugTaskStatus.NEW, self.user), | ||
306 | 94 | True) | ||
307 | 95 | self.assertEqual( | ||
308 | 96 | self.task.canTransitionToStatus( | ||
309 | 97 | BugTaskStatus.INCOMPLETE, self.user), True) | ||
310 | 98 | self.assertEqual( | ||
311 | 99 | self.task.canTransitionToStatus( | ||
312 | 100 | BugTaskStatus.OPINION, self.user), | ||
313 | 101 | True) | ||
314 | 102 | self.assertEqual( | ||
315 | 103 | self.task.canTransitionToStatus( | ||
316 | 104 | BugTaskStatus.INVALID, self.user), | ||
317 | 105 | True) | ||
318 | 106 | self.assertEqual( | ||
319 | 107 | self.task.canTransitionToStatus( | ||
320 | 108 | BugTaskStatus.CONFIRMED, self.user), | ||
321 | 109 | True) | ||
322 | 110 | self.assertEqual( | ||
323 | 111 | self.task.canTransitionToStatus( | ||
324 | 112 | BugTaskStatus.INPROGRESS, self.user), | ||
325 | 113 | True) | ||
326 | 114 | self.assertEqual( | ||
327 | 115 | self.task.canTransitionToStatus( | ||
328 | 116 | BugTaskStatus.FIXCOMMITTED, self.user), | ||
329 | 117 | True) | ||
330 | 118 | self.assertEqual( | ||
331 | 119 | self.task.canTransitionToStatus( | ||
332 | 120 | BugTaskStatus.FIXRELEASED, self.user), | ||
333 | 121 | True) | ||
334 | 122 | |||
335 | 123 | def test_user_canTransitionToStatus_from_wontfix(self): | ||
336 | 124 | # A regular user cannot transition away from Won't Fix, | ||
337 | 125 | # so canTransitionToStatus should return False. | ||
338 | 126 | removeSecurityProxy(self.task).status = BugTaskStatus.WONTFIX | ||
339 | 127 | self.assertEqual( | ||
340 | 128 | self.task.canTransitionToStatus( | ||
341 | 129 | BugTaskStatus.NEW, self.user), | ||
342 | 130 | False) | ||
343 | 131 | |||
344 | 132 | |||
345 | 133 | class TestBugTaskStatusTransitionForPrivilegedUserBase: | ||
346 | 134 | """Base class used to test privileged users and status transitions.""" | ||
347 | 135 | |||
348 | 136 | layer = LaunchpadFunctionalLayer | ||
349 | 137 | |||
350 | 138 | def setUp(self): | ||
351 | 139 | super(TestBugTaskStatusTransitionForPrivilegedUserBase, self).setUp() | ||
352 | 140 | # Creation of task and target are deferred to subclasses. | ||
353 | 141 | self.task = None | ||
354 | 142 | self.person = None | ||
355 | 143 | self.makePersonAndTask() | ||
356 | 144 | |||
357 | 145 | def makePersonAndTask(self): | ||
358 | 146 | """Create a bug task and privileged person for this task. | ||
359 | 147 | |||
360 | 148 | This method is implemented by subclasses to correctly setup | ||
361 | 149 | each test. | ||
362 | 150 | """ | ||
363 | 151 | raise NotImplementedError(self.makePersonAndTask) | ||
364 | 152 | |||
365 | 153 | def test_privileged_user_transition_any_status(self): | ||
366 | 154 | # Privileged users (like owner or bug supervisor) should | ||
367 | 155 | # be able to set any status. | ||
368 | 156 | with person_logged_in(self.person): | ||
369 | 157 | self.task.transitionToStatus(BugTaskStatus.WONTFIX, self.person) | ||
370 | 158 | self.assertEqual(self.task.status, BugTaskStatus.WONTFIX) | ||
371 | 159 | self.task.transitionToStatus(BugTaskStatus.EXPIRED, self.person) | ||
372 | 160 | self.assertEqual(self.task.status, BugTaskStatus.EXPIRED) | ||
373 | 161 | self.task.transitionToStatus(BugTaskStatus.TRIAGED, self.person) | ||
374 | 162 | self.assertEqual(self.task.status, BugTaskStatus.TRIAGED) | ||
375 | 163 | self.task.transitionToStatus(BugTaskStatus.NEW, self.person) | ||
376 | 164 | self.assertEqual(self.task.status, BugTaskStatus.NEW) | ||
377 | 165 | self.task.transitionToStatus( | ||
378 | 166 | BugTaskStatus.INCOMPLETE, self.person) | ||
379 | 167 | self.assertEqual(self.task.status, BugTaskStatus.INCOMPLETE) | ||
380 | 168 | self.task.transitionToStatus(BugTaskStatus.OPINION, self.person) | ||
381 | 169 | self.assertEqual(self.task.status, BugTaskStatus.OPINION) | ||
382 | 170 | self.task.transitionToStatus(BugTaskStatus.INVALID, self.person) | ||
383 | 171 | self.assertEqual(self.task.status, BugTaskStatus.INVALID) | ||
384 | 172 | self.task.transitionToStatus(BugTaskStatus.CONFIRMED, self.person) | ||
385 | 173 | self.assertEqual(self.task.status, BugTaskStatus.CONFIRMED) | ||
386 | 174 | self.task.transitionToStatus( | ||
387 | 175 | BugTaskStatus.INPROGRESS, self.person) | ||
388 | 176 | self.assertEqual(self.task.status, BugTaskStatus.INPROGRESS) | ||
389 | 177 | self.task.transitionToStatus( | ||
390 | 178 | BugTaskStatus.FIXCOMMITTED, self.person) | ||
391 | 179 | self.assertEqual(self.task.status, BugTaskStatus.FIXCOMMITTED) | ||
392 | 180 | self.task.transitionToStatus( | ||
393 | 181 | BugTaskStatus.FIXRELEASED, self.person) | ||
394 | 182 | self.assertEqual(self.task.status, BugTaskStatus.FIXRELEASED) | ||
395 | 183 | |||
396 | 184 | def test_privileged_user_can_unset_wont_fix_status(self): | ||
397 | 185 | # Privileged users can transition away from Won't Fix. | ||
398 | 186 | removeSecurityProxy(self.task).status = BugTaskStatus.WONTFIX | ||
399 | 187 | with person_logged_in(self.person): | ||
400 | 188 | self.task.transitionToStatus(BugTaskStatus.CONFIRMED, self.person) | ||
401 | 189 | self.assertEqual(self.task.status, BugTaskStatus.CONFIRMED) | ||
402 | 190 | |||
403 | 191 | def test_privileged_user_canTransitionToStatus(self): | ||
404 | 192 | # Privileged users (like owner or bug supervisor) should | ||
405 | 193 | # be able to set any status, so canTransitionToStatus should | ||
406 | 194 | # always return True. | ||
407 | 195 | self.assertEqual( | ||
408 | 196 | self.task.canTransitionToStatus( | ||
409 | 197 | BugTaskStatus.WONTFIX, self.person), | ||
410 | 198 | True) | ||
411 | 199 | self.assertEqual( | ||
412 | 200 | self.task.canTransitionToStatus( | ||
413 | 201 | BugTaskStatus.EXPIRED, self.person), | ||
414 | 202 | True) | ||
415 | 203 | self.assertEqual( | ||
416 | 204 | self.task.canTransitionToStatus( | ||
417 | 205 | BugTaskStatus.TRIAGED, self.person), | ||
418 | 206 | True) | ||
419 | 207 | self.assertEqual( | ||
420 | 208 | self.task.canTransitionToStatus( | ||
421 | 209 | BugTaskStatus.NEW, self.person), | ||
422 | 210 | True) | ||
423 | 211 | self.assertEqual( | ||
424 | 212 | self.task.canTransitionToStatus( | ||
425 | 213 | BugTaskStatus.INCOMPLETE, self.person), | ||
426 | 214 | True) | ||
427 | 215 | self.assertEqual( | ||
428 | 216 | self.task.canTransitionToStatus( | ||
429 | 217 | BugTaskStatus.OPINION, self.person), | ||
430 | 218 | True) | ||
431 | 219 | self.assertEqual( | ||
432 | 220 | self.task.canTransitionToStatus( | ||
433 | 221 | BugTaskStatus.INVALID, self.person), | ||
434 | 222 | True) | ||
435 | 223 | self.assertEqual( | ||
436 | 224 | self.task.canTransitionToStatus( | ||
437 | 225 | BugTaskStatus.CONFIRMED, self.person), | ||
438 | 226 | True) | ||
439 | 227 | self.assertEqual( | ||
440 | 228 | self.task.canTransitionToStatus( | ||
441 | 229 | BugTaskStatus.INPROGRESS, self.person), | ||
442 | 230 | True) | ||
443 | 231 | self.assertEqual( | ||
444 | 232 | self.task.canTransitionToStatus( | ||
445 | 233 | BugTaskStatus.FIXCOMMITTED, self.person), | ||
446 | 234 | True) | ||
447 | 235 | self.assertEqual( | ||
448 | 236 | self.task.canTransitionToStatus( | ||
449 | 237 | BugTaskStatus.FIXRELEASED, self.person), | ||
450 | 238 | True) | ||
451 | 239 | |||
452 | 240 | def test_privileged_user_canTransitionToStatus_from_wontfix(self): | ||
453 | 241 | # A privileged user can transition away from Won't Fix, so | ||
454 | 242 | # canTransitionToStatus should return True. | ||
455 | 243 | removeSecurityProxy(self.task).status = BugTaskStatus.WONTFIX | ||
456 | 244 | self.assertEqual( | ||
457 | 245 | self.task.canTransitionToStatus( | ||
458 | 246 | BugTaskStatus.NEW, self.person), | ||
459 | 247 | True) | ||
460 | 248 | |||
461 | 249 | |||
462 | 250 | class TestBugTaskStatusTransitionOwnerPerson( | ||
463 | 251 | TestBugTaskStatusTransitionForPrivilegedUserBase, TestCaseWithFactory): | ||
464 | 252 | """Tests to ensure owner person can transition to any status..""" | ||
465 | 253 | |||
466 | 254 | def makePersonAndTask(self): | ||
467 | 255 | self.person = self.factory.makePerson() | ||
468 | 256 | self.product = self.factory.makeProduct(owner=self.person) | ||
469 | 257 | self.task = self.factory.makeBugTask(target=self.product) | ||
470 | 258 | |||
471 | 259 | |||
472 | 260 | class TestBugTaskStatusTransitionOwnerTeam( | ||
473 | 261 | TestBugTaskStatusTransitionForPrivilegedUserBase, TestCaseWithFactory): | ||
474 | 262 | """Tests to ensure owner team can transition to any status..""" | ||
475 | 263 | |||
476 | 264 | def makePersonAndTask(self): | ||
477 | 265 | self.person = self.factory.makePerson() | ||
478 | 266 | self.team = self.factory.makeTeam(members=[self.person]) | ||
479 | 267 | self.product = self.factory.makeProduct(owner=self.team) | ||
480 | 268 | self.task = self.factory.makeBugTask(target=self.product) | ||
481 | 269 | |||
482 | 270 | |||
483 | 271 | class TestBugTaskStatusTransitionBugSupervisorPerson( | ||
484 | 272 | TestBugTaskStatusTransitionForPrivilegedUserBase, TestCaseWithFactory): | ||
485 | 273 | """Tests to ensure bug supervisor person can transition to any status.""" | ||
486 | 274 | |||
487 | 275 | def makePersonAndTask(self): | ||
488 | 276 | self.owner = self.factory.makePerson() | ||
489 | 277 | self.person = self.factory.makePerson() | ||
490 | 278 | self.product = self.factory.makeProduct(owner=self.owner) | ||
491 | 279 | self.task = self.factory.makeBugTask(target=self.product) | ||
492 | 280 | with person_logged_in(self.owner): | ||
493 | 281 | self.product.setBugSupervisor(self.person, self.person) | ||
494 | 282 | |||
495 | 283 | |||
496 | 284 | class TestBugTaskStatusTransitionBugSupervisorTeamMember( | ||
497 | 285 | TestBugTaskStatusTransitionForPrivilegedUserBase, TestCaseWithFactory): | ||
498 | 286 | """Tests to ensure bug supervisor team can transition to any status.""" | ||
499 | 287 | |||
500 | 288 | def makePersonAndTask(self): | ||
501 | 289 | self.owner = self.factory.makePerson() | ||
502 | 290 | self.person = self.factory.makePerson() | ||
503 | 291 | self.team = self.factory.makeTeam(members=[self.person]) | ||
504 | 292 | self.product = self.factory.makeProduct(owner=self.owner) | ||
505 | 293 | self.task = self.factory.makeBugTask(target=self.product) | ||
506 | 294 | with person_logged_in(self.owner): | ||
507 | 295 | self.product.setBugSupervisor(self.team, self.team) | ||
508 | 296 | |||
509 | 297 | |||
510 | 298 | class TestBugTaskStatusTransitionBugWatchUpdater( | ||
511 | 299 | TestBugTaskStatusTransitionForPrivilegedUserBase, TestCaseWithFactory): | ||
512 | 300 | """Tests to ensure bug_watch_updater can transition to any status.""" | ||
513 | 301 | |||
514 | 302 | def makePersonAndTask(self): | ||
515 | 303 | self.person = getUtility(ILaunchpadCelebrities).bug_watch_updater | ||
516 | 304 | self.task = self.factory.makeBugTask() | ||
517 | 305 | |||
518 | 306 | |||
519 | 307 | class TestBugTaskStatusTransitionBugImporter( | ||
520 | 308 | TestBugTaskStatusTransitionForPrivilegedUserBase, TestCaseWithFactory): | ||
521 | 309 | """Tests to ensure bug_importer can transition to any status.""" | ||
522 | 310 | |||
523 | 311 | def makePersonAndTask(self): | ||
524 | 312 | self.person = getUtility(ILaunchpadCelebrities).bug_importer | ||
525 | 313 | self.task = self.factory.makeBugTask() | ||
526 | 314 | |||
527 | 315 | |||
528 | 316 | class TestBugTaskStatusTransitionJanitor( | ||
529 | 317 | TestBugTaskStatusTransitionForPrivilegedUserBase, TestCaseWithFactory): | ||
530 | 318 | """Tests to ensure lp janitor can transition to any status.""" | ||
531 | 319 | |||
532 | 320 | def makePersonAndTask(self): | ||
533 | 321 | self.person = getUtility(ILaunchpadCelebrities).janitor | ||
534 | 322 | self.task = self.factory.makeBugTask() |
(17:52:07) adeuring: deryck: I think it might make sense to change the test setup so that the product owner is not a member of the bug supervisor team; right now, the term "or user.inTeam( pillar. owner)" in canTransitionTo Status( ) is not executed bug_watch_ updater, celebrities. bug_importer, celebrities. janitor. You could add these tests quickly by definig a base class for tests of "extended permissions", where you do not define the user who is tested, then derive the "real" test classes for supervisor, owner and the celebrities.
(17:52:53) deryck: adeuring, ok, that's a good idea. I can do that.
(17:53:07) adeuring: deryck: thanks! another suggestion, before you start ;)
(17:53:16) deryck: sure
(17:55:28) salgado heißt jetzt salgado-lunch
(17:55:30) adeuring: deryck: you don't test at all for celebrities.
(17:55:45) adeuring: That should make the tests a bit shorter and more comprehensive
(17:57:44) deryck: sure, I like that idea. I can do that, too.
(17:57:59) adeuring: deryck: cool, thanks!