~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/tests/test_packagecopyjob.py

  • Committer: Jeroen Vermeulen
  • Date: 2011-05-31 13:56:03 UTC
  • mto: (7675.1176.10 db-bug-790761)
  • mto: This revision was merged to the branch mainline in revision 13163.
  • Revision ID: jeroen.vermeulen@canonical.com-20110531135603-090ru9z475939ya6
Move PackageCopyJob package name into db column, add copy_policy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
from lp.soyuz.interfaces.sourcepackageformat import (
34
34
    ISourcePackageFormatSelectionSet,
35
35
    )
36
 
from lp.soyuz.model.packagecopyjob import specify_dsd_package
37
36
from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
38
37
from lp.testing import (
39
38
    run_script,
56
55
        """Create a `PlainPackageCopyJob` that would resolve `dsd`."""
57
56
        if dsd is None:
58
57
            dsd = self.factory.makeDistroSeriesDifference()
59
 
        source_packages = [specify_dsd_package(dsd)]
60
58
        source_archive = dsd.parent_series.main_archive
61
59
        target_archive = dsd.derived_series.main_archive
62
60
        target_distroseries = dsd.derived_series
63
61
        target_pocket = self.factory.getAnyPocket()
64
62
        return getUtility(IPlainPackageCopyJobSource).create(
65
 
            source_packages, source_archive, target_archive,
66
 
            target_distroseries, target_pocket)
 
63
            dsd.source_package_name.name, source_archive, target_archive,
 
64
            target_distroseries, target_pocket,
 
65
            package_version=dsd.parent_source_version)
67
66
 
68
67
    def runJob(self, job):
69
68
        """Helper to switch to the right DB user and run the job."""
84
83
        archive2 = self.factory.makeArchive(distroseries.distribution)
85
84
        source = getUtility(IPlainPackageCopyJobSource)
86
85
        job = source.create(
87
 
            source_packages=[("foo", "1.0-1"), ("bar", "2.4")],
88
 
            source_archive=archive1, target_archive=archive2,
89
 
            target_distroseries=distroseries,
 
86
            package_name="foo", source_archive=archive1,
 
87
            target_archive=archive2, target_distroseries=distroseries,
90
88
            target_pocket=PackagePublishingPocket.RELEASE,
91
 
            include_binaries=False)
 
89
            package_version="1.0-1", include_binaries=False)
92
90
        self.assertProvides(job, IPackageCopyJob)
93
91
        self.assertEquals(archive1.id, job.source_archive_id)
94
92
        self.assertEquals(archive1, job.source_archive)
96
94
        self.assertEquals(archive2, job.target_archive)
97
95
        self.assertEquals(distroseries, job.target_distroseries)
98
96
        self.assertEquals(PackagePublishingPocket.RELEASE, job.target_pocket)
99
 
        self.assertContentEqual(
100
 
            job.source_packages,
101
 
            [("foo", "1.0-1", None), ("bar", "2.4", None)])
 
97
        self.assertEqual("foo", job.package_name)
 
98
        self.assertEqual("1.0-1", job.package_version)
102
99
        self.assertEquals(False, job.include_binaries)
103
100
 
104
101
    def test_getActiveJobs(self):
108
105
        archive2 = self.factory.makeArchive(distroseries.distribution)
109
106
        source = getUtility(IPlainPackageCopyJobSource)
110
107
        job = source.create(
111
 
            source_packages=[("foo", "1.0-1")], source_archive=archive1,
 
108
            package_name="foo", source_archive=archive1,
112
109
            target_archive=archive2, target_distroseries=distroseries,
113
110
            target_pocket=PackagePublishingPocket.RELEASE,
114
 
            include_binaries=False)
 
111
            package_version="1.0-1", include_binaries=False)
115
112
        self.assertContentEqual([job], source.getActiveJobs(archive2))
116
113
 
117
114
    def test_getActiveJobs_gets_oldest_first(self):
167
164
        archive2 = self.factory.makeArchive(distroseries.distribution)
168
165
        job_source = getUtility(IPlainPackageCopyJobSource)
169
166
        job = job_source.create(
170
 
            source_packages=[("foo", "1.0-1")], source_archive=archive1,
 
167
            package_name="foo", source_archive=archive1,
171
168
            target_archive=archive2, target_distroseries=distroseries,
172
169
            target_pocket=PackagePublishingPocket.RELEASE,
173
 
            include_binaries=False)
 
170
            package_version="1.0-1", include_binaries=False)
174
171
        naked_job = removeSecurityProxy(job)
175
172
        naked_job.reportFailure = FakeMethod()
176
173
 
181
178
    def test_target_ppa_non_release_pocket(self):
182
179
        # When copying to a PPA archive the target must be the release pocket.
183
180
        distroseries = self.factory.makeDistroSeries()
 
181
        package = self.factory.makeSourcePackageName()
184
182
        archive1 = self.factory.makeArchive(distroseries.distribution)
185
183
        archive2 = self.factory.makeArchive(distroseries.distribution)
186
184
        source = getUtility(IPlainPackageCopyJobSource)
187
185
        job = source.create(
188
 
            source_packages=[], source_archive=archive1,
 
186
            package_name=package.name, source_archive=archive1,
189
187
            target_archive=archive2, target_distroseries=distroseries,
190
188
            target_pocket=PackagePublishingPocket.UPDATES,
191
 
            include_binaries=False)
 
189
            include_binaries=False, package_version='1.0')
192
190
 
193
191
        naked_job = removeSecurityProxy(job)
194
192
        naked_job.reportFailure = FakeMethod()
218
216
        getUtility(ISourcePackageFormatSelectionSet).add(
219
217
            target_series, SourcePackageFormat.FORMAT_1_0)
220
218
 
221
 
        source_package = publisher.getPubSource(
 
219
        publisher.getPubSource(
222
220
            distroseries=distroseries, sourcename="libc",
223
221
            version="2.8-1", status=PackagePublishingStatus.PUBLISHED,
224
222
            archive=breezy_archive)
225
223
 
226
224
        source = getUtility(IPlainPackageCopyJobSource)
227
225
        job = source.create(
228
 
            source_packages=[("libc", "2.8-1")],
 
226
            package_name="libc",
229
227
            source_archive=breezy_archive, target_archive=target_archive,
230
228
            target_distroseries=target_series,
231
229
            target_pocket=PackagePublishingPocket.RELEASE,
232
 
            include_binaries=False)
233
 
        self.assertContentEqual(
234
 
            job.source_packages, [("libc", "2.8-1", source_package)])
 
230
            package_version="2.8-1", include_binaries=False)
 
231
        self.assertEqual("libc", job.package_name)
 
232
        self.assertEqual("2.8-1", job.package_version)
235
233
 
236
234
        # Make sure everything hits the database, switching db users
237
235
        # aborts.
256
254
        archive2 = self.factory.makeArchive(distroseries.distribution)
257
255
        source = getUtility(IPlainPackageCopyJobSource)
258
256
        job = source.create(
259
 
            source_packages=[("foo", "1.0-1")], source_archive=archive1,
 
257
            package_name="foo", source_archive=archive1,
260
258
            target_archive=archive2, target_distroseries=distroseries,
261
259
            target_pocket=PackagePublishingPocket.RELEASE,
262
 
            include_binaries=False)
 
260
            package_version="1.0-1", include_binaries=False)
263
261
        oops_vars = job.getOopsVars()
264
262
        naked_job = removeSecurityProxy(job)
265
263
        self.assertIn(
285
283
            version="2.8-1", status=PackagePublishingStatus.PUBLISHED,
286
284
            archive=archive1)
287
285
        getUtility(IPlainPackageCopyJobSource).create(
288
 
            source_packages=[("libc", "2.8-1")], source_archive=archive1,
 
286
            package_name="libc", source_archive=archive1,
289
287
            target_archive=archive2, target_distroseries=distroseries,
290
288
            target_pocket=PackagePublishingPocket.RELEASE,
291
 
            include_binaries=False)
 
289
            package_version="2.8-1", include_binaries=False)
292
290
        transaction.commit()
293
291
 
294
292
        out, err, exit_code = run_script(
309
307
        archive2 = self.factory.makeArchive(distroseries.distribution)
310
308
        source = getUtility(IPlainPackageCopyJobSource)
311
309
        job = source.create(
312
 
            source_packages=[("foo", "1.0-1"), ("bar", "2.4")],
313
 
            source_archive=archive1, target_archive=archive2,
314
 
            target_distroseries=distroseries,
 
310
            package_name="foo", source_archive=archive1,
 
311
            target_archive=archive2, target_distroseries=distroseries,
315
312
            target_pocket=PackagePublishingPocket.RELEASE,
316
 
            include_binaries=True)
 
313
            package_version="1.0-1", include_binaries=True)
317
314
        self.assertEqual(
318
 
            ("<PlainPackageCopyJob to copy 2 package(s) from "
 
315
            ("<PlainPackageCopyJob to copy package foo from "
319
316
             "{distroseries.distribution.name}/{archive1.name} to "
320
317
             "{distroseries.distribution.name}/{archive2.name}, "
321
318
             "RELEASE pocket, in {distroseries.distribution.name} "
331
328
        job = self.makeJob(dsd)
332
329
        job_source = getUtility(IPlainPackageCopyJobSource)
333
330
        self.assertEqual(
334
 
            {specify_dsd_package(dsd): job},
 
331
            {dsd.source_package_name.name: job},
335
332
            job_source.getPendingJobsPerPackage(dsd.derived_series))
336
333
 
337
334
    def test_getPendingJobsPerPackage_ignores_other_distroseries(self):
347
344
        # getPendingJobsPerPackage ignores jobs that have already been
348
345
        # run.
349
346
        dsd = self.factory.makeDistroSeriesDifference()
350
 
        package = specify_dsd_package(dsd)
351
347
        job = self.makeJob(dsd)
352
348
        job_source = getUtility(IPlainPackageCopyJobSource)
353
349
        found_by_state = {}
355
351
            removeSecurityProxy(job).job._status = status
356
352
            result = job_source.getPendingJobsPerPackage(dsd.derived_series)
357
353
            if len(result) > 0:
358
 
                found_by_state[status] = result[package]
 
354
                found_by_state[status] = result[dsd.source_package_name.name]
359
355
        expected = {
360
356
            JobStatus.WAITING: job,
361
357
            JobStatus.RUNNING: job,
374
370
        jobs = map(self.makeJob, dsds)
375
371
        job_source = getUtility(IPlainPackageCopyJobSource)
376
372
        self.assertEqual(
377
 
            dict(zip(map(specify_dsd_package, dsds), jobs)),
 
373
            dict(zip([dsd.source_package_name.name for dsd in dsds], jobs)),
378
374
            job_source.getPendingJobsPerPackage(derived_series))
379
375
 
380
376
    def test_getPendingJobsPerPackage_picks_oldest_job_for_dsd(self):
384
380
        jobs = [self.makeJob(dsd) for counter in xrange(2)]
385
381
        job_source = getUtility(IPlainPackageCopyJobSource)
386
382
        self.assertEqual(
387
 
            {specify_dsd_package(dsd): jobs[0]},
 
383
            {dsd.source_package_name.name: jobs[0]},
388
384
            job_source.getPendingJobsPerPackage(dsd.derived_series))
389
385
 
390
386
    def test_getPendingJobsPerPackage_ignores_dsds_without_jobs(self):