class PackageTest(tests.support.DnfBaseTestCase): REPOS = ['main'] def setUp(self): super(PackageTest, self).setUp() self.pkg = self.sack.query().available().filter(name="pepper")[1] def test_from_cmdline(self): self.sack.create_cmdline_repo() local_pkg = self.sack.add_cmdline_package(tests.support.TOUR_44_PKG_PATH) self.assertTrue(local_pkg._from_cmdline) self.assertFalse(self.pkg._from_cmdline) def test_from_system(self): pkg = self.sack.query().installed().filter(name="pepper")[0] self.assertTrue(pkg._from_system) self.assertFalse(self.pkg._from_system) def test_header(self): self.sack.create_cmdline_repo() pkg = self.sack.add_cmdline_package(tests.support.TOUR_44_PKG_PATH) header = pkg._header self.assertIsInstance(header, rpm.hdr) def fn_getter(): return tests.support.NONEXISTENT_FILE with mock.patch.object(pkg, 'localPkg', fn_getter): with self.assertRaises(IOError): pkg._header # rpm.hdr() is not easy to construct with custom data, we just return a string # instead, as we don't actually need an instance of rpm.hdr for the test @mock.patch("rpm.TransactionSet.dbMatch", lambda self, a, b: iter(["package_header_test_data"])) def test_get_header(self): pkg = self.sack.query().installed().filter(name="pepper")[0] header = pkg.get_header() self.assertEqual(header, "package_header_test_data") pkg = self.sack.query().available().filter(name="pepper")[0] header = pkg.get_header() self.assertEqual(header, None) @mock.patch("dnf.package.Package.rpmdbid", long(3)) def test_idx(self): """ pkg.idx is an int. """ pkg = self.sack.query().installed().filter(name="pepper")[0] self.assertEqual(type(pkg.idx), int) def test_pkgtup(self): self.assertEqual(self.pkg.pkgtup, ('pepper', 'x86_64', '0', '20', '0')) @mock.patch("dnf.package.Package.location", 'f/foo.rpm') def test_localPkg(self): self.pkg.repo.basecachedir = '/cachedir' self.pkg.repo.baseurl = ['file:///mnt/cd'] self.assertTrue(self.pkg._is_local_pkg()) self.assertEqual(self.pkg.localPkg(), '/mnt/cd/f/foo.rpm') self.pkg.repo.baseurl = ['http://remote'] self.assertFalse(self.pkg._is_local_pkg()) self.assertEqual(self.pkg.localPkg(), self.pkg.repo._repo.getCachedir() + '/packages/foo.rpm') def test_verify(self): with mock.patch.object(self.pkg, 'localPkg', return_value=tests.support.TOUR_44_PKG_PATH): self.pkg._chksum = (hawkey.CHKSUM_MD5, TOUR_MD5) self.pkg._size = TOUR_SIZE self.assertTrue(self.pkg.verifyLocalPkg()) self.pkg._chksum = (hawkey.CHKSUM_MD5, TOUR_WRONG_MD5) self.assertFalse(self.pkg.verifyLocalPkg()) def test_return_id_sum(self): self.pkg._chksum = (hawkey.CHKSUM_MD5, TOUR_MD5) self.assertEqual(self.pkg.returnIdSum(), ('md5', '68e9ded8ea25137c964a638f12e9987c')) def test_verify_local(self): self.sack.create_cmdline_repo() local_pkg = self.sack.add_cmdline_package(tests.support.TOUR_44_PKG_PATH) self.assertEqual(local_pkg.reponame, hawkey.CMDLINE_REPO_NAME) self.assertTrue(local_pkg.verifyLocalPkg()) def test_chksum_local(self): self.sack.create_cmdline_repo() local_pkg = self.sack.add_cmdline_package(tests.support.TOUR_44_PKG_PATH) chksum = local_pkg._chksum self.assertEqual(chksum[0], hawkey.CHKSUM_SHA256) self.assertEqual(chksum[1], TOUR_SHA256) def test_verify_installed(self): pkg = self.sack.query().installed().filter(name="pepper")[0] self.assertRaises(ValueError, pkg.verifyLocalPkg)
def keyIdToRPMVer(keyid): '''Convert an integer representing a GPG key ID to the hex version string used by RPM ''' return "%08x" % (keyid & long(0xffffffff))
class PackageTest(support.TestCase): def setUp(self): base = support.MockBase("main") self.sack = base.sack self.pkg = self.sack.query().available().filter(name="pepper")[1] def test_from_cmdline(self): self.sack.create_cmdline_repo() local_pkg = self.sack.add_cmdline_package(support.TOUR_44_PKG_PATH) self.assertTrue(local_pkg.from_cmdline) self.assertFalse(self.pkg.from_cmdline) def test_from_system(self): pkg = self.sack.query().installed().filter(name="pepper")[0] self.assertTrue(pkg.from_system) self.assertFalse(self.pkg.from_system) def test_header(self): self.sack.create_cmdline_repo() pkg = self.sack.add_cmdline_package(support.TOUR_44_PKG_PATH) header = pkg.header self.assertIsInstance(header, rpm.hdr) fn_getter = lambda: support.NONEXISTENT_FILE with mock.patch.object(pkg, 'localPkg', fn_getter): with self.assertRaises(IOError): pkg.header @mock.patch("dnf.package.Package.rpmdbid", long(3)) def test_idx(self): """ pkg.idx is an int. """ pkg = self.sack.query().installed().filter(name="pepper")[0] self.assertEqual(type(pkg.idx), int) def test_pkgtup(self): self.assertEqual(self.pkg.pkgtup, ('pepper', 'x86_64', '0', '20', '0')) @mock.patch("dnf.package.Package.location", 'f/foo.rpm') def test_localPkg(self): self.pkg.repo.basecachedir = '/cachedir' self.pkg.repo.baseurl = ['file:///mnt/cd'] self.assertTrue(self.pkg.repo.local) self.assertEquals(self.pkg.localPkg(), '/mnt/cd/f/foo.rpm') self.pkg.repo.baseurl = ['http://remote'] self.assertFalse(self.pkg.repo.local) self.assertEquals(self.pkg.localPkg(), '/cachedir/main/packages/foo.rpm') def test_verify(self): with mock.patch.object(self.pkg, 'localPkg', return_value=support.TOUR_44_PKG_PATH): self.pkg.chksum = (hawkey.CHKSUM_MD5, TOUR_MD5) self.pkg.size = TOUR_SIZE self.assertTrue(self.pkg.verifyLocalPkg()) self.pkg.chksum = (hawkey.CHKSUM_MD5, TOUR_WRONG_MD5) self.assertFalse(self.pkg.verifyLocalPkg()) def test_return_id_sum(self): self.pkg.chksum = (hawkey.CHKSUM_MD5, TOUR_MD5) self.assertEqual(self.pkg.returnIdSum(), ('md5', '68e9ded8ea25137c964a638f12e9987c')) def test_verify_local(self): self.sack.create_cmdline_repo() local_pkg = self.sack.add_cmdline_package(support.TOUR_44_PKG_PATH) self.assertEqual(local_pkg.reponame, hawkey.CMDLINE_REPO_NAME) self.assertTrue(local_pkg.verifyLocalPkg()) def test_chksum_local(self): self.sack.create_cmdline_repo() local_pkg = self.sack.add_cmdline_package(support.TOUR_44_PKG_PATH) chksum = local_pkg.chksum self.assertEqual(chksum[0], hawkey.CHKSUM_SHA256) self.assertEqual(chksum[1], TOUR_SHA256) def test_verify_installed(self): pkg = self.sack.query().installed().filter(name="pepper")[0] self.assertRaises(ValueError, pkg.verifyLocalPkg)