def test_distributionsourcepackage_to_sourcepackagename(self):
     # A sourcepackagename can be retrieved distribution source package.
     package = self.factory.makeDistributionSourcePackage()
     spn = package_to_sourcepackagename(package)
     self.assertTrue(ISourcePackageName.providedBy(spn))
     self.assertEqual(package.sourcepackagename,
                      ISourcePackageName(package))
 def test_distributionsourcepackage_to_sourcepackagename(self):
     # A sourcepackagename can be retrieved distribution source package.
     package = self.factory.makeDistributionSourcePackage()
     spn = package_to_sourcepackagename(package)
     self.assertTrue(ISourcePackageName.providedBy(spn))
     self.assertEqual(
         package.sourcepackagename, ISourcePackageName(package))
Example #3
0
    def checkAuthenticated(self,
                           person,
                           archive,
                           permission,
                           item,
                           distroseries=None):
        """See `IArchivePermissionSet`."""
        clauses = [
            """
            ArchivePermission.archive = %s AND
            ArchivePermission.permission = %s AND
            ArchivePermission.person = TeamParticipation.team AND
            TeamParticipation.person = %s
            """ % sqlvalues(archive, permission, person)
        ]

        prejoins = []

        if IComponent.providedBy(item):
            clauses.append("ArchivePermission.component = %s" %
                           sqlvalues(item))
            prejoins.append("component")
        elif ISourcePackageName.providedBy(item):
            clauses.append("ArchivePermission.sourcepackagename = %s" %
                           sqlvalues(item))
            prejoins.append("sourcepackagename")
        elif IPackageset.providedBy(item):
            clauses.append("ArchivePermission.packageset = %s" %
                           sqlvalues(item.id))
            prejoins.append("packageset")
        elif (zope_isinstance(item, DBItem)
              and item.enum.name == "PackagePublishingPocket"):
            clauses.append("ArchivePermission.pocket = %s" % sqlvalues(item))
            if distroseries is not None:
                clauses.append("(ArchivePermission.distroseries IS NULL OR "
                               "ArchivePermission.distroseries = %s)" %
                               sqlvalues(distroseries))
                prejoins.append("distroseries")
        else:
            raise AssertionError(
                "'item' %r is not an IComponent, IPackageset, "
                "ISourcePackageName or PackagePublishingPocket" % item)

        query = " AND ".join(clauses)
        auth = ArchivePermission.select(query,
                                        clauseTables=["TeamParticipation"],
                                        prejoins=prejoins)

        return auth
    def checkAuthenticated(self, person, archive, permission, item,
                           distroseries=None):
        """See `IArchivePermissionSet`."""
        clauses = ["""
            ArchivePermission.archive = %s AND
            ArchivePermission.permission = %s AND
            ArchivePermission.person = TeamParticipation.team AND
            TeamParticipation.person = %s
            """ % sqlvalues(archive, permission, person)]

        prejoins = []

        if IComponent.providedBy(item):
            clauses.append(
                "ArchivePermission.component = %s" % sqlvalues(item))
            prejoins.append("component")
        elif ISourcePackageName.providedBy(item):
            clauses.append(
                "ArchivePermission.sourcepackagename = %s" % sqlvalues(item))
            prejoins.append("sourcepackagename")
        elif IPackageset.providedBy(item):
            clauses.append(
                "ArchivePermission.packageset = %s" % sqlvalues(item.id))
            prejoins.append("packageset")
        elif (zope_isinstance(item, DBItem) and
              item.enum.name == "PackagePublishingPocket"):
            clauses.append("ArchivePermission.pocket = %s" % sqlvalues(item))
            if distroseries is not None:
                clauses.append(
                    "(ArchivePermission.distroseries IS NULL OR "
                     "ArchivePermission.distroseries = %s)" %
                    sqlvalues(distroseries))
                prejoins.append("distroseries")
        else:
            raise AssertionError(
                "'item' %r is not an IComponent, IPackageset, "
                "ISourcePackageName or PackagePublishingPocket" % item)

        query = " AND ".join(clauses)
        auth = ArchivePermission.select(
            query, clauseTables=["TeamParticipation"],
            prejoins=prejoins)

        return auth