~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[rs=buildbot-poller] automatic merge from stable. Revisions: 13201,
        13202, 13203, 13204, 13205 included.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
    )
11
11
import doctest
12
12
 
13
 
from testtools.matchers import DocTestMatches
 
13
from testtools.matchers import DocTestMatches, MatchesRegex
 
14
from testtools.testcase import ExpectedException
 
15
 
14
16
import transaction
15
17
from zope.component import getUtility
16
18
from zope.security.interfaces import Unauthorized
48
50
    PackagePublishingStatus,
49
51
    )
50
52
from lp.soyuz.interfaces.archive import (
 
53
    ArchiveDependencyError,
51
54
    ArchiveDisabled,
52
55
    CannotRestrictArchitectures,
53
56
    CannotUploadToPocket,
223
226
        # Calling series_with_sources returns all series with publishings.
224
227
        distribution = self.factory.makeDistribution()
225
228
        archive = self.factory.makeArchive(distribution=distribution)
226
 
        series_with_no_sources = self.factory.makeDistroSeries(
 
229
        self.factory.makeDistroSeries(
227
230
            distribution=distribution, version="0.5")
228
231
        series_with_sources1 = self.factory.makeDistroSeries(
229
232
            distribution=distribution, version="1")
283
286
                source_package_release=sourcepackagerelease,
284
287
                archive=archive, status=status)
285
288
            sprs.append(sourcepackagerelease)
286
 
        unlinked_spr = self.factory.makeSourcePackageRelease()
 
289
        self.factory.makeSourcePackageRelease()
287
290
        return archive, sprs
288
291
 
289
292
    def test_getSourcePackageReleases_with_no_params(self):
425
428
        other_spn = self.factory.makeSourcePackageName(name="bar")
426
429
        archive = self.factory.makeArchive()
427
430
        self.makePublishedSources(archive,
428
 
            [PackagePublishingStatus.PUBLISHED]*3,
 
431
            [PackagePublishingStatus.PUBLISHED] * 3,
429
432
            ["1.0", "1.1", "2.0"],
430
433
            [sourcepackagename, sourcepackagename, other_spn])
431
434
        pubs = removeSecurityProxy(archive)._collectLatestPublishedSources(
1299
1302
        self.assertTrue(self.archive.build_debug_symbols)
1300
1303
 
1301
1304
 
 
1305
class TestAddArchiveDependencies(TestCaseWithFactory):
 
1306
 
 
1307
    layer = DatabaseFunctionalLayer
 
1308
 
 
1309
    def test_add_hidden_dependency(self):
 
1310
        # The user cannot add a dependency on an archive they cannot see.
 
1311
        archive = self.factory.makeArchive(private=True)
 
1312
        dependency = self.factory.makeArchive(private=True)
 
1313
        with person_logged_in(archive.owner):
 
1314
            with ExpectedException(
 
1315
                ArchiveDependencyError,
 
1316
                "You don't have permission to use this dependency."):
 
1317
                archive.addArchiveDependency(dependency, 'foo')
 
1318
 
 
1319
    def test_private_dependency_public_archive(self):
 
1320
        # A public archive may not depend on a private archive.
 
1321
        archive = self.factory.makeArchive()
 
1322
        dependency = self.factory.makeArchive(
 
1323
            private=True, owner=archive.owner)
 
1324
        with person_logged_in(archive.owner):
 
1325
            with ExpectedException(
 
1326
                ArchiveDependencyError,
 
1327
                "Public PPAs cannot depend on private ones."):
 
1328
                archive.addArchiveDependency(dependency, 'foo')
 
1329
 
 
1330
    def test_add_private_dependency(self):
 
1331
        # The user can add a dependency on private archive they can see.
 
1332
        archive = self.factory.makeArchive(private=True)
 
1333
        dependency = self.factory.makeArchive(
 
1334
            private=True, owner=archive.owner)
 
1335
        with person_logged_in(archive.owner):
 
1336
            archive_dependency = archive.addArchiveDependency(dependency,
 
1337
                PackagePublishingPocket.RELEASE)
 
1338
            self.assertContentEqual(
 
1339
                archive.dependencies, [archive_dependency])
 
1340
 
 
1341
 
 
1342
class TestArchiveDependencies(TestCaseWithFactory):
 
1343
 
 
1344
    layer = LaunchpadZopelessLayer
 
1345
 
 
1346
    def test_private_sources_list(self):
 
1347
        """Entries for private dependencies include credentials."""
 
1348
        p3a = self.factory.makeArchive(name='p3a', private=True)
 
1349
        dependency = self.factory.makeArchive(
 
1350
            name='dependency', private=True, owner=p3a.owner)
 
1351
        with person_logged_in(p3a.owner):
 
1352
            bpph = self.factory.makeBinaryPackagePublishingHistory(
 
1353
                archive=dependency, status=PackagePublishingStatus.PUBLISHED)
 
1354
            p3a.addArchiveDependency(dependency,
 
1355
                PackagePublishingPocket.RELEASE)
 
1356
            build = self.factory.makeBinaryPackageBuild(archive=p3a,
 
1357
                distroarchseries=bpph.distroarchseries)
 
1358
            sources_list = get_sources_list_for_building(
 
1359
                build, build.distro_arch_series,
 
1360
                build.source_package_release.name)
 
1361
            sources_list_str = '\n'.join(sources_list)
 
1362
            matches = MatchesRegex(
 
1363
                "deb http://buildd:sekrit@private-ppa.launchpad.dev/"
 
1364
                "person-name-.*/dependency/ubuntu distroseries-.* main")
 
1365
            self.assertThat(sources_list[0], matches)
 
1366
 
 
1367
 
1302
1368
class TestFindDepCandidates(TestCaseWithFactory):
1303
1369
    """Tests for Archive.findDepCandidates."""
1304
1370
 
1346
1412
 
1347
1413
    def test_does_not_find_pending_publication(self):
1348
1414
        # A pending candidate in the same archive should not be found.
1349
 
        bins = self.publisher.getPubBinaries(
 
1415
        self.publisher.getPubBinaries(
1350
1416
            binaryname='foo', archive=self.archive)
1351
1417
        self.assertDep('i386', 'foo', [])
1352
1418
 
1572
1638
    def test_two_ppas_with_team(self):
1573
1639
        team = self.factory.makeTeam(
1574
1640
            subscription_policy=TeamSubscriptionPolicy.MODERATED)
1575
 
        ppa = self.factory.makeArchive(owner=team, name='ppa')
 
1641
        self.factory.makeArchive(owner=team, name='ppa')
1576
1642
        self.assertEqual("%s already has a PPA named 'ppa'." % (
1577
1643
            team.displayname), Archive.validatePPA(team, 'ppa'))
1578
1644