2088
2088
copy_job = job_source.getActiveJobs(target_archive).one()
2089
2089
self.assertEqual(target_archive, copy_job.target_archive)
2091
def test_copyPackages_with_multiple_packages(self):
2092
(source, source_archive, source_name, target_archive, to_pocket,
2093
to_series, version) = self._setup_copy_data()
2095
sources.append(self.factory.makeSourcePackagePublishingHistory(
2096
archive=source_archive,
2097
status=PackagePublishingStatus.PUBLISHED))
2098
sources.append(self.factory.makeSourcePackagePublishingHistory(
2099
archive=source_archive,
2100
status=PackagePublishingStatus.PUBLISHED))
2101
names = [source.sourcepackagerelease.sourcepackagename.name
2102
for source in sources]
2104
with person_logged_in(target_archive.owner):
2105
target_archive.copyPackages(
2106
names, source_archive, to_pocket.name,
2107
to_series=to_series.name, include_binaries=False,
2108
person=target_archive.owner)
2110
# Make sure three copy jobs exist.
2111
job_source = getUtility(IPlainPackageCopyJobSource)
2112
copy_jobs = job_source.getActiveJobs(target_archive)
2113
self.assertEqual(3, copy_jobs.count())
2115
def test_copyPackages_disallows_non_primary_archive_uploaders(self):
2116
# If copying to a primary archive and you're not an uploader for
2117
# the package then you can't copy.
2118
(source, source_archive, source_name, target_archive, to_pocket,
2119
to_series, version) = self._setup_copy_data(
2120
target_purpose=ArchivePurpose.PRIMARY)
2121
person = self.factory.makePerson()
2124
target_archive.copyPackages, [source_name], source_archive,
2125
to_pocket.name, to_series=to_series.name, include_binaries=False,
2128
def test_copyPackages_allows_primary_archive_uploaders(self):
2129
# Copying to a primary archive if you're already an uploader is OK.
2130
(source, source_archive, source_name, target_archive, to_pocket,
2131
to_series, version) = self._setup_copy_data(
2132
target_purpose=ArchivePurpose.PRIMARY)
2133
person = self.factory.makePerson()
2134
with person_logged_in(target_archive.owner):
2135
target_archive.newComponentUploader(person, "universe")
2136
target_archive.copyPackages(
2137
[source_name], source_archive, to_pocket.name,
2138
to_series=to_series.name, include_binaries=False,
2141
# There should be one copy job.
2142
job_source = getUtility(IPlainPackageCopyJobSource)
2143
copy_job = job_source.getActiveJobs(target_archive).one()
2144
self.assertEqual(target_archive, copy_job.target_archive)
2146
def test_copyPackages_disallows_non_PPA_owners(self):
2147
# Only people with launchpad.Append are allowed to call copyPackage.
2148
(source, source_archive, source_name, target_archive, to_pocket,
2149
to_series, version) = self._setup_copy_data()
2150
person = self.factory.makePerson()
2151
self.assertTrue(target_archive.is_ppa)
2154
target_archive.copyPackages, [source_name], source_archive,
2155
to_pocket.name, to_series=to_series.name, include_binaries=False,