Ejemplo n.º 1
0
 def test_pkg_from_file_without_md5sums(self, _log_warn, _DebFile):
     meta = dict(package="a", version="1", architecture="amd64")
     _DebFile.return_value.control.debcontrol.return_value = meta
     args = "'md5sums' file not found, can't list MD5 sums"
     _DebFile.return_value.md5sums.side_effect = debfile.DebError(args)
     dp = DebPkg.from_file("/dev/null")
     _DebFile.return_value.md5sums.assert_called_once_with(encoding='utf-8')
     self.assertTrue(_log_warn.call_count == 1)
     self.assertEqual(dp.md5sums, DebPkgMD5sums())
Ejemplo n.º 2
0
 def test_pkg_from_file(self, _DebFile):
     meta = dict(package="a", version="1", architecture="amd64")
     _DebFile.return_value.control.debcontrol.return_value = meta
     dp = DebPkg.from_file("/dev/null")
     # Let's convert the rfc822 format to a dict
     lines = str(dp.package).split('\n')
     ldict = dict(
         (x, z) for (x, y, z) in (line.partition(': ') for line in lines))
     # Make sure the original dict is included
     for k, v in meta.items():
         self.assertEqual(v, ldict[k])
Ejemplo n.º 3
0
 def test_pkg(self):
     pkg = DebPkg(self.control_data, self.md5sum_data, self.hashes_data)
     for k, v in self.attrs_data.items():
         self.assertEqual(getattr(pkg, k), v)
     # Make sure the hashes are not part of the control file
     for k in pkg.hashes:
         self.assertFalse(k in pkg._c)
     self.assertEqual(pkg.package, self.package_obj)
     # Make sure the hashes are still not part of the control file
     for k in pkg.hashes:
         self.assertFalse(k in pkg._c)
     self.assertTrue(isinstance(pkg.control, deb822.Deb822))
     self.assertTrue(isinstance(pkg.hashes, deb822.Deb822))
Ejemplo n.º 4
0
 def test_pkg_versions(self):
     expected = ('bar_0.0.1-1_amd64', 'foo_0.0.1-1_amd64',
                 'bar_0.0.1-2_amd64', 'foo_0.0.1-2_amd64',
                 'bar_0.0.2-1_amd64', 'foo_0.0.2-1_amd64',
                 'bar_0.1.0-1_amd64', 'foo_0.1.0-1_amd64')
     versions = ('0.0.1-1', '0.0.1-2', '0.0.2-1', '0.1.0-1')
     foos = []
     bars = []
     for version in versions:
         control_data = self.control_data.copy()
         control_data.update(dict(Version=version))
         foos.append(
             DebPkg(control_data, self.md5sum_data, self.hashes_data))
         control_data.update(dict(Package='bar'))
         bars.append(
             DebPkg(control_data, self.md5sum_data, self.hashes_data))
     self.assertTrue(bars[2] == bars[2])
     self.assertTrue(bars[2] >= bars[2])
     self.assertTrue(bars[3] >= bars[2])
     self.assertTrue(bars[2] <= bars[2])
     self.assertTrue(bars[2] <= bars[3])
     self.assertTrue(bars[1] != bars[2])
     self.assertTrue(bars[0] <= bars[1])
     self.assertTrue(bars[0] < bars[1])
     self.assertFalse(bars[0] > bars[1])
     self.assertFalse(bars[0] >= bars[1])
     self.assertTrue(foos[0] < foos[1])
     self.assertTrue(foos[0] < foos[-1])
     self.assertFalse(foos[0] > foos[1])
     self.assertFalse(foos[0] > foos[-1])
     self.assertTrue(bars[0] < foos[0])
     self.assertTrue(foos[0] != bars[0])
     self.assertFalse(foos[0] == bars[0])
     self.assertFalse(foos[0] == foos[1])
     _all = sorted(foos + bars)
     _all_versions = [x.nevra for x in _all]
     for index in range(len(expected)):
         self.assertEqual(expected[index], _all_versions[index])
Ejemplo n.º 5
0
 def test_pkg_from_file_with_Filename(self, _DebFile):
     _DebFile.return_value.control.debcontrol.return_value = {}
     Filename = "pool/comp/a_1.deb"
     dp = DebPkg.from_file("/dev/null", Filename=Filename)
     self.assertEqual(Filename, dp._c['Filename'])
Ejemplo n.º 6
0
    def test_pkg_dependencies(self):
        ArchRestriction = namedtuple('ArchRestriction', ['enabled', 'arch'])
        # TODO
        # BuildRestriction = namedtuple('BuildRestriction',
        #                              ['enabled', 'profile'])
        control_data = self.control_data.copy()
        control_data.update({
            'Breaks':
            u'broken (<=1.0-1) [i386]',
            'Conflicts':
            u'conflicting (=1.0-4)',
            'Pre-Depends':
            u'pre (>= 2.0-1)',
            'Depends':
            u'bar (>= 1.0-6), baz2.7 | baz3.5, '
            'buz [i386] | fuz [amd64], '
            'caz [i386], cuz [amd64], '
            'daz [!i386]',
            'Enhances':
            u'enhanceable [!i386]',
        })

        dependencies = {
            u'breaks': [[{
                'arch': [ArchRestriction(enabled=True, arch=u'i386')],
                'archqual': None,
                'name': u'broken',
                'restrictions': None,
                'version': (u'<=', u'1.0-1')
            }]],
            u'conflicts': [[{
                'arch': None,
                'archqual': None,
                'name': u'conflicting',
                'restrictions': None,
                'version': (u'=', u'1.0-4')
            }]],
            u'depends':
            [[{
                'arch': None,
                'archqual': None,
                'name': u'bar',
                'restrictions': None,
                'version': (u'>=', u'1.0-6')
            }],
             [{
                 'arch': None,
                 'archqual': None,
                 'name': u'baz2.7',
                 'restrictions': None,
                 'version': None
             }, {
                 'arch': None,
                 'archqual':
                 None,
                 'name': u'baz3.5',
                 'restrictions': None,
                 'version': None
             }],
             [{
                 'arch': [ArchRestriction(enabled=True, arch=u'i386')],
                 'archqual': None,
                 'name': u'buz',
                 'restrictions': None,
                 'version': None
             }, {
                 'arch': [ArchRestriction(enabled=True, arch=u'amd64')],
                 'archqual':
                 None,
                 'name': u'fuz',
                 'restrictions': None,
                 'version': None
             }],
             [{
                 'arch': [ArchRestriction(enabled=True, arch=u'i386')],
                 'archqual': None,
                 'name': u'caz',
                 'restrictions': None,
                 'version': None
             }],
             [{
                 'arch': [ArchRestriction(enabled=True, arch=u'amd64')],
                 'archqual': None,
                 'name': u'cuz',
                 'restrictions': None,
                 'version': None
             }],
             [{
                 'arch': [ArchRestriction(enabled=False, arch=u'i386')],
                 'archqual': None,
                 'name': u'daz',
                 'restrictions': None,
                 'version': None
             }]],
            u'enhances': [[{
                'arch': [ArchRestriction(enabled=False, arch=u'i386')],
                'archqual':
                None,
                'name':
                u'enhanceable',
                'restrictions':
                None,
                'version':
                None
            }]],
            u'pre_depends': [[{
                'arch': None,
                'archqual': None,
                'name': u'pre',
                'restrictions': None,
                'version': (u'>=', u'2.0-1')
            }]],
            u'provides': [],
            u'recommends': [],
            u'replaces': [],
            u'suggests': []
        }

        pkg = DebPkg(control_data, self.md5sum_data, self.hashes_data)
        self.assertEqual(dependencies, pkg.dependencies)
        self.assertEqual(dependencies['depends'], pkg.depends)
Ejemplo n.º 7
0
    def test_pkg(self):

        package_data = {
            'Package':
            u'foo',
            'Version':
            u'0.0.1-1',
            'Architecture':
            u'amd64',
            'Maintainer':
            u'Brett Smith <*****@*****.**>',
            'Installed-Size':
            u'25',
            'Section':
            u'database',
            'Priority':
            u'extra',
            'Multi-Arch':
            u'foreign',
            'Homepage':
            u'https://github.com/xbcsmith/foo',
            'Description':
            u'So this is the Foo of Brixton program\n'
            ' When they kick at your front door\n How you'
            ' gonna come?\n With your hands on your head\n'
            ' Or on the trigger of your gun',
            'MD5sum':
            u'5fc5c0cb24690e78d6c6a2e13753f1aa',
            'SHA256':
            u'd80568c932f54997713bb7832c6da6aa04992919'
            'f3d0f47afb6ba600a7586780',
            'SHA1':
            u'5e26ae3ebf9f7176bb7fd01c9e802ac8e223cdcc'
        }

        attrs_data = {
            'md5sum': u'5fc5c0cb24690e78d6c6a2e13753f1aa',
            'sha1': u'5e26ae3ebf9f7176bb7fd01c9e802ac8e223cdcc',
            'sha256': u'd80568c932f54997713bb7832c6da6aa049929'
            '19f3d0f47afb6ba600a7586780',
            'name': u'foo',
            'nevra': u'foo_0.0.1-1_amd64',
        }

        md5sums_data = {
            u'usr/share/doc/foo/changelog.Debian.gz':
            u'9e2d1b5db1f1fb50621a48538d570ee8',
            u'usr/share/doc/foo/copyright':
            u'a664cb0d199e56bb5691d8ae29ca759a',
            u'usr/share/doc/foo/README.Debian':
            u'22c9f74e69fd45c5a60331586763c253'
        }

        files_data = [x for x in md5sums_data.keys()]

        package_attrs = {'foo': attrs_data}
        package_objects = {'foo': deb822.Deb822(package_data)}
        package_files = {'foo': DebPkgFiles(files_data)}
        package_md5sums = {'foo': DebPkgMD5sums(md5sums_data)}

        files = []
        for root, _, fl in os.walk(self.pool_dir):
            for f in fl:
                if f.endswith('.deb'):
                    files.append(os.path.join(root, f))

        packages = {}

        for fpath in files:
            pkg = DebPkg.from_file(fpath)
            packages.setdefault(pkg.name, pkg)

        for name, pkg in packages.items():
            if name in package_attrs:
                for attr in package_attrs[name]:
                    self.assertEquals(package_attrs[name][attr],
                                      getattr(pkg, attr))
            if name in package_md5sums:
                self.assertEquals(package_md5sums[name], pkg.md5sums)
            if name in package_files:
                self.assertEquals(sorted([x for x in package_files[name]]),
                                  sorted([x for x in pkg.files]))
                self.assertEquals(package_files[name], pkg.files)
            if name in package_data:
                self.assertEquals(package_objects[name], pkg.package)