Merge lp:~adeuring/launchpad/bug-532078 into lp:launchpad/db-devel

Proposed by Abel Deuring
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~adeuring/launchpad/bug-532078
Merge into: lp:launchpad/db-devel
Diff against target: 128 lines (+104/-2)
2 files modified
lib/lp/bugs/browser/bugtask.py (+2/-2)
lib/lp/bugs/browser/tests/test_bugtarget_patches_view.py (+102/-0)
To merge this branch: bzr merge lp:~adeuring/launchpad/bug-532078
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+20727@code.launchpad.net

Description of the change

This branch fixes bug 532048: Count of bugs with patches is wrong, +patches shows different information

The cause is simple: While BugTarget.searchTasks() is used both by BugsStatsMixin.bugs_with_patches_count to retrive the number of bugs with patches and by BugsPatchesView.batchedPatchTasks() to retrieve the bugs to show, they pass different sets of bug tasks statuses to searchParams(): BugsStatsMixin.bugs_with_patches_count used all statused except UNKNOWN, while BugsPatchesView.batchedPatchTasks() excluded in addition WONTFIX and INVALID.

I added unit tests for BugsStatsMixin.bugs_with_patches_count and BugsPatchesView to ensure that they include the same sets of bugtasks.

test: ./bin/test -vv -t test_bugtarget_patches_view

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/bugs/browser/bugtask.py
  lib/lp/bugs/browser/tests/test_bugtarget_patches_view.py

== Pylint notices ==

lib/lp/bugs/browser/bugtask.py
    78: [F0401] Unable to import 'lazr.delegates' (No module named delegates)
    79: [F0401] Unable to import 'lazr.enum' (No module named enum)
    81: [F0401] Unable to import 'lazr.lifecycle.event' (No module named lifecycle)
    82: [F0401] Unable to import 'lazr.lifecycle.snapshot' (No module named lifecycle)
    83: [F0401] Unable to import 'lazr.restful.interface' (No module named restful)
    84: [F0401] Unable to import 'lazr.restful.interfaces' (No module named restful)
    100: [F0401] Unable to import 'lazr.uri' (No module named uri)
    155: [F0401] Unable to import 'lazr.restful.interfaces' (No module named restful)

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/bugs/browser/bugtask.py'
--- lib/lp/bugs/browser/bugtask.py 2010-03-01 11:28:05 +0000
+++ lib/lp/bugs/browser/bugtask.py 2010-03-08 09:24:33 +0000
@@ -114,7 +114,7 @@
114 INominationsReviewTableBatchNavigator, INullBugTask, IPersonBugTaskSearch,114 INominationsReviewTableBatchNavigator, INullBugTask, IPersonBugTaskSearch,
115 IProductSeriesBugTask, IRemoveQuestionFromBugTaskForm, IUpstreamBugTask,115 IProductSeriesBugTask, IRemoveQuestionFromBugTaskForm, IUpstreamBugTask,
116 IUpstreamProductBugTaskSearch, UNRESOLVED_BUGTASK_STATUSES,116 IUpstreamProductBugTaskSearch, UNRESOLVED_BUGTASK_STATUSES,
117 RESOLVED_BUGTASK_STATUSES)117 UNRESOLVED_PLUS_FIXRELEASED_BUGTASK_STATUSES)
118from lp.bugs.interfaces.bugtracker import BugTrackerType118from lp.bugs.interfaces.bugtracker import BugTrackerType
119from lp.bugs.interfaces.cve import ICveSet119from lp.bugs.interfaces.cve import ICveSet
120from lp.registry.interfaces.distribution import IDistribution120from lp.registry.interfaces.distribution import IDistribution
@@ -1886,7 +1886,7 @@
1886 """A count of unresolved bugs with patches."""1886 """A count of unresolved bugs with patches."""
1887 return self.context.searchTasks(1887 return self.context.searchTasks(
1888 None, user=self.user,1888 None, user=self.user,
1889 status=(UNRESOLVED_BUGTASK_STATUSES + RESOLVED_BUGTASK_STATUSES),1889 status=UNRESOLVED_PLUS_FIXRELEASED_BUGTASK_STATUSES,
1890 omit_duplicates=True, has_patch=True).count()1890 omit_duplicates=True, has_patch=True).count()
18911891
18921892
18931893
=== added file 'lib/lp/bugs/browser/tests/test_bugtarget_patches_view.py'
--- lib/lp/bugs/browser/tests/test_bugtarget_patches_view.py 1970-01-01 00:00:00 +0000
+++ lib/lp/bugs/browser/tests/test_bugtarget_patches_view.py 2010-03-08 09:24:33 +0000
@@ -0,0 +1,102 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4__metaclass__ = type
5
6
7import unittest
8
9from canonical.launchpad.ftests import login
10from canonical.launchpad.webapp.servers import LaunchpadTestRequest
11from canonical.testing import LaunchpadFunctionalLayer
12
13from lp.bugs.browser.bugtarget import BugsPatchesView
14from lp.bugs.browser.bugtask import BugListingPortletStatsView
15from lp.bugs.interfaces.bugtask import BugTaskStatus
16from lp.testing import TestCaseWithFactory
17
18
19DISPLAY_BUG_STATUS_FOR_PATCHES = {
20 BugTaskStatus.NEW: True,
21 BugTaskStatus.INCOMPLETE: True,
22 BugTaskStatus.INVALID: False,
23 BugTaskStatus.WONTFIX: False,
24 BugTaskStatus.CONFIRMED: True,
25 BugTaskStatus.TRIAGED: True,
26 BugTaskStatus.INPROGRESS: True,
27 BugTaskStatus.FIXCOMMITTED: True,
28 BugTaskStatus.FIXRELEASED: True,
29 BugTaskStatus.UNKNOWN: False,
30 }
31
32
33class TestBugTargetPatchCountBase(TestCaseWithFactory):
34
35 layer = LaunchpadFunctionalLayer
36
37 def setUp(self):
38 super(TestBugTargetPatchCountBase, self).setUp()
39 login('foo.bar@canonical.com')
40 self.product = self.factory.makeProduct()
41
42 def makeBugWithPatch(self, status):
43 bug = self.factory.makeBug(
44 product=self.product, owner=self.product.owner)
45 self.factory.makeBugAttachment(bug=bug, is_patch=True)
46 bug.default_bugtask.transitionToStatus(status, user=bug.owner)
47
48
49class TestBugTargetPatchView(TestBugTargetPatchCountBase):
50
51 def setUp(self):
52 super(TestBugTargetPatchView, self).setUp()
53 self.view = BugsPatchesView(self.product, LaunchpadTestRequest())
54
55 def test_status_of_bugs_with_patches_shown(self):
56 # Bugs with patches that have the status INVALID, WONTFIX,
57 # UNKNOWN are not shown in the +patches view; all other
58 # bugs are shown.
59 number_of_bugs_shown = 0
60 for bugtask_status in DISPLAY_BUG_STATUS_FOR_PATCHES:
61 if DISPLAY_BUG_STATUS_FOR_PATCHES[bugtask_status]:
62 number_of_bugs_shown += 1
63 self.makeBugWithPatch(bugtask_status)
64 batched_tasks = self.view.batchedPatchTasks()
65 self.assertEqual(
66 batched_tasks.batch.listlength, number_of_bugs_shown,
67 "Unexpected number of bugs with patches displayed for status "
68 "%s" % bugtask_status)
69
70
71class TestBugListingPortletStatsView(TestBugTargetPatchCountBase):
72
73 def setUp(self):
74 super(TestBugListingPortletStatsView, self).setUp()
75 self.view = BugListingPortletStatsView(
76 self.product, LaunchpadTestRequest())
77
78 def test_bugs_with_patches_count(self):
79 # Bugs with patches that have the status INVALID, WONTFIX,
80 # UNKNOWN are not counted in
81 # BugListingPortletStatsView.bugs_with_patches_count, bugs
82 # with all other statuses are counted.
83 number_of_bugs_shown = 0
84 for bugtask_status in DISPLAY_BUG_STATUS_FOR_PATCHES:
85 if DISPLAY_BUG_STATUS_FOR_PATCHES[bugtask_status]:
86 number_of_bugs_shown += 1
87 self.makeBugWithPatch(bugtask_status)
88 self.assertEqual(
89 self.view.bugs_with_patches_count, number_of_bugs_shown,
90 "Unexpected number of bugs with patches displayed for status "
91 "%s" % bugtask_status)
92
93
94def test_suite():
95 suite = unittest.TestSuite()
96 suite.addTest(unittest.makeSuite(TestBugTargetPatchView))
97 suite.addTest(unittest.makeSuite(TestBugListingPortletStatsView))
98 return suite
99
100
101if __name__ == '__main__':
102 unittest.TextTestRunner().run(test_suite())

Subscribers

People subscribed via source and target branches

to status/vote changes: