1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import unittest
16
17 import trac.tests.compat
18 from trac.tests.functional import FunctionalTwillTestCaseSetup, tc
19
20
22
33
40
42 """When using the workflow operation `set_owner`, the assign-to field
43 will default to the currently requesting username.
44 """
45 ticket_id = self._tester.create_ticket(self.__class__.__name__,
46 info={'owner': 'lammy'})
47 self._tester.go_to_ticket(ticket_id)
48 tc.find('The owner will be changed from '
49 '<span class="trac-author">lammy</span>')
50 tc.find('<input type="text" name="action_reassign_reassign_owner" '
51 'value="admin" id="action_reassign_reassign_owner" />')
52
54 """When using the workflow operation `set_owner` with
55 restrict_owner=true, the assign-to dropdown menu will not contain the
56 requesting user, if the requesting user is not a known user.
57 """
58 try:
59 ticket_id = self._tester.create_ticket(self.__class__.__name__,
60 info={'owner': 'lammy'})
61 self.env.config.set('ticket', 'restrict_owner', True)
62 self.env.config.save()
63 self._tester.logout()
64 self._testenv.grant_perm('anonymous', 'TICKET_ADMIN')
65
66 self._tester.go_to_ticket(ticket_id)
67 tc.find('The owner will be changed from '
68 '<span class="trac-author">lammy</span>')
69 tc.notfind('<option value="anonymous" selected="selected">'
70 'anonymous</option>')
71
72 finally:
73 self._testenv.revoke_perm('anonymous', 'TICKET_ADMIN')
74 self._tester.login('admin')
75
77 """When using the workflow operation `set_owner` with
78 a specific list of available owners, the assign-to field
79 will only contain that list of owners. The requesting user
80 will not be added to the list, and the current ticket owner
81 will not be added to the list.
82 """
83 try:
84 ticket_id = self._tester.create_ticket(self.__class__.__name__,
85 info={'owner': 'lammy'})
86 self.env.config.set('ticket-workflow', 'reassign.set_owner',
87 "alice,bill")
88 self.env.config.save()
89
90 self._tester.go_to_ticket(ticket_id)
91 tc.find('The owner will be changed from '
92 '<span class="trac-author">lammy</span>')
93
94 tc.notfind('<input type="text" name="action_reassign_reassign_owner" '
95 'value="admin" id="action_reassign_reassign_owner" />')
96 tc.notfind('<option selected="selected" value="admin">admin</option>')
97 tc.notfind('<option value="admin">admin</option>')
98
99 tc.notfind('<input type="text" name="action_reassign_reassign_owner" '
100 'value="lammy" id="action_reassign_reassign_owner" />')
101 tc.notfind('<option selected="selected" value="lammy">lammy</option>')
102 tc.notfind('<option value="lammy">lammy</option>')
103
104 finally:
105 self.env.config.remove('ticket-workflow', 'reassign.set_owner')
106
108 """When using the workflow operation `set_owner` with
109 a specific single-element list of available owners, the assign-to field
110 will not give the end user any choices at all.
111 """
112 try:
113 ticket_id = self._tester.create_ticket(self.__class__.__name__,
114 info={'owner': 'lammy'})
115 self.env.config.set('ticket-workflow', 'reassign.set_owner',
116 "alice")
117 self.env.config.save()
118
119 self._tester.go_to_ticket(ticket_id)
120
121 tc.notfind('<select name="action_reassign_reassign_owner"')
122 tc.find('<input type="hidden" '
123 'name="action_reassign_reassign_owner" '
124 'value="alice" id="action_reassign_reassign_owner" />')
125 tc.find('The owner will be changed from '
126 '<span class="trac-author">lammy</span> to '
127 '<span class="trac-author">alice</span>')
128
129 tc.notfind('<input type="text" name="action_reassign_reassign_owner" '
130 'value="admin" id="action_reassign_reassign_owner" />')
131 tc.notfind('<option selected="selected" value="admin">admin</option>')
132 tc.notfind('<option value="admin">admin</option>')
133
134 tc.notfind('<input type="text" name="action_reassign_reassign_owner" '
135 'value="lammy" id="action_reassign_reassign_owner" />')
136 tc.notfind('<option selected="selected" value="lammy">lammy</option>')
137 tc.notfind('<option value="lammy">lammy</option>')
138
139 finally:
140 self.env.config.remove('ticket-workflow', 'reassign.set_owner')
141
142
144 """Test cases for may_set_owner operation with
145 `[ticket] restrict_owner = False`
146 https://trac.edgewall.org/ticket/10018
147 """
158
165
167 """The assign-to field will default to the ticket's current owner.
168 """
169 ticket_id = self._tester.create_ticket(self.__class__.__name__,
170 info={'owner': 'lammy'})
171 self._tester.go_to_ticket(ticket_id)
172 tc.find('The owner will be changed from '
173 '<span class="trac-author">lammy</span>')
174 tc.find('<input type="text" name="action_reassign_reassign_owner"'
175 ' value="lammy" id="action_reassign_reassign_owner" />')
176
178 """The assign-to field will default to a blank field if the ticket
179 currently has no owner.
180 """
181 ticket_id = self._tester.create_ticket(self.__class__.__name__,
182 info={'owner': ''})
183 self._tester.go_to_ticket(ticket_id)
184 tc.find("The ticket will remain with no owner.")
185 tc.find('The owner will be changed from '
186 '<span class="trac-author-none">\(none\)</span>')
187 tc.find('<input type="text" name="action_reassign_reassign_owner"'
188 ' id="action_reassign_reassign_owner" />')
189
191 """The assign-to field will default to the ticket's current owner
192 even if the current owner is not otherwise known to the Trac
193 environment."""
194 ticket_id = self._tester.create_ticket(self.__class__.__name__,
195 info={'owner': 'lammy'})
196 self.env.config.set('ticket', 'restrict_owner', True)
197 self.env.config.save()
198 self._tester.go_to_ticket(ticket_id)
199 tc.find('The owner will be changed from '
200 '<span class="trac-author">lammy</span>')
201 tc.find('<option selected="selected" value="lammy">'
202 'lammy</option>')
203
204 known_usernames = [u[0] for u in self.env.get_known_users()]
205 self.assertNotIn('lammy', known_usernames)
206
208 """When using the workflow operation `may_set_owner` with
209 a specific list of available owners, the assign-to field
210 will only contain that list of owners. The requesting user
211 will not be added to the list. But the current ticket owner
212 will be added to the list, and will be the default choice.
213 """
214 try:
215 ticket_id = self._tester.create_ticket(self.__class__.__name__,
216 info={'owner': 'lammy'})
217 self.env.config.set('ticket-workflow', 'reassign.set_owner',
218 "alice,bill")
219 self.env.config.save()
220
221 self._tester.go_to_ticket(ticket_id)
222 tc.find('The owner will be changed from '
223 '<span class="trac-author">lammy</span>')
224
225 tc.notfind('<input type="text" name="action_reassign_reassign_owner" '
226 'value="admin" id="action_reassign_reassign_owner" />')
227 tc.find('<option selected="selected" value="lammy">lammy</option>')
228 tc.find('<option value="alice">alice</option>')
229 tc.find('<option value="bill">bill</option>')
230
231 tc.notfind('<input type="text" name="action_reassign_reassign_owner" '
232 'value="admin" id="action_reassign_reassign_owner" />')
233 tc.notfind('<option selected="selected" value="admin">admin</option>')
234 tc.notfind('<option value="admin">admin</option>')
235
236 finally:
237 self.env.config.remove('ticket-workflow', 'reassign.set_owner')
238
240 """When using the workflow operation `may_set_owner` with
241 a specific single-element list of available owners, the assign-to field
242 will become a dropdown with two options if the current owner is not
243 the single specified option. It will be a text field, and will not give
244 the end user any choices at all, if and only if the current owner
245 is the single specified option.
246 """
247 try:
248 ticket_id = self._tester.create_ticket(self.__class__.__name__,
249 info={'owner': 'lammy'})
250 self.env.config.set('ticket-workflow', 'reassign.set_owner',
251 "alice")
252 self.env.config.save()
253
254 self._tester.go_to_ticket(ticket_id)
255 tc.find('The owner will be changed from '
256 '<span class="trac-author">lammy</span>')
257
258 tc.find('<select name="action_reassign_reassign_owner"')
259 tc.notfind('<input type="hidden" '
260 'name="action_reassign_reassign_owner" '
261 'value="alice" id="action_reassign_reassign_owner" />')
262 tc.notfind('The owner will be changed from '
263 '<span class="trac-author">lammy<span> to '
264 '<span class="trac-author">alice</span>')
265 tc.find('<option selected="selected" value="lammy">lammy</option>')
266 tc.find('<option value="alice">alice</option>')
267
268 self.env.config.set('ticket-workflow', 'reassign.set_owner',
269 "lammy")
270 self.env.config.save()
271
272 self._tester.go_to_ticket(ticket_id)
273
274 tc.notfind('<select name="action_reassign_reassign_owner"')
275 tc.find('<input type="hidden" '
276 'name="action_reassign_reassign_owner" '
277 'value="lammy" id="action_reassign_reassign_owner" />')
278 tc.find('The owner will remain '
279 '<span class="trac-author">lammy</span>')
280 tc.notfind('<option selected="selected" value="lammy">lammy</option>')
281
282
283 finally:
284 self.env.config.remove('ticket-workflow', 'reassign.set_owner')
285
286
287
290 """When using the workflow operation `may_set_owner` with
291 restrict_owner=true, the assign-to field will default to an empty
292 option labeled (none) if the ticket currently has no owner.
293 """
294 env = self._testenv.get_trac_environment()
295 reassign_operations = env.config.get('ticket-workflow',
296 'reassign.operations')
297 env.config.set('ticket-workflow', 'reassign.operations',
298 'may_set_owner')
299 env.config.save()
300
301 try:
302 ticket_id = self._tester.create_ticket(self.__class__.__name__,
303 info={'owner': ''})
304 restrict_owner = env.config.get('ticket', 'restrict_owner')
305 env.config.set('ticket', 'restrict_owner', True)
306 env.config.save()
307
308 self._tester.go_to_ticket(ticket_id)
309 tc.find("The ticket will remain with no owner.")
310 tc.find('The owner will be changed from '
311 '<span class="trac-author-none">\(none\)</span>')
312 tc.find('<option selected="selected" value="">\(none\)</option>')
313 finally:
314 env.config.set('ticket-workflow', 'reassign.operations',
315 reassign_operations)
316 env.config.set('ticket', 'restrict_owner', restrict_owner)
317 env.config.save()
318
319
322 """When using the workflow operation `may_set_owner` with
323 restrict_owner=true, the assign-to dropdown menu will contain a
324 selected option "anonymous" if the ticket is owned by "anonymous".
325 """
326 env = self._testenv.get_trac_environment()
327 reassign_operations = env.config.get('ticket-workflow',
328 'reassign.operations')
329 env.config.set('ticket-workflow', 'reassign.operations',
330 'may_set_owner')
331 restrict_owner = env.config.get('ticket', 'restrict_owner')
332 env.config.set('ticket', 'restrict_owner', False)
333 env.config.save()
334
335 try:
336 ticket_id = \
337 self._tester.create_ticket(self.__class__.__name__,
338 info={'owner': 'anonymous'})
339 env.config.set('ticket', 'restrict_owner', True)
340 env.config.save()
341 self._tester.logout()
342 self._testenv.grant_perm('anonymous', 'TICKET_ADMIN')
343
344 self._tester.go_to_ticket(ticket_id)
345 tc.find('The owner will be changed from '
346 '<span class="trac-author-anonymous">anonymous</span>')
347 tc.find('<option selected="selected" value="anonymous">'
348 'anonymous</option>')
349
350 finally:
351 self._testenv.revoke_perm('anonymous', 'TICKET_ADMIN')
352 self._tester.login('admin')
353 env.config.set('ticket-workflow', 'reassign.operations',
354 reassign_operations)
355 env.config.set('ticket', 'restrict_owner', restrict_owner)
356 env.config.save()
357
358
361 """Test for regression of https://trac.edgewall.org/ticket/11930
362 Workflow action labels are present on the ticket page.
363 """
364 self._tester.create_ticket()
365 tc.find('<label for="action_leave">leave</label>[ \n\t]+as new')
366 tc.find('<label for="action_resolve">resolve</label>[ \n\t]+as')
367 tc.find('<label for="action_reassign">reassign</label>[ \n\t]+to')
368 tc.find('<label for="action_accept">accept</label>')
369
370
386
387
401
402
403 test_suite = functionalSuite
404
405
406 if __name__ == '__main__':
407 unittest.main(defaultTest='test_suite')
408