1966
1998
ubuntu.main_archive.getPublishedSources(
1967
1999
name=source.source_package_name).count())
2001
def _setup_copy_data(self, target_purpose=None):
2002
if target_purpose is None:
2003
target_purpose = ArchivePurpose.PPA
2004
source_archive = self.factory.makeArchive()
2005
target_archive = self.factory.makeArchive(purpose=target_purpose)
2006
source = self.factory.makeSourcePackagePublishingHistory(
2007
archive=source_archive, status=PackagePublishingStatus.PUBLISHED)
2008
source_name = source.source_package_name
2009
version = source.source_package_version
2010
to_pocket = PackagePublishingPocket.RELEASE
2011
to_series = self.factory.makeDistroSeries(
2012
distribution=target_archive.distribution)
2013
return (source, source_archive, source_name, target_archive,
2014
to_pocket, to_series, version)
2016
def test_copyPackage_creates_packagecopyjob(self):
2017
# The copyPackage method should create a PCJ with the appropriate
2019
(source, source_archive, source_name, target_archive, to_pocket,
2020
to_series, version) = self._setup_copy_data()
2021
with person_logged_in(target_archive.owner):
2022
target_archive.copyPackage(
2023
source_name, version, source_archive, to_pocket.name,
2024
to_series=to_series.name, include_binaries=False,
2025
person=target_archive.owner)
2027
# The source should not be published yet in the target_archive.
2028
published = target_archive.getPublishedSources(
2029
name=source.source_package_name).any()
2030
self.assertIs(None, published)
2032
# There should be one copy job.
2033
job_source = getUtility(IPlainPackageCopyJobSource)
2034
copy_job = job_source.getActiveJobs(target_archive).one()
2036
# Its data should reflect the requested copy.
2037
self.assertEqual(source_name, copy_job.package_name)
2038
self.assertEqual(version, copy_job.package_version)
2039
self.assertEqual(target_archive, copy_job.target_archive)
2040
self.assertEqual(source_archive, copy_job.source_archive)
2041
self.assertEqual(to_series, copy_job.target_distroseries)
2042
self.assertEqual(to_pocket, copy_job.target_pocket)
2043
self.assertFalse(copy_job.include_binaries)
2044
self.assertEquals(PackageCopyPolicy.INSECURE, copy_job.copy_policy)
2046
def test_copyPackage_disallows_non_primary_archive_uploaders(self):
2047
# If copying to a primary archive and you're not an uploader for
2048
# the package then you can't copy.
2049
(source, source_archive, source_name, target_archive, to_pocket,
2050
to_series, version) = self._setup_copy_data(
2051
target_purpose=ArchivePurpose.PRIMARY)
2052
person = self.factory.makePerson()
2055
target_archive.copyPackage, source_name, version, source_archive,
2056
to_pocket.name, to_series=to_series.name, include_binaries=False,
2059
def test_copyPackage_allows_primary_archive_uploaders(self):
2060
# Copying to a primary archive if you're already an uploader is OK.
2061
(source, source_archive, source_name, target_archive, to_pocket,
2062
to_series, version) = self._setup_copy_data(
2063
target_purpose=ArchivePurpose.PRIMARY)
2064
person = self.factory.makePerson()
2065
with person_logged_in(target_archive.owner):
2066
target_archive.newComponentUploader(person, "universe")
2067
target_archive.copyPackage(
2068
source_name, version, source_archive, to_pocket.name,
2069
to_series=to_series.name, include_binaries=False,
2072
# There should be one copy job.
2073
job_source = getUtility(IPlainPackageCopyJobSource)
2074
copy_job = job_source.getActiveJobs(target_archive).one()
2075
self.assertEqual(target_archive, copy_job.target_archive)
2077
def test_copyPackage_disallows_non_PPA_owners(self):
2078
# Only people with launchpad.Append are allowed to call copyPackage.
2079
(source, source_archive, source_name, target_archive, to_pocket,
2080
to_series, version) = self._setup_copy_data()
2081
person = self.factory.makePerson()
2082
self.assertTrue(target_archive.is_ppa)
2085
target_archive.copyPackage, source_name, version, source_archive,
2086
to_pocket.name, to_series=to_series.name, include_binaries=False,
2089
def test_copyPackage_disallows_non_release_target_pocket_for_PPA(self):
2090
(source, source_archive, source_name, target_archive, to_pocket,
2091
to_series, version) = self._setup_copy_data()
2092
to_pocket = PackagePublishingPocket.UPDATES
2093
self.assertTrue(target_archive.is_ppa)
2096
target_archive.copyPackage, source_name, version, source_archive,
2097
to_pocket.name, to_series=to_series.name, include_binaries=False,
2098
person=target_archive.owner)
2100
def test_copyPackages_with_single_package(self):
2101
(source, source_archive, source_name, target_archive, to_pocket,
2102
to_series, version) = self._setup_copy_data()
2104
with person_logged_in(target_archive.owner):
2105
target_archive.copyPackages(
2106
[source_name], source_archive, to_pocket.name,
2107
to_series=to_series.name, include_binaries=False,
2108
person=target_archive.owner)
2110
# The source should not be published yet in the target_archive.
2111
published = target_archive.getPublishedSources(
2112
name=source.source_package_name).any()
2113
self.assertIs(None, published)
2115
# There should be one copy job.
2116
job_source = getUtility(IPlainPackageCopyJobSource)
2117
copy_job = job_source.getActiveJobs(target_archive).one()
2118
self.assertEqual(target_archive, copy_job.target_archive)
2120
def test_copyPackages_with_multiple_packages(self):
2121
(source, source_archive, source_name, target_archive, to_pocket,
2122
to_series, version) = self._setup_copy_data()
2124
sources.append(self.factory.makeSourcePackagePublishingHistory(
2125
archive=source_archive,
2126
status=PackagePublishingStatus.PUBLISHED))
2127
sources.append(self.factory.makeSourcePackagePublishingHistory(
2128
archive=source_archive,
2129
status=PackagePublishingStatus.PUBLISHED))
2130
names = [source.sourcepackagerelease.sourcepackagename.name
2131
for source in sources]
2133
with person_logged_in(target_archive.owner):
2134
target_archive.copyPackages(
2135
names, source_archive, to_pocket.name,
2136
to_series=to_series.name, include_binaries=False,
2137
person=target_archive.owner)
2139
# Make sure three copy jobs exist.
2140
job_source = getUtility(IPlainPackageCopyJobSource)
2141
copy_jobs = job_source.getActiveJobs(target_archive)
2142
self.assertEqual(3, copy_jobs.count())
2144
def test_copyPackages_disallows_non_primary_archive_uploaders(self):
2145
# If copying to a primary archive and you're not an uploader for
2146
# the package then you can't copy.
2147
(source, source_archive, source_name, target_archive, to_pocket,
2148
to_series, version) = self._setup_copy_data(
2149
target_purpose=ArchivePurpose.PRIMARY)
2150
person = self.factory.makePerson()
2153
target_archive.copyPackages, [source_name], source_archive,
2154
to_pocket.name, to_series=to_series.name, include_binaries=False,
2157
def test_copyPackages_allows_primary_archive_uploaders(self):
2158
# Copying to a primary archive if you're already an uploader is OK.
2159
(source, source_archive, source_name, target_archive, to_pocket,
2160
to_series, version) = self._setup_copy_data(
2161
target_purpose=ArchivePurpose.PRIMARY)
2162
person = self.factory.makePerson()
2163
with person_logged_in(target_archive.owner):
2164
target_archive.newComponentUploader(person, "universe")
2165
target_archive.copyPackages(
2166
[source_name], source_archive, to_pocket.name,
2167
to_series=to_series.name, include_binaries=False,
2170
# There should be one copy job.
2171
job_source = getUtility(IPlainPackageCopyJobSource)
2172
copy_job = job_source.getActiveJobs(target_archive).one()
2173
self.assertEqual(target_archive, copy_job.target_archive)
2175
def test_copyPackages_disallows_non_PPA_owners(self):
2176
# Only people with launchpad.Append are allowed to call copyPackage.
2177
(source, source_archive, source_name, target_archive, to_pocket,
2178
to_series, version) = self._setup_copy_data()
2179
person = self.factory.makePerson()
2180
self.assertTrue(target_archive.is_ppa)
2183
target_archive.copyPackages, [source_name], source_archive,
2184
to_pocket.name, to_series=to_series.name, include_binaries=False,