File: test_update_origin.py

package info (click to toggle)
update-manager 0.68.debian-7
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,796 kB
  • ctags: 814
  • sloc: python: 5,646; xml: 1,571; sh: 433; makefile: 356; ansic: 264
file content (86 lines) | stat: -rwxr-xr-x 3,675 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python

import os
import sys
sys.path = [os.path.normpath(os.path.join(os.getcwd(),"../"))] + sys.path


import apt
import unittest
from UpdateManager.UpdateManager import (MyCache,
                                         UpdateList)


class testOriginMatcher(unittest.TestCase):
    def setUp(self):
        self.dpkg_status = open("apt/var/lib/dpkg/status","w")
        self.dpkg_status.flush()
        self.cache = MyCache(apt.progress.OpProgress(), os.path.join(os.getcwd(),"apt/"))
        self.cache.update()

    def testOriginMatcherSimple(self):
        test_pkgs = set()
        for pkg in self.cache:
            if pkg.candidateOrigin:
                if [l.archive for l in pkg.candidateOrigin
                    if l.archive == "dapper-security"]:
                    test_pkgs.add(pkg.name)
        self.assert_(len(test_pkgs) > 0)
        ul = UpdateList()
        matcher = ul.initMatcher("dapper")
        for pkgname in test_pkgs:
            pkg = self.cache[pkgname]
            self.assertEqual(self.cache.matchPackageOrigin(pkg, matcher),
                             matcher[("dapper-security","Ubuntu")],
                             "pkg '%s' is not in dapper-security but in '%s' instead" % (pkg.name, str(self.cache.matchPackageOrigin(pkg, matcher))))
        

    def testOriginMatcherWithVersionInUpdatesAndSecurity(self):
        # empty dpkg status
        self.cache.open(apt.progress.OpProgress())
        
        # find test packages set
        test_pkgs = set()
        for pkg in self.cache:
            if pkg.candidateOrigin:
                for v in pkg.candidateOrigin:
                    if (v.archive == "dapper-updates" and
                        len(pkg._pkg.VersionList) > 2):
                        test_pkgs.add(pkg.name)
        self.assert_(len(test_pkgs) > 0,
                     "no suitable test package found that has a version in both -security and -updates and where -updates is newer")

        # now test if versions in -security are detected
        ul = UpdateList()
        matcher = ul.initMatcher("dapper")
        for pkgname in test_pkgs:
            pkg = self.cache[pkgname]
            self.assertEqual(self.cache.matchPackageOrigin(pkg, matcher),
                             matcher[("dapper-security","Ubuntu")],
                             "package '%s' from dapper-updates contains also a (not yet installed) security updates, but it is not labeled as such" % pkg.name)

        # now check if it marks the version with -update if the -security
        # version is installed
        for pkgname in test_pkgs:
            pkg = self.cache[pkgname]
            # FIXME: make this more inteligent (picking the versin from
            #        -security
            sec_ver = pkg._pkg.VersionList[1]
            self.dpkg_status.write("Package: %s\n"
                              "Status: install ok installed\n"
                              "Installed-Size: 1\n"
                              "Version: %s\n"
                              "Description: foo\n"
                              % (pkg.name, sec_ver.VerStr))
            self.dpkg_status.flush()
        self.cache.open(apt.progress.OpProgress())
        for pkgname in test_pkgs:
            pkg = self.cache[pkgname]
            self.assert_(pkg._pkg.CurrentVer != None)
            self.assertEqual(self.cache.matchPackageOrigin(pkg, matcher),
                             matcher[("dapper-updates","Ubuntu")],
                             "package '%s' from dapper-updates is labeld -security even though we have marked this version as installed already" % pkg.name)


if __name__ == "__main__":
    unittest.main()