]> git.saurik.com Git - apt.git/blob - test/pre-upload-check.py
* apt-pkg/deb/dpkgpm.cc:
[apt.git] / test / pre-upload-check.py
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 apt_args = [] # ["-o","Debug::pkgAcquire::Auth=true"]
15
16
17 class testAuthentication(unittest.TestCase):
18
19 # some class wide data
20 apt = "apt-get"
21 pkg = "libglib2.0-data"
22 pkgver = "2.13.6-1ubuntu1"
23 pkgpath = "/var/cache/apt/archives/libglib2.0-data_2.13.6-1ubuntu1_all.deb"
24
25 def setUp(self):
26 for f in glob.glob("testkeys/*,key"):
27 call(["apt-key", "add", f], stdout=stdout, stderr=stderr)
28
29 def _cleanup(self):
30 " make sure we get new lists and no i-m-s "
31 call(["rm","-f", "/var/lib/apt/lists/*"])
32 if os.path.exists(self.pkgpath):
33 os.unlink(self.pkgpath)
34
35 def _expectedRes(self, resultstr):
36 if resultstr == 'ok':
37 return 0
38 elif resultstr == 'broken':
39 return 100
40
41
42 def testPackages(self):
43 for f in glob.glob("testsources.list/sources.list*package*"):
44 self._cleanup()
45 (prefix, testtype, result) = f.split("-")
46 expected_res = self._expectedRes(result)
47 # update first
48 call([self.apt,"update",
49 "-o","Dir::Etc::sourcelist=./%s" % f]+apt_args,
50 stdout=stdout, stderr=stderr)
51 # then get the pkg
52 cmd = ["install", "-y", "-d", "--reinstall",
53 "%s=%s" % (self.pkg, self.pkgver),
54 "-o","Dir::state::Status=./fake-status"]
55 res = call([self.apt, "-o","Dir::Etc::sourcelist=./%s" % f]+cmd+apt_args,
56 stdout=stdout, stderr=stderr)
57 self.assert_(res == expected_res,
58 "test '%s' failed (got %s expected %s" % (f,res,expected_res))
59
60
61 def testGPG(self):
62 for f in glob.glob("testsources.list/sources.list*gpg*"):
63 self._cleanup()
64 (prefix, testtype, result) = f.split("-")
65 expected_res = self._expectedRes(result)
66 # update first
67 call([self.apt,"update",
68 "-o","Dir::Etc::sourcelist=./%s" % f]+apt_args,
69 stdout=stdout, stderr=stderr)
70 # then get the pkg
71 cmd = ["install", "-y", "-d", "--reinstall",
72 "%s=%s" % (self.pkg, self.pkgver),
73 "-o","Dir::state::Status=./fake-status"]
74 res = call([self.apt, "-o","Dir::Etc::sourcelist=./%s" % f]+
75 cmd+apt_args,
76 stdout=stdout, stderr=stderr)
77 self.assert_(res == expected_res,
78 "test '%s' failed (got %s expected %s" % (f,res,expected_res))
79
80 def testRelease(self):
81 for f in glob.glob("testsources.list/sources.list*release*"):
82 self._cleanup()
83 (prefix, testtype, result) = f.split("-")
84 expected_res = self._expectedRes(result)
85 cmd = ["update"]
86 res = call([self.apt,"-o","Dir::Etc::sourcelist=./%s" % f]+cmd+apt_args,
87 stdout=stdout, stderr=stderr)
88 self.assert_(res == expected_res,
89 "test '%s' failed (got %s expected %s" % (f,res,expected_res))
90
91
92
93 class testLocalRepositories(unittest.TestCase):
94 " test local repository regressions "
95
96 repo_dir = "local-repo"
97 apt = "apt-get"
98 pkg = "gdebi-test4"
99
100 def setUp(self):
101 self.repo = os.path.abspath(os.path.join(os.getcwd(), self.repo_dir))
102 self.sources = os.path.join(self.repo, "sources.list")
103 s = open(self.sources,"w")
104 s.write("deb file://%s/ /\n" % self.repo)
105 s.close()
106
107 def testLocalRepoAuth(self):
108 # two times to get at least one i-m-s hit
109 for i in range(2):
110 self.assert_(os.path.exists(self.sources))
111 cmd = [self.apt,"update","-o", "Dir::Etc::sourcelist=%s" % self.sources]+apt_args
112 res = call(cmd, stdout=stdout, stderr=stderr)
113 self.assertEqual(res, 0, "local repo test failed")
114 self.assert_(os.path.exists(os.path.join(self.repo,"Packages.gz")),
115 "Packages.gz vanished from local repo")
116
117 def testInstallFromLocalRepo(self):
118 apt = [self.apt,"-o", "Dir::Etc::sourcelist=%s"% self.sources]+apt_args
119 cmd = apt+["update"]
120 res = call(cmd, stdout=stdout, stderr=stderr)
121 self.assertEqual(res, 0)
122 res = call(apt+["-y","install","--reinstall",self.pkg],
123 stdout=stdout, stderr=stderr)
124 self.assert_(res == 0,
125 "installing %s failed (got %s)" % (self.pkg, res))
126 res = call(apt+["-y","remove",self.pkg],
127 stdout=stdout, stderr=stderr)
128 self.assert_(res == 0,
129 "removing %s failed (got %s)" % (self.pkg, res))
130
131 def testPythonAptInLocalRepo(self):
132 import apt, apt_pkg
133 apt_pkg.Config.Set("Dir::Etc::sourcelist",self.sources)
134 cache = apt.Cache()
135 cache.update()
136 pkg = cache["apt"]
137 self.assert_(pkg.name == 'apt')
138
139
140
141 if __name__ == "__main__":
142 print "Runing simple testsuit on current apt-get and libapt"
143 if len(sys.argv) > 1 and sys.argv[1] == "-v":
144 stdout = sys.stdout
145 stderr = sys.stderr
146 unittest.main()
147
148