def test_package_copying(self):
        import copy

        pkg_a = cr.Package()
        pkg_a.name = "FooPackage"
        pkg_b = pkg_a
        self.assertEqual(id(pkg_a), id(pkg_b))
        pkg_c = copy.copy(pkg_a)
        self.assertFalse(id(pkg_a) == id(pkg_c))
        pkg_d = copy.deepcopy(pkg_a)
        self.assertFalse(id(pkg_a) == id(pkg_d))
        self.assertFalse(id(pkg_c) == id(pkg_d))

        # Next lines should not fail (if copy really works)
        del (pkg_a)
        del (pkg_b)
        self.assertEqual(pkg_c.name, "FooPackage")
        del (pkg_c)
        self.assertEqual(pkg_d.name, "FooPackage")
        del (pkg_d)
Example #2
0
 def newpkgcb(pkgId, name, arch):
     pkg = cr.Package()
     userdata["pkgs"].append(pkg)
     return pkg
Example #3
0
 def newpkgcb(pkgId, name, arch):
     return cr.Package()
Example #4
0
    def to_createrepo_c(self):
        """
        Convert Package object to a createrepo_c package object.

        Currently it works under assumption that Package attributes' names are exactly the same
        as createrepo_c ones.

        Returns:
            createrepo_c.Package: package itself in a format of a createrepo_c package object

        """
        def list_to_createrepo_c(l):
            """
            Convert list to createrepo_c format.

            Createrepo_c expects list of tuples, not list of lists.
            The assumption is that there are no nested lists, which is true for the data on the
            Package model at the moment.

            Args:
                l(list): a list

            Returns:
                list: list of strings and/or tuples

            """
            createrepo_c_list = []
            for item in l:
                if isinstance(item, list):
                    createrepo_c_list.append(tuple(item))
                else:
                    createrepo_c_list.append(item)

            return createrepo_c_list

        package = cr.Package()
        package.arch = getattr(self, PULP_PACKAGE_ATTRS.ARCH)
        package.changelogs = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.CHANGELOGS))
        package.checksum_type = getattr(self, PULP_PACKAGE_ATTRS.CHECKSUM_TYPE)
        package.conflicts = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.CONFLICTS))
        package.description = getattr(self, PULP_PACKAGE_ATTRS.DESCRIPTION)
        package.enhances = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.ENHANCES))
        package.epoch = getattr(self, PULP_PACKAGE_ATTRS.EPOCH)
        package.files = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.FILES))
        package.location_base = getattr(self, PULP_PACKAGE_ATTRS.LOCATION_BASE)
        package.location_href = getattr(self, PULP_PACKAGE_ATTRS.LOCATION_HREF)
        package.name = getattr(self, PULP_PACKAGE_ATTRS.NAME)
        package.obsoletes = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.OBSOLETES))
        package.pkgId = getattr(self, PULP_PACKAGE_ATTRS.PKGID)
        package.provides = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.PROVIDES))
        package.recommends = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.RECOMMENDS))
        package.release = getattr(self, PULP_PACKAGE_ATTRS.RELEASE)
        package.requires = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.REQUIRES))
        package.rpm_buildhost = getattr(self, PULP_PACKAGE_ATTRS.RPM_BUILDHOST)
        package.rpm_group = getattr(self, PULP_PACKAGE_ATTRS.RPM_GROUP)
        package.rpm_header_end = getattr(self,
                                         PULP_PACKAGE_ATTRS.RPM_HEADER_END)
        package.rpm_header_start = getattr(self,
                                           PULP_PACKAGE_ATTRS.RPM_HEADER_START)
        package.rpm_license = getattr(self, PULP_PACKAGE_ATTRS.RPM_LICENSE)
        package.rpm_packager = getattr(self, PULP_PACKAGE_ATTRS.RPM_PACKAGER)
        package.rpm_sourcerpm = getattr(self, PULP_PACKAGE_ATTRS.RPM_SOURCERPM)
        package.rpm_vendor = getattr(self, PULP_PACKAGE_ATTRS.RPM_VENDOR)
        package.size_archive = getattr(self, PULP_PACKAGE_ATTRS.SIZE_ARCHIVE)
        package.size_installed = getattr(self,
                                         PULP_PACKAGE_ATTRS.SIZE_INSTALLED)
        package.size_package = getattr(self, PULP_PACKAGE_ATTRS.SIZE_PACKAGE)
        package.suggests = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.SUGGESTS))
        package.summary = getattr(self, PULP_PACKAGE_ATTRS.SUMMARY)
        package.supplements = list_to_createrepo_c(
            getattr(self, PULP_PACKAGE_ATTRS.SUPPLEMENTS))
        package.time_build = getattr(self, PULP_PACKAGE_ATTRS.TIME_BUILD)
        package.time_file = getattr(self, PULP_PACKAGE_ATTRS.TIME_FILE)
        package.url = getattr(self, PULP_PACKAGE_ATTRS.URL)
        package.version = getattr(self, PULP_PACKAGE_ATTRS.VERSION)

        return package
Example #5
0
 def test_pkg_id_str_01(self):
     pkg = cr.Package()
     idstr = pkg_id_str(pkg)
     self.assertEqual(idstr, "")
    def test_package_setters(self):
        pkg = cr.Package()
        self.assertTrue(pkg)

        pkg.pkgId = "foo"
        self.assertEqual(pkg.pkgId, "foo")
        pkg.name = "bar"
        self.assertEqual(pkg.name, "bar")
        pkg.arch = "quantum"
        self.assertEqual(pkg.arch, "quantum")
        pkg.version = "11"
        self.assertEqual(pkg.version, "11")
        pkg.epoch = "22"
        self.assertEqual(pkg.epoch, "22")
        pkg.release = "33"
        self.assertEqual(pkg.release, "33")
        pkg.summary = "sum"
        self.assertEqual(pkg.summary, "sum")
        pkg.description = "desc"
        self.assertEqual(pkg.description, "desc")
        pkg.url = "http://foo"
        self.assertEqual(pkg.url, "http://foo")
        pkg.time_file = 111
        self.assertEqual(pkg.time_file, 111)
        pkg.time_build = 112
        self.assertEqual(pkg.time_build, 112)
        pkg.rpm_license = "EULA"
        self.assertEqual(pkg.rpm_license, "EULA")
        pkg.rpm_vendor = "Me"
        self.assertEqual(pkg.rpm_vendor, "Me")
        pkg.rpm_group = "a-team"
        self.assertEqual(pkg.rpm_group, "a-team")
        pkg.rpm_buildhost = "hal3000.space"
        self.assertEqual(pkg.rpm_buildhost, "hal3000.space")
        pkg.rpm_sourcerpm = "source.src.rpm"
        self.assertEqual(pkg.rpm_sourcerpm, "source.src.rpm")
        pkg.rpm_header_start = 1
        self.assertEqual(pkg.rpm_header_start, 1)
        pkg.rpm_header_end = 2
        self.assertEqual(pkg.rpm_header_end, 2)
        pkg.rpm_packager = "Arnold Rimmer"
        self.assertEqual(pkg.rpm_packager, "Arnold Rimmer")
        pkg.size_package = 33
        self.assertEqual(pkg.size_package, 33)
        pkg.size_installed = 44
        self.assertEqual(pkg.size_installed, 44)
        pkg.size_archive = 55
        self.assertEqual(pkg.size_archive, 55)
        pkg.location_href = "package/foo.rpm"
        self.assertEqual(pkg.location_href, "package/foo.rpm")
        pkg.location_base = "file://dir/"
        self.assertEqual(pkg.location_base, "file://dir/")
        pkg.checksum_type = "crc"
        self.assertEqual(pkg.checksum_type, "crc")

        pkg.requires = [('bar', 'GE', '1', '3.2.1', None, True)]
        self.assertEqual(pkg.requires,
                         [('bar', 'GE', '1', '3.2.1', None, True)])
        pkg.provides = [('foo', None, None, None, None, False)]
        self.assertEqual(pkg.provides,
                         [('foo', None, None, None, None, False)])
        pkg.conflicts = [('foobar', 'LT', '0', '1.0.0', None, False)]
        self.assertEqual(pkg.conflicts,
                         [('foobar', 'LT', '0', '1.0.0', None, False)])
        pkg.obsoletes = [('foobar', 'GE', '0', '1.1.0', None, False)]
        self.assertEqual(pkg.obsoletes,
                         [('foobar', 'GE', '0', '1.1.0', None, False)])
        pkg.suggests = [('foo_sug', 'GE', '0', '1.1.0', None, False)]
        self.assertEqual(pkg.suggests,
                         [('foo_sug', 'GE', '0', '1.1.0', None, False)])
        pkg.enhances = [('foo_enh', 'GE', '0', '1.1.0', None, False)]
        self.assertEqual(pkg.enhances,
                         [('foo_enh', 'GE', '0', '1.1.0', None, False)])
        pkg.recommends = [('foo_rec', 'GE', '0', '1.1.0', None, False)]
        self.assertEqual(pkg.recommends,
                         [('foo_rec', 'GE', '0', '1.1.0', None, False)])
        pkg.supplements = [('foo_sup', 'GE', '0', '1.1.0', None, False)]
        self.assertEqual(pkg.supplements,
                         [('foo_sup', 'GE', '0', '1.1.0', None, False)])
        pkg.files = [(None, '/foo/', 'bar')]
        self.assertEqual(pkg.files, [(None, '/foo/', 'bar')])
        pkg.changelogs = [('me', 123456, 'first commit')]
        self.assertEqual(pkg.changelogs, [('me', 123456, 'first commit')])

        self.assertEqual(pkg.nvra(), "bar-11-33.quantum")
        self.assertEqual(pkg.nevra(), "bar-22:11-33.quantum")