~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Julian Edwards
  • Date: 2011-07-14 15:54:26 UTC
  • mto: This revision was merged to the branch mainline in revision 13459.
  • Revision ID: julian.edwards@canonical.com-20110714155426-x3p8hr4iyh02xbdf
Loads more test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2088
2088
        copy_job = job_source.getActiveJobs(target_archive).one()
2089
2089
        self.assertEqual(target_archive, copy_job.target_archive)
2090
2090
 
 
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()
 
2094
        sources = [source]
 
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]
 
2103
 
 
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)
 
2109
 
 
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())
 
2114
 
 
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()
 
2122
        self.assertRaises(
 
2123
            CannotCopy,
 
2124
            target_archive.copyPackages, [source_name], source_archive,
 
2125
            to_pocket.name, to_series=to_series.name, include_binaries=False,
 
2126
            person=person)
 
2127
 
 
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,
 
2139
            person=person)
 
2140
 
 
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)
 
2145
 
 
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)
 
2152
        self.assertRaises(
 
2153
            CannotCopy,
 
2154
            target_archive.copyPackages, [source_name], source_archive,
 
2155
            to_pocket.name, to_series=to_series.name, include_binaries=False,
 
2156
            person=person)
 
2157