]>
Commit | Line | Data |
---|---|---|
4aaa50a3 MV |
1 | #!/usr/bin/python |
2 | ||
3 | import sys | |
4 | import os | |
5 | import glob | |
6 | import os.path | |
7 | from subprocess import call, PIPE | |
8 | ||
9 | import unittest | |
10 | ||
11 | stdout = os.open("/dev/null",0) #sys.stdout | |
12 | stderr = os.open("/dev/null",0) # sys.stderr | |
13 | ||
14 | class testAuthentication(unittest.TestCase): | |
15 | ||
16 | # some class wide data | |
17 | apt = "apt-get" | |
18 | args = [] # ["-q", "-q", "-o","Debug::pkgAcquire::Auth=true"] | |
19 | pkg = "libglib2.0-data" | |
20 | pkgver = "2.13.6-1ubuntu1" | |
21 | pkgpath = "/var/cache/apt/archives/libglib2.0-data_2.13.6-1ubuntu1_all.deb" | |
22 | ||
23 | def setUp(self): | |
24 | for f in glob.glob("testkeys/*,key"): | |
25 | call(["apt-key", "add", f], stdout=stdout, stderr=stderr) | |
26 | ||
27 | def _cleanup(self): | |
28 | " make sure we get new lists and no i-m-s " | |
29 | call(["rm","-f", "/var/lib/apt/lists/*"]) | |
30 | if os.path.exists(self.pkgpath): | |
31 | os.unlink(self.pkgpath) | |
32 | ||
33 | def _expectedRes(self, resultstr): | |
34 | if resultstr == 'ok': | |
35 | return 0 | |
36 | elif resultstr == 'broken': | |
37 | return 100 | |
38 | ||
39 | ||
40 | def testPackages(self): | |
41 | for f in glob.glob("testsources.list/sources.list*package*"): | |
42 | self._cleanup() | |
43 | (prefix, testtype, result) = f.split("-") | |
44 | expected_res = self._expectedRes(result) | |
45 | # update first | |
46 | call([self.apt,"update", | |
47 | "-o","Dir::Etc::sourcelist=./%s" % f]+self.args, | |
48 | stdout=stdout, stderr=stderr) | |
49 | # then get the pkg | |
50 | cmd = ["install", "-y", "-d", "--reinstall", | |
51 | "%s=%s" % (self.pkg, self.pkgver), | |
52 | "-o","Dir::state::Status=./fake-status"] | |
53 | res = call([self.apt, "-o","Dir::Etc::sourcelist=./%s" % f]+cmd+self.args, | |
54 | stdout=stdout, stderr=stderr) | |
55 | self.assert_(res == expected_res, | |
56 | "test '%s' failed (got %s expected %s" % (f,res,expected_res)) | |
57 | ||
58 | ||
59 | def testGPG(self): | |
60 | for f in glob.glob("testsources.list/sources.list*gpg*"): | |
61 | self._cleanup() | |
62 | (prefix, testtype, result) = f.split("-") | |
63 | expected_res = self._expectedRes(result) | |
64 | # update first | |
65 | call([self.apt,"update", | |
66 | "-o","Dir::Etc::sourcelist=./%s" % f]+self.args, | |
67 | stdout=stdout, stderr=stderr) | |
68 | # then get the pkg | |
69 | cmd = ["install", "-y", "-d", "--reinstall", | |
70 | "%s=%s" % (self.pkg, self.pkgver), | |
71 | "-o","Dir::state::Status=./fake-status"] | |
72 | res = call([self.apt, "-o","Dir::Etc::sourcelist=./%s" % f]+ | |
73 | cmd+self.args, | |
74 | stdout=stdout, stderr=stderr) | |
75 | self.assert_(res == expected_res, | |
76 | "test '%s' failed (got %s expected %s" % (f,res,expected_res)) | |
77 | ||
78 | def testRelease(self): | |
79 | for f in glob.glob("testsources.list/sources.list*release*"): | |
80 | self._cleanup() | |
81 | (prefix, testtype, result) = f.split("-") | |
82 | expected_res = self._expectedRes(result) | |
83 | cmd = ["update"] | |
84 | res = call([self.apt,"-o","Dir::Etc::sourcelist=./%s" % f]+cmd+self.args, | |
85 | stdout=stdout, stderr=stderr) | |
86 | self.assert_(res == expected_res, | |
87 | "test '%s' failed (got %s expected %s" % (f,res,expected_res)) | |
88 | ||
89 | ||
90 | class testPythonApt(unittest.TestCase): | |
91 | " test if python-apt is still working and if we not accidently broke the ABI " | |
92 | ||
93 | def testPythonApt(self): | |
94 | import apt | |
95 | cache = apt.Cache() | |
96 | cache.update() | |
97 | pkg = cache["apt"] | |
98 | self.assert_(pkg.name == 'apt') | |
99 | ||
100 | class testAptInstall(unittest.TestCase): | |
101 | " test if installing still works " | |
102 | ||
103 | apt = "apt-get" | |
104 | pkg = "coreutils" | |
105 | ||
106 | def testInstall(self): | |
107 | res = call([self.apt,"-y","install","--reinstall",self.pkg], | |
108 | stdout=stdout, stderr=stderr) | |
109 | self.assert_(res == 0, | |
110 | "installing %s failed (got %s)" % (self.pkg, res)) | |
111 | ||
112 | if __name__ == "__main__": | |
113 | if len(sys.argv) > 1 and sys.argv[1] == "-v": | |
114 | stdout = sys.stdout | |
115 | stderr = sys.stderr | |
116 | unittest.main() | |
117 | ||
118 |