Merge lp:~cjwatson/launchpad/copy-custom-uploads-fix into lp:launchpad

Proposed by Colin Watson on 2012-06-26
Status: Merged
Approved by: Colin Watson on 2012-06-26
Approved revision: no longer in the source branch.
Merged at revision: 15499
Proposed branch: lp:~cjwatson/launchpad/copy-custom-uploads-fix
Merge into: lp:launchpad
Diff against target: 138 lines (+64/-35)
3 files modified
database/schema/security.cfg (+1/-0)
lib/lp/soyuz/scripts/tests/test_copypackage.py (+0/-35)
lib/lp/soyuz/tests/test_packagecopyjob.py (+63/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/copy-custom-uploads-fix
Reviewer Review Type Date Requested Status
Richard Harding (community) 2012-06-26 Approve on 2012-06-26
Review via email: mp+112122@code.launchpad.net

Commit Message

Allow copy_packages to INSERT into packageuploadcustom so that PCJ copying of custom uploads can work.

Description of the Change

== Summary ==

https://code.launchpad.net/~cjwatson/launchpad/copy-custom-uploads/+merge/111653 failed QA due to missing DB permissions.

== Implementation details ==

I moved the tests from test_copypackage to test_packagecopyjob, since the script is eventually going to go away anyway and we want everything to end up as PCJs. The PCJ test is clearly more stringent.

== LOC Rationale ==

+29. Same rationale as https://code.launchpad.net/~cjwatson/launchpad/copy-custom-uploads/+merge/111653.

== Tests ==

bin/test -vvct test_packagecopyjob

== Demo and Q/A ==

Same as https://code.launchpad.net/~cjwatson/launchpad/copy-custom-uploads/+merge/111653.

== Lint ==

As with https://code.launchpad.net/~cjwatson/launchpad/copy-custom-uploads/+merge/111653, pre-existing lint in ./lib/lp/soyuz/scripts/tests/test_copypackage.py.

To post a comment you must log in.
Richard Harding (rharding) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/security.cfg'
2--- database/schema/security.cfg 2012-06-26 00:46:41 +0000
3+++ database/schema/security.cfg 2012-06-26 14:28:34 +0000
4@@ -1093,6 +1093,7 @@
5 public.packagesetinclusion = SELECT, INSERT
6 public.packagesetsources = SELECT, INSERT
7 public.packageupload = SELECT, INSERT, UPDATE
8+public.packageuploadcustom = SELECT, INSERT, UPDATE
9 public.packageuploadsource = SELECT
10 public.packaging = SELECT, INSERT
11 public.person = SELECT
12
13=== modified file 'lib/lp/soyuz/scripts/tests/test_copypackage.py'
14--- lib/lp/soyuz/scripts/tests/test_copypackage.py 2012-06-25 08:35:33 +0000
15+++ lib/lp/soyuz/scripts/tests/test_copypackage.py 2012-06-26 14:28:34 +0000
16@@ -1660,41 +1660,6 @@
17
18 self.assertIsNone(copied_source.sponsor)
19
20- def test_copy_custom_upload_files(self):
21- # Custom upload files are queued for republication when they are
22- # copied.
23- self.test_publisher.breezy_autotest.status = SeriesStatus.CURRENT
24- source = self.test_publisher.getPubSource(
25- pocket=PackagePublishingPocket.PROPOSED)
26- self.test_publisher.getPubBinaries(
27- pocket=PackagePublishingPocket.PROPOSED, pub_source=source)
28- [build] = source.getBuilds()
29- custom_file = self.factory.makeLibraryFileAlias()
30- build.package_upload.addCustom(
31- custom_file, PackageUploadCustomFormat.DIST_UPGRADER)
32- # Make the new librarian file available.
33- self.layer.txn.commit()
34-
35- self.doCopy(
36- source, source.archive, source.distroseries,
37- PackagePublishingPocket.UPDATES, include_binaries=True)
38- [upload] = source.distroseries.getPackageUploads(
39- status=PackageUploadStatus.ACCEPTED, archive=source.archive,
40- pocket=PackagePublishingPocket.UPDATES,
41- custom_type=PackageUploadCustomFormat.DIST_UPGRADER)
42-
43- # The upload is targeted to the right publishing context.
44- self.assertEqual(source.archive, upload.archive)
45- self.assertEqual(source.distroseries, upload.distroseries)
46- self.assertEqual(PackagePublishingPocket.UPDATES, upload.pocket)
47-
48- # It contains only the custom files.
49- self.assertEqual([], list(upload.sources))
50- self.assertEqual([], list(upload.builds))
51- self.assertEqual(
52- [custom_file],
53- [custom.libraryfilealias for custom in upload.customfiles])
54-
55
56 class TestDoDelayedCopy(TestCaseWithFactory, BaseDoCopyTests):
57
58
59=== modified file 'lib/lp/soyuz/tests/test_packagecopyjob.py'
60--- lib/lp/soyuz/tests/test_packagecopyjob.py 2012-06-25 09:10:14 +0000
61+++ lib/lp/soyuz/tests/test_packagecopyjob.py 2012-06-26 14:28:34 +0000
62@@ -34,6 +34,7 @@
63 from lp.soyuz.enums import (
64 ArchivePurpose,
65 PackageCopyPolicy,
66+ PackageUploadCustomFormat,
67 PackageUploadStatus,
68 SourcePackageFormat,
69 )
70@@ -1166,6 +1167,68 @@
71 for source_file in copied_source.sourcepackagerelease.files:
72 self.assertFalse(source_file.libraryfile.restricted)
73
74+ def test_copy_custom_upload_files(self):
75+ # Custom upload files are queued for republication when they are
76+ # copied.
77+ publisher = SoyuzTestPublisher()
78+ publisher.prepareBreezyAutotest()
79+ publisher.breezy_autotest.status = SeriesStatus.CURRENT
80+ spph = publisher.getPubSource(
81+ pocket=PackagePublishingPocket.PROPOSED)
82+ publisher.getPubBinaries(
83+ pocket=PackagePublishingPocket.PROPOSED, pub_source=spph)
84+ [build] = spph.getBuilds()
85+ custom_file = self.factory.makeLibraryFileAlias()
86+ build.package_upload.addCustom(
87+ custom_file, PackageUploadCustomFormat.DIST_UPGRADER)
88+ # Make the new librarian file available.
89+ self.layer.txn.commit()
90+
91+ # Create the copy job.
92+ source = getUtility(IPlainPackageCopyJobSource)
93+ requester = self.factory.makePerson()
94+ with person_logged_in(spph.archive.owner):
95+ spph.archive.newPocketUploader(
96+ requester, PackagePublishingPocket.UPDATES)
97+ job = source.create(
98+ package_name=spph.sourcepackagerelease.name,
99+ package_version=spph.sourcepackagerelease.version,
100+ source_archive=spph.archive,
101+ target_archive=spph.archive,
102+ target_distroseries=spph.distroseries,
103+ target_pocket=PackagePublishingPocket.UPDATES,
104+ include_binaries=True,
105+ requester=requester)
106+
107+ # Start, accept, and run the job.
108+ self.assertRaises(SuspendJobException, self.runJob, job)
109+ job.suspend()
110+ switch_dbuser("launchpad_main")
111+ pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
112+ [removeSecurityProxy(job).context.id]).one()
113+ self.assertEqual(PackageUploadStatus.UNAPPROVED, pu.status)
114+ pu.acceptFromQueue()
115+ self.assertEqual(PackageUploadStatus.ACCEPTED, pu.status)
116+ self.runJob(job)
117+ self.assertEqual(PackageUploadStatus.DONE, pu.status)
118+
119+ [upload] = spph.distroseries.getPackageUploads(
120+ status=PackageUploadStatus.ACCEPTED, archive=spph.archive,
121+ pocket=PackagePublishingPocket.UPDATES,
122+ custom_type=PackageUploadCustomFormat.DIST_UPGRADER)
123+
124+ # The upload is targeted to the right publishing context.
125+ self.assertEqual(spph.archive, upload.archive)
126+ self.assertEqual(spph.distroseries, upload.distroseries)
127+ self.assertEqual(PackagePublishingPocket.UPDATES, upload.pocket)
128+
129+ # It contains only the custom files.
130+ self.assertEqual([], list(upload.sources))
131+ self.assertEqual([], list(upload.builds))
132+ self.assertEqual(
133+ [custom_file],
134+ [custom.libraryfilealias for custom in upload.customfiles])
135+
136 def test_findMatchingDSDs_matches_all_DSDs_for_job(self):
137 # findMatchingDSDs finds matching DSDs for any of the packages
138 # in the job.