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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
Edit a bug watch
================
After a bug watch is recorded, it is possible to go back and change it.
>>> admin_browser.open('http://bugs.launchpad.dev/bugs/1/+watch/2')
>>> admin_browser.getControl('URL').value = (
... 'https://bugzilla.mozilla.org/show_bug.cgi?id=1000')
>>> admin_browser.getControl('Change').click()
>>> admin_browser.url
'http://bugs.launchpad.dev/firefox/+bug/1'
>>> 'https://bugzilla.mozilla.org/show_bug.cgi?id=1000' in (
... admin_browser.contents)
True
The URL supplied must be a valid bug tracker URL and must point to a
bug tracker already registered with Launchpad.
>>> admin_browser.open('http://bugs.launchpad.dev/bugs/1/+watch/2')
>>> admin_browser.getControl('URL').value = (
... 'https://bugzilla.mozilla.org/foo_bug.cgi?id=1000')
>>> admin_browser.getControl('Change').click()
>>> admin_browser.url
'http://bugs.launchpad.dev/bugs/1/+watch/2/+edit'
>>> for message in find_tags_by_class(admin_browser.contents, 'message'):
... print extract_text(message)
There is 1 error.
Invalid bug tracker URL.
Likewise, stupid URLs are rejected with a polite error message.
>>> admin_browser.getControl('URL').value = 'GELLER'
>>> admin_browser.getControl('Change').click()
>>> admin_browser.url
'http://bugs.launchpad.dev/bugs/1/+watch/2/+edit'
>>> for message in find_tags_by_class(admin_browser.contents, 'message'):
... print extract_text(message)
There is 1 error.
"GELLER" is not a valid URI
BugWatch details
----------------
The +edit page for a watch also displays some details about the watch.
>>> for data_tag in find_tags_by_class(
... admin_browser.contents, 'bugwatch-data'):
... print extract_text(data_tag.renderContents())
Tracker: The Mozilla.org Bug Tracker
Remote bug ID: 1000
Last status: None recorded
Changed: 2004-10-04
Checked: 2004-10-04
Next check: Not yet scheduled
Created: 2004-10-04
Created by: Mark Shuttleworth
If we change the next_check date of the watch its will be shown in the
Next check column.
>>> from zope.component import getUtility
>>> from datetime import datetime
>>> from pytz import utc
>>> from canonical.launchpad.ftests import login, logout
>>> from lp.bugs.interfaces.bugwatch import IBugWatchSet
>>> login('foo.bar@canonical.com')
>>> watch = getUtility(IBugWatchSet).get(2)
>>> watch.next_check = datetime(2010, 4, 8, 16, 07, tzinfo=utc)
>>> logout()
>>> admin_browser.open('http://bugs.launchpad.dev/bugs/1/+watch/2')
>>> data_tag = find_tag_by_id(
... admin_browser.contents, 'bugwatch-next_check')
>>> print extract_text(data_tag.renderContents())
Next check: 2010-04-08...
Recent activity
---------------
Recent activity on a bug watch is shown on the page as a list of
activity entries. When a watch has not been checked, no activity is
shown.
>>> user_browser.open('http://bugs.launchpad.dev/bugs/1/+watch/2')
>>> recent_activity_list = find_tag_by_id(
... user_browser.contents, 'recent-watch-activity')
>>> print recent_activity_list
None
Adding some activity to the watch will cause it to show up in the recent
activity list.
>>> login('foo.bar@canonical.com')
>>> watch = getUtility(IBugWatchSet).get(2)
>>> watch.addActivity()
>>> logout()
>>> user_browser.open('http://bugs.launchpad.dev/bugs/1/+watch/2')
>>> recent_activity_list = find_tag_by_id(
... user_browser.contents, 'recent-watch-activity')
>>> print extract_text(recent_activity_list)
Update completed successfully ... ago
If an update fails, that too will be reflected in the list.
>>> from lp.bugs.interfaces.bugwatch import BugWatchActivityStatus
>>> login('foo.bar@canonical.com')
>>> watch = getUtility(IBugWatchSet).get(2)
>>> watch.addActivity(result=BugWatchActivityStatus.BUG_NOT_FOUND)
>>> logout()
>>> user_browser.open('http://bugs.launchpad.dev/bugs/1/+watch/2')
>>> recent_activity_list = find_tag_by_id(
... user_browser.contents, 'recent-watch-activity')
>>> print extract_text(recent_activity_list)
Update failed with error 'Bug Not Found' ... ago
Update completed successfully ... ago
If a failure has an OOPS ID attached to it, that too will be reflected
in the list.
>>> login('foo.bar@canonical.com')
>>> watch = getUtility(IBugWatchSet).get(2)
>>> watch.addActivity(
... result=BugWatchActivityStatus.COMMENT_IMPORT_FAILED,
... oops_id="OOPS-12345TEST")
>>> logout()
>>> user_browser.open('http://bugs.launchpad.dev/bugs/1/+watch/2')
>>> recent_activity_list = find_tag_by_id(
... user_browser.contents, 'recent-watch-activity')
>>> print extract_text(recent_activity_list)
Update failed with error 'Unable to import...' (OOPS-12345TEST) ... ago
Update failed with error 'Bug Not Found' ... ago
Update completed successfully ... ago
If a Launchpad developer views the page the OOPS IDs will be linkified.
>>> admin_browser.open('http://bugs.launchpad.dev/bugs/1/+watch/2')
>>> oops_link = admin_browser.getLink('OOPS-12345TEST')
>>> print oops_link.url
http...OOPS-12345TEST
Rescheduling a watch
--------------------
It's possible to reschedule a failing watch via the BugWatch +edit page
by clicking the "Update Now" button.
For a new watch, the "Update Now" button isn't shown.
>>> login('foo.bar@canonical.com')
>>> bug_watch = factory.makeBugWatch()
>>> bug_watch.next_check = None
>>> watch_url = (
... 'http://bugs.launchpad.dev/bugs/%s/+watch/%s' %
... (bug_watch.bug.id, bug_watch.id))
>>> logout()
>>> user_browser.open(watch_url)
>>> user_browser.getControl('Update Now')
Traceback (most recent call last):
...
LookupError: label 'Update Now'
If the watch has been checked but has never failed, the button will
remain hidden.
>>> login('foo.bar@canonical.com')
>>> bug_watch.addActivity()
>>> logout()
>>> user_browser.open(watch_url)
>>> user_browser.getControl('Update Now')
Traceback (most recent call last):
...
LookupError: label 'Update Now'
If the watch has failed less than 60% of its recent checks, the button
will appear on the page.
>>> login('foo.bar@canonical.com')
>>> bug_watch.addActivity(result=BugWatchActivityStatus.BUG_NOT_FOUND)
>>> logout()
>>> user_browser.open(watch_url)
>>> reschedule_button = user_browser.getControl('Update Now')
>>> data_tag = find_tag_by_id(
... user_browser.contents, 'bugwatch-next_check')
>>> print extract_text(data_tag.renderContents())
Next check: Not yet scheduled
Clicking the Update Now button will schedule it to be checked
immediately.
>>> reschedule_button.click()
>>> for message in find_tags_by_class(
... user_browser.contents, 'informational message'):
... print extract_text(message)
The ... bug watch has been scheduled for immediate checking.
Looking at the watch +edit page again, we can see that the watch has
been scheduled.
>>> user_browser.open(watch_url)
>>> data_tag = find_tag_by_id(
... user_browser.contents, 'bugwatch-next_check')
>>> print extract_text(data_tag.renderContents())
Next check: 2...
The button will no longer be shown on the page.
>>> reschedule_button = user_browser.getControl('Update Now')
Traceback (most recent call last):
...
LookupError: label 'Update Now'
If a watch has run once and failed once, the reschedule button will be
shown.
>>> login('foo.bar@canonical.com')
>>> bug_watch = factory.makeBugWatch()
>>> bug_watch.next_check = None
>>> bug_watch.addActivity(result=BugWatchActivityStatus.BUG_NOT_FOUND)
>>> watch_url = (
... 'http://bugs.launchpad.dev/bugs/%s/+watch/%s' %
... (bug_watch.bug.id, bug_watch.id))
>>> logout()
>>> user_browser.open(watch_url)
>>> reschedule_button = user_browser.getControl('Update Now')
>>> reschedule_button.click()
>>> for message in find_tags_by_class(
... user_browser.contents, 'informational message'):
... print extract_text(message)
The ... bug watch has been scheduled for immediate checking.
However, once the watch succeeds the button will disappear, even though
the watch has failed > 60% of the time. This is because the most recent
check succeeded, so there's no point in allowing users to reschedule the
watch for checking.
>>> from datetime import timedelta
>>> login('foo.bar@canonical.com')
>>> bug_watch.next_check = datetime.now(utc) + timedelta(days=7)
>>> bug_watch.addActivity()
>>> logout()
>>> user_browser.open(watch_url)
>>> user_browser.getControl('Update Now')
Traceback (most recent call last):
...
LookupError: label 'Update Now'
Resetting a watch
-----------------
It's possible to reset a watch at any time by clicking the "Reset this
watch" button on the watch's page.
>>> from lp.testing.sampledata import ADMIN_EMAIL
>>> login(ADMIN_EMAIL)
>>> bug_watch = factory.makeBugWatch()
>>> bug_watch.lastchecked = datetime.now(utc)
>>> watch_url = (
... 'http://bugs.launchpad.dev/bugs/%s/+watch/%s' %
... (bug_watch.bug.id, bug_watch.id))
>>> logout()
The "Reset this watch" button will appear for administrators.
>>> admin_browser.open(watch_url)
>>> admin_browser.getControl('Reset this watch')
<SubmitControl...>
It also appears for Launchpad Developers.
>>> from zope.component import getUtility
>>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities
>>> from lp.registry.interfaces.person import IPersonSet
>>> login(ADMIN_EMAIL)
>>> admin_user = getUtility(IPersonSet).getByEmail(ADMIN_EMAIL)
>>> new_lp_developer = factory.makePerson(password='newpassword')
>>> launchpad_developers = getUtility(
... ILaunchpadCelebrities).launchpad_developers
>>> dev_added = launchpad_developers.addMember(
... new_lp_developer, admin_user)
>>> lp_dev_browser = setupBrowser(
... auth='Basic %s:newpassword' %
... new_lp_developer.preferredemail.email)
>>> logout()
>>> lp_dev_browser.open(watch_url)
>>> reset_button = lp_dev_browser.getControl('Reset this watch')
Clicking the button will reset the watch completely.
>>> reset_button.click()
>>> for message in find_tags_by_class(
... lp_dev_browser.contents, 'informational message'):
... print extract_text(message)
The ... bug watch has been reset.
>>> data_tag = find_tag_by_id(
... user_browser.contents, 'bugwatch-lastchecked')
>>> print extract_text(data_tag.renderContents())
Checked:
Should a non-admin, non-Launchpad-developer user visit the page, the
button will not appear.
>>> user_browser.open(watch_url)
>>> user_browser.getControl('Reset this watch')
Traceback (most recent call last):
...
LookupError: label 'Reset this watch'
|