~launchpad-pqm/launchpad/devel

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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
= Distribution Search page =

In the 'Bugs' facet of a distribution we can find a list of bugs
reported in that distribution and simple and advanced search forms.

    >>> from canonical.launchpad.webapp.interfaces import IOpenLaunchBag
    >>> from lp.registry.interfaces.distribution import IDistributionSet
    >>> launchbag = getUtility(IOpenLaunchBag)
    >>> debian = getUtility(IDistributionSet).getByName('debian')

A helper function to make it easier to construct a view.  The function
also adds the context object to the launchbag, which approximates what
happens during traversal.

    >>> from zope.component import getMultiAdapter
    >>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest
    >>> def create_view(context, name, form=None):
    ...     launchbag.clear()
    ...     launchbag.add(context)
    ...     view = getMultiAdapter(
    ...         (context, LaunchpadTestRequest(form=form)), name=name)
    ...     view.initialize()
    ...     return view

The simple search form returns only open bugtasks.

    >>> form_values = {
    ...     'search': 'Search',
    ...     'field.searchtext': '',
    ...     'field.orderby': '-importance'}

    >>> distro_search_listingview = create_view(
    ...     debian, "+bugs", form_values)

    >>> open_bugtasks = list(distro_search_listingview.search().batch)
    >>> [(bugtask.bug.id, bugtask.status.name, bugtask.importance.name)
    ...  for bugtask in open_bugtasks]
    [(3, 'NEW', 'UNKNOWN'),
     (1, 'CONFIRMED', 'LOW'),
     (2, 'CONFIRMED', 'LOW')]

And the advanced form allows us to query for specific bug statuses.

    >>> form_values = {
    ...     'search': 'Search bugs in Debian',
    ...     'advanced': 1,
    ...     'field.status': 'Fix Released',
    ...     'field.searchtext': '',
    ...     'field.orderby': '-importance'}

    >>> distro_advanced_search_listingview = create_view(
    ...     debian, '+bugs', form_values)
    >>> fix_released_bugtasks = list(
    ...     distro_advanced_search_listingview.search().batch)
    >>> [(bugtask.bug.id, bugtask.status.name)
    ...     for bugtask in fix_released_bugtasks]
    [(8, 'FIXRELEASED')]

The advanced search page also has a widget to filter on upstream
status.

    >>> distro_advanced_search_listingview.shouldShowUpstreamStatusBox()
    True

It also allows filtering on milestones.

    >>> milestones = (
    ...     distro_advanced_search_listingview.getMilestoneWidgetValues())
    >>> for value in milestones:
    ...     print value['title']
    Debian 3.1
    Debian 3.1-rc1

The same milestone will be available for a debian package.

    >>> form_values = {'advanced': 1}

    >>> firefox_debian = debian.getSourcePackage('mozilla-firefox')
    >>> package_advanced_search_listingview = create_view(
    ...     firefox_debian, '+bugs', form_values)
    >>> milestones = (
    ...     package_advanced_search_listingview.getMilestoneWidgetValues())
    >>> for value in milestones:
    ...     print value['title']
    Debian 3.1
    Debian 3.1-rc1

A triager may find it useful to query for bugs with no package:

    >>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')

    >>> form_values = {
    ...     'search': 'Search bugs in Ubuntu',
    ...     'advanced': 1,
    ...     'field.has_no_package': 'on',
    ...     'field.orderby': '-importance'}

    >>> distro_advanced_search_listingview = create_view(
    ...     ubuntu, '+bugs', form_values)

    >>> bugtasks_needing_packages = list(
    ...     distro_advanced_search_listingview.search().batch)
    >>> [bugtask.bug.id for bugtask in bugtasks_needing_packages]
    [2]

If the search query contains new line characters they'll be replaced by
spaces.

    >>> form_values = {
    ...     'search': 'Search',
    ...     'field.searchtext': 'blackhole\n\rtrash\n\rfolder',
    ...     'field.orderby': '-importance'}

    >>> distro_search_listingview = create_view(
    ...     ubuntu, '+bugs', form_values)

    >>> bugtasks_search_with_new_lines = list(
    ...     distro_search_listingview.search().batch)
    >>> [bugtask.bug.id for bugtask in bugtasks_search_with_new_lines]
    [2]

We can filter our search results by reporter

    >>> form_values = {
    ...     'search': 'Search bugs in Ubuntu',
    ...     'advanced': 1,
    ...     'field.bug_reporter': 'name12',
    ...     'field.orderby': '-importance'}

    >>> distro_advanced_search_listingview = create_view(
    ...     debian, '+bugs', form_values)

    >>> bugtasks_filtered_by_reporter = list(
    ...     distro_advanced_search_listingview.search().batch)
    >>> [(bugtask.bug.id, bugtask.bug.owner.name)
    ...     for bugtask in bugtasks_filtered_by_reporter]
    [(1, u'name12'), (2, u'name12')]

But if we query for an invalid person, the view displays a nice error
message.

    >>> form_values = {
    ...     'search': 'Search bugs in Ubuntu',
    ...     'advanced': 1,
    ...     'field.bug_reporter': 'invalid-reporter',
    ...     'field.orderby': '-importance'}

    >>> distro_advanced_search_listingview = create_view(
    ...     debian, '+bugs', form_values)

    >>> distro_advanced_search_listingview.getFieldError('bug_reporter')
    u"There's no person with the name or email address 'invalid-reporter'."

The same if we try with an invalid assignee.

    >>> form_values = {
    ...     'search': 'Search bugs in Ubuntu',
    ...     'advanced': 1,
    ...     'field.assignee': 'invalid-assignee',
    ...     'field.orderby': '-importance'}

    >>> distro_advanced_search_listingview = create_view(
    ...     debian, '+bugs', form_values)

    >>> distro_advanced_search_listingview.getFieldError('assignee')
    u"There's no person with the name or email address 'invalid-assignee'."

Searching by component is possible, as long as the context has defined a
.currentseries.

    >>> form_values = {
    ...     'search': 'Search bugs in Ubuntu',
    ...     'advanced': 1,
    ...     'field.component': 1,
    ...     'field.orderby': '-importance'}

    >>> distro_advanced_search_listingview = create_view(
    ...     ubuntu, '+bugs', form_values)

    >>> distro_advanced_search_listingview.shouldShowComponentWidget()
    True

    >>> found_bugs = list(distro_advanced_search_listingview.search().batch)

    >>> sorted([bug.id for bug in found_bugs])
    [25]

If the context does *not* have a currentseries, component searching is
ambiguous, because a package may be published in a different component
in each series. In this case, the component search widget is hidden.

    >>> gentoo = getUtility(IDistributionSet).getByName('gentoo')

    >>> form_values = {
    ...     'search': 'Search bugs in Gentoo',
    ...     'advanced': 1,
    ...     'field.component': 1,
    ...     'field.orderby': '-importance'}

    >>> distro_advanced_search_listingview = create_view(
    ...     gentoo, '+bugs', form_values)

    >>> distro_advanced_search_listingview.shouldShowComponentWidget()
    False


== Distribution Series search page ==

    >>> sarge = debian.getSeries('sarge')

The simple search form returns only open bugtasks.

    >>> form_values = {
    ...     'search': 'Search',
    ...     'field.searchtext': '',
    ...     'field.orderby': '-importance'}

    >>> distroseries_search_listingview = create_view(
    ...     sarge, "+bugs", form_values)

    >>> open_bugtasks = list(distroseries_search_listingview.search().batch)
    >>> [(bugtask.id, bugtask.bug.id, bugtask.status.name, bugtask.importance.name)
    ...  for bugtask in open_bugtasks]
    [(19, 3, 'NEW', 'MEDIUM')]

Note that because we are not in a package context, the ordering was done
by BugTask.id and not Bug.id -- Bug IDs are not unique in the
distribution context.

And now we'll change the status of one of the bugtasks, but first we
need to be logged in.

    >>> from canonical.database.sqlbase import flush_database_updates
    >>> from canonical.launchpad.ftests import login

    >>> login("test@canonical.com")

    >>> from lp.bugs.interfaces.bugtask import BugTaskStatus, IBugTaskSet
    >>> open_bugtask = getUtility(IBugTaskSet).get(19)
    >>> open_bugtask.status.name
    'NEW'
    >>> open_bugtask.bug.id
    3
    >>> open_bugtask.transitionToStatus(
    ...     BugTaskStatus.INVALID, getUtility(ILaunchBag).user)
    >>> flush_database_updates()

And the advanced form allows us to query for specific bug statuses.

    >>> form_values = {
    ...     'search': 'Search bugs in sarge',
    ...     'advanced': 1,
    ...     'field.status': 'Invalid',
    ...     'field.searchtext': '',
    ...     'field.orderby': '-importance'}

    >>> distroseries_advanced_search_view = create_view(
    ...     sarge, '+bugs', form_values)
    >>> invalid_bugtasks = list(
    ...     distroseries_advanced_search_view.search().batch)
    >>> [(bugtask.bug.id, bugtask.status.name)
    ...     for bugtask in invalid_bugtasks]
    [(3, 'INVALID')]

The upstream status widget is also present here.

    >>> distroseries_advanced_search_view.shouldShowUpstreamStatusBox()
    True

There are no milestones to filter on, since sarge doesn't have any
milestones.

    >>> distroseries_advanced_search_view.getMilestoneWidgetValues()
    []

The same is true for a sarge package.

    >>> form_values = {'advanced': 1}
    >>> firefox_sarge = sarge.getSourcePackage('mozilla-firefox')
    >>> package_advanced_search_view = create_view(
    ...     firefox_sarge, '+bugs', form_values)
    >>> package_advanced_search_view.getMilestoneWidgetValues()
    []


== ProjectGroup Search Page ==

    >>> from lp.registry.interfaces.projectgroup import IProjectGroupSet
    >>> mozilla = getUtility(IProjectGroupSet).getByName('mozilla')

The simple search form returns only open bugtasks.

    >>> form_values = {
    ...     'search': 'Search',
    ...     'field.searchtext': '',
    ...     'field.orderby': '-importance'}

    >>> mozilla_search_listingview = create_view(
    ...     mozilla, "+bugs", form_values)

    >>> open_bugtasks = list(mozilla_search_listingview.search().batch)
    >>> for bugtask in open_bugtasks:
    ...     print bugtask.bug.id, bugtask.product.name, bugtask.status.name
    15 thunderbird NEW
    5 firefox NEW
    4 firefox NEW
    1 firefox NEW

And now we'll change the status of one of the bugtasks (we are still
logged in from earlier):

    >>> previous_status = open_bugtasks[0].status
    >>> open_bugtasks[0].transitionToStatus(
    ...     BugTaskStatus.INVALID, getUtility(ILaunchBag).user)
    >>> flush_database_updates()

And the advanced form allows us to query for specific bug statuses.

    >>> form_values = {
    ...     'search': 'Search bugs in the Mozilla Project',
    ...     'advanced': 1,
    ...     'field.status': 'Invalid',
    ...     'field.searchtext': '',
    ...     'field.orderby': '-importance'}

    >>> mozilla_search_listingview = create_view(mozilla, '+bugs', form_values)
    >>> invalid_bugtasks = list(mozilla_search_listingview.search().batch)
    >>> for bugtask in invalid_bugtasks:
    ...     print bugtask.bug.id, bugtask.product.name, bugtask.status.name
    15 thunderbird INVALID

    >>> open_bugtasks[0].transitionToStatus(
    ...     previous_status, getUtility(ILaunchBag).user)
    >>> flush_database_updates()

This view does *not* render the upstream status widget.

    >>> mozilla_search_listingview.shouldShowUpstreamStatusBox()
    False

Check what milestones are displayed on the advanced search form:

    >>> form_values = {
    ...     'advanced': 1}

    >>> advanced_search_view = create_view(
    ...     mozilla, '+bugs', form_values)
    >>> for value in advanced_search_view.getMilestoneWidgetValues():
    ...     print value['title']
    Mozilla Firefox 1.0


== Constructing search filter urls ==

There is a helper method, get_buglisting_search_filter_url(), which can
be used to construct bug search URLs. It takes keyword parameters for
the assignee, importance, status and status_upstream fields of a bug
search and returns the correct URL for a bug listing with those
parameters. The URL returned isn't tied to any specific bugtarget, so
it's up to the callsite to urljoin() the results of
get_buglisting_search_filter_url() with a bugtarget URL to make it
useful.

    >>> from lp.bugs.browser.bugtask import (
    ...     get_buglisting_search_filter_url)

Calling get_buglisting_search_filter_url() without any parameters will
return a plain search URL which, when visited, will display all open
bugs.

    >>> print get_buglisting_search_filter_url()
    +bugs?search=Search

Passing an assignee will add an assignee field to the query string. Not
that get_buglisting_search_filter_url() doesn't check any of the data
that's passed to it; that's for the target search to do.

    >>> print get_buglisting_search_filter_url(assignee='gmb')
    +bugs?search=Search&field.assignee=gmb

Passing an importance will add an importance field to the query string.

    >>> print get_buglisting_search_filter_url(importance='UNDECIDED')
    +bugs?search=Search&field.importance=UNDECIDED

Importance can be a single item or a list of items:

    >>> print get_buglisting_search_filter_url(importance=['LOW', 'HIGH'])
    +bugs?search=Search&field.importance=LOW&field.importance=HIGH

Passing a status will add a status field to the query string:

    >>> print get_buglisting_search_filter_url(status='TRIAGED')
    +bugs?search=Search&field.status=TRIAGED

Status, like importance, can be a list:

    >>> print get_buglisting_search_filter_url(status=['NEW', 'INCOMPLETE'])
    +bugs?search=Search&field.status=NEW&field.status=INCOMPLETE

Passing a status_upstream parameter will add a status_upstream field to
the query string.

    >>> print get_buglisting_search_filter_url(
    ...     status_upstream='open_upstream')
    +bugs?search=Search&field.status_upstream=open_upstream

The fields will always be rendered in the order assignee, importance,
status, status_upstream, regardless of what order they're passed to
get_buglisting_search_filter_url().

    >>> print get_buglisting_search_filter_url(
    ...     status_upstream='open_upstream', status='NEW',
    ...     importance='WISHLIST', assignee='mark')
    +bugs?search=Search&field.assignee=mark&field.importance=WISHLIST&field.status=NEW&field.status_upstream=open_upstream