Merge lp:~julian-edwards/launchpad/sync-close-bugs-bug-833736 into lp:launchpad

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 13886
Proposed branch: lp:~julian-edwards/launchpad/sync-close-bugs-bug-833736
Merge into: lp:launchpad
Diff against target: 179 lines (+71/-29)
3 files modified
lib/lp/soyuz/interfaces/archive.py (+3/-5)
lib/lp/soyuz/scripts/processaccepted.py (+10/-5)
lib/lp/soyuz/scripts/tests/test_processaccepted.py (+58/-19)
To merge this branch: bzr merge lp:~julian-edwards/launchpad/sync-close-bugs-bug-833736
Reviewer Review Type Date Requested Status
Julian Edwards Pending
Review via email: mp+74117@code.launchpad.net

Commit message

[r=julian-edwards][bug=833736] When closing bugs on package syncs, fix a bug that prevented closing bugs in a different distroseries source package to the original upload distroseries on the sourcepackagerelease.

Description of the change

Fix an additional bug in the original branch that prevented closure of bugs that are in a different distroseries package to the original uploaded distroseries.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/interfaces/archive.py'
2--- lib/lp/soyuz/interfaces/archive.py 2011-08-30 14:54:57 +0000
3+++ lib/lp/soyuz/interfaces/archive.py 2011-09-06 10:47:26 +0000
4@@ -1245,17 +1245,15 @@
5 @operation_for_version('devel')
6 def copyPackages(source_names, from_archive, to_pocket, person,
7 to_series=None, include_binaries=False):
8- """Atomically copy named sources into this archive from another.
9+ """Copy multiple named sources into this archive from another.
10
11 Asynchronously copy the most recent PUBLISHED versions of the named
12 sources to the destination archive if necessary. Calls to this
13 method will return immediately if the copy passes basic security
14 checks and the copy will happen sometime later with full checking.
15
16- This operation will only succeed when all requested packages
17- are synchronised between the archives. If any of the requested
18- copies cannot be performed, the whole operation will fail. There
19- will be no partial changes of the destination archive.
20+ Partial changes of the destination archive can happen because each
21+ source is copied in its own transaction.
22
23 :param source_names: a list of string names of packages to copy.
24 :param from_archive: the source archive from which to copy.
25
26=== modified file 'lib/lp/soyuz/scripts/processaccepted.py'
27--- lib/lp/soyuz/scripts/processaccepted.py 2011-08-31 11:58:28 +0000
28+++ lib/lp/soyuz/scripts/processaccepted.py 2011-09-06 10:47:26 +0000
29@@ -164,11 +164,13 @@
30 changesfile_object = sourcepackagerelease.upload_changesfile
31
32 close_bugs_for_sourcepackagerelease(
33- sourcepackagerelease, changesfile_object, since_version)
34+ sourcepackagerelease, changesfile_object, since_version,
35+ upload_distroseries=source_publication.distroseries)
36
37
38 def close_bugs_for_sourcepackagerelease(source_release, changesfile_object,
39- since_version=None):
40+ since_version=None,
41+ upload_distroseries=None):
42 """Close bugs for a given source.
43
44 Given a `ISourcePackageRelease` and a corresponding changesfile object,
45@@ -203,10 +205,13 @@
46 # here, BE CAREFUL with the unproxied bug object and look at
47 # what you're doing with it that might violate security.
48 bug = removeSecurityProxy(bug)
49+ if upload_distroseries is not None:
50+ target = upload_distroseries.getSourcePackage(
51+ source_release.sourcepackagename)
52+ else:
53+ target = source_release.sourcepackage
54 edited_task = bug.setStatus(
55- target=source_release.sourcepackage,
56- status=BugTaskStatus.FIXRELEASED,
57- user=janitor)
58+ target=target, status=BugTaskStatus.FIXRELEASED, user=janitor)
59 if edited_task is not None:
60 assert source_release.changelog_entry is not None, (
61 "New source uploads should have a changelog.")
62
63=== modified file 'lib/lp/soyuz/scripts/tests/test_processaccepted.py'
64--- lib/lp/soyuz/scripts/tests/test_processaccepted.py 2011-08-29 17:02:01 +0000
65+++ lib/lp/soyuz/scripts/tests/test_processaccepted.py 2011-09-06 10:47:26 +0000
66@@ -8,8 +8,10 @@
67
68 from canonical.testing.layers import LaunchpadZopelessLayer
69 from lp.bugs.interfaces.bugtask import BugTaskStatus
70+from lp.registry.interfaces.pocket import PackagePublishingPocket
71 from lp.soyuz.scripts.processaccepted import (
72 close_bugs_for_sourcepackagerelease,
73+ close_bugs_for_sourcepublication,
74 )
75 from lp.testing import TestCaseWithFactory
76
77@@ -27,28 +29,30 @@
78 """
79 layer = LaunchpadZopelessLayer
80
81- def test_close_bugs_for_sourcepackagerelease_with_no_changes_file(self):
82- # If there's no changes file it should read the changelog_entry on
83- # the sourcepackagerelease.
84-
85- spr = self.factory.makeSourcePackageRelease(changelog_entry="blah")
86-
87+ def makeChangelogWithBugs(self, spr, target_series=None):
88+ """Create a changelog for the passed sourcepackagerelease that has
89+ 6 bugs referenced.
90+
91+ :param spr: The sourcepackagerelease that needs a changelog.
92+ :param target_distro: the distribution context for the source package
93+ bug target. If None, default to its uploaded distribution.
94+
95+ :return: A tuple which is a list of (bug, bugtask)
96+ """
97 # Make 4 bugs and corresponding bugtasks and put them in an array
98 # as tuples.
99 bugs = []
100- for i in range(5):
101+ for i in range(6):
102+ if target_series is None:
103+ target = spr.sourcepackage
104+ else:
105+ target = target_series.getSourcePackage(spr.sourcepackagename)
106 bug = self.factory.makeBug()
107- bugtask = self.factory.makeBugTask(
108- target=spr.sourcepackage, bug=bug)
109+ bugtask = self.factory.makeBugTask(target=target, bug=bug)
110 bugs.append((bug, bugtask))
111-
112- unfixed_bug = self.factory.makeBug()
113- unfixed_task = self.factory.makeBugTask(
114- target=spr.sourcepackage, bug=unfixed_bug)
115-
116 # Make a changelog entry for a package which contains the IDs of
117- # the 5 bugs separated across 2 releases.
118- changelog=dedent("""
119+ # the 6 bugs separated across 3 releases.
120+ changelog = dedent("""
121 foo (1.0-3) unstable; urgency=low
122
123 * closes: %s, %s
124@@ -74,18 +78,53 @@
125 bugs[2][0].id,
126 bugs[3][0].id,
127 bugs[4][0].id,
128- unfixed_bug.id,
129+ bugs[5][0].id,
130 ))
131 lfa = self.factory.makeLibraryFileAlias(content=changelog)
132-
133 removeSecurityProxy(spr).changelog = lfa
134 self.layer.txn.commit()
135+ return bugs
136+
137+ def test_close_bugs_for_sourcepackagerelease_with_no_changes_file(self):
138+ # If there's no changes file it should read the changelog_entry on
139+ # the sourcepackagerelease.
140+
141+ spr = self.factory.makeSourcePackageRelease(changelog_entry="blah")
142+ bugs = self.makeChangelogWithBugs(spr)
143
144 # Call the method and test it's closed the bugs.
145 close_bugs_for_sourcepackagerelease(spr, changesfile_object=None,
146 since_version="1.0-1")
147 for bug, bugtask in bugs:
148+ if bug.id != bugs[5][0].id:
149+ self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask.status)
150+ else:
151+ self.assertEqual(BugTaskStatus.NEW, bugtask.status)
152+
153+ def test__close_bugs_for_sourcepublication__uses_right_distro(self):
154+ # If a source was originally uploaded to a different distro,
155+ # closing bugs based on a publication of the same source in a new
156+ # distro should work.
157+
158+ # Create a source package that was originally uploaded to one
159+ # distro and publish it in a second distro.
160+ spr = self.factory.makeSourcePackageRelease(changelog_entry="blah")
161+ target_distro = self.factory.makeDistribution()
162+ target_distroseries = self.factory.makeDistroSeries(target_distro)
163+ bugs = self.makeChangelogWithBugs(
164+ spr, target_series=target_distroseries)
165+ target_spph = self.factory.makeSourcePackagePublishingHistory(
166+ sourcepackagerelease=spr, distroseries=target_distroseries,
167+ archive=target_distro.main_archive,
168+ pocket=PackagePublishingPocket.RELEASE)
169+
170+ # The test depends on this pre-condition.
171+ self.assertNotEqual(spr.upload_distroseries.distribution,
172+ target_distroseries.distribution)
173+
174+ close_bugs_for_sourcepublication(target_spph, since_version="1.0")
175+
176+ for bug, bugtask in bugs:
177 self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask.status)
178
179- self.assertEqual(BugTaskStatus.NEW, unfixed_task.status)
180