]> git.saurik.com Git - apt.git/blame - test/pre-upload-check.py
Galician translation update
[apt.git] / test / pre-upload-check.py
CommitLineData
4aaa50a3
MV
1#!/usr/bin/python
2
3import sys
4import os
5import glob
6import os.path
7from subprocess import call, PIPE
8
9import unittest
10
11stdout = os.open("/dev/null",0) #sys.stdout
12stderr = os.open("/dev/null",0) # sys.stderr
13
5177f802
MV
14apt_args = [] # ["-o","Debug::pkgAcquire::Auth=true"]
15
16
4aaa50a3 17class testAuthentication(unittest.TestCase):
6ec741fe
MV
18 """
19 test if the authentication is working, the repository
20 of the test-data can be found here:
21 bzr get http://people.ubuntu.com/~mvo/bzr/apt/apt-auth-test-suit/
22 """
23
4aaa50a3
MV
24 # some class wide data
25 apt = "apt-get"
4aaa50a3
MV
26 pkg = "libglib2.0-data"
27 pkgver = "2.13.6-1ubuntu1"
28 pkgpath = "/var/cache/apt/archives/libglib2.0-data_2.13.6-1ubuntu1_all.deb"
29
30 def setUp(self):
31 for f in glob.glob("testkeys/*,key"):
32 call(["apt-key", "add", f], stdout=stdout, stderr=stderr)
33
34 def _cleanup(self):
35 " make sure we get new lists and no i-m-s "
36 call(["rm","-f", "/var/lib/apt/lists/*"])
37 if os.path.exists(self.pkgpath):
38 os.unlink(self.pkgpath)
39
40 def _expectedRes(self, resultstr):
41 if resultstr == 'ok':
42 return 0
43 elif resultstr == 'broken':
44 return 100
45
46
47 def testPackages(self):
48 for f in glob.glob("testsources.list/sources.list*package*"):
49 self._cleanup()
50 (prefix, testtype, result) = f.split("-")
51 expected_res = self._expectedRes(result)
52 # update first
53 call([self.apt,"update",
5177f802 54 "-o","Dir::Etc::sourcelist=./%s" % f]+apt_args,
4aaa50a3
MV
55 stdout=stdout, stderr=stderr)
56 # then get the pkg
57 cmd = ["install", "-y", "-d", "--reinstall",
58 "%s=%s" % (self.pkg, self.pkgver),
59 "-o","Dir::state::Status=./fake-status"]
5177f802 60 res = call([self.apt, "-o","Dir::Etc::sourcelist=./%s" % f]+cmd+apt_args,
4aaa50a3
MV
61 stdout=stdout, stderr=stderr)
62 self.assert_(res == expected_res,
63 "test '%s' failed (got %s expected %s" % (f,res,expected_res))
64
65
66 def testGPG(self):
67 for f in glob.glob("testsources.list/sources.list*gpg*"):
68 self._cleanup()
69 (prefix, testtype, result) = f.split("-")
70 expected_res = self._expectedRes(result)
71 # update first
72 call([self.apt,"update",
5177f802 73 "-o","Dir::Etc::sourcelist=./%s" % f]+apt_args,
4aaa50a3 74 stdout=stdout, stderr=stderr)
4aaa50a3
MV
75 cmd = ["install", "-y", "-d", "--reinstall",
76 "%s=%s" % (self.pkg, self.pkgver),
77 "-o","Dir::state::Status=./fake-status"]
78 res = call([self.apt, "-o","Dir::Etc::sourcelist=./%s" % f]+
5177f802 79 cmd+apt_args,
4aaa50a3
MV
80 stdout=stdout, stderr=stderr)
81 self.assert_(res == expected_res,
82 "test '%s' failed (got %s expected %s" % (f,res,expected_res))
83
84 def testRelease(self):
85 for f in glob.glob("testsources.list/sources.list*release*"):
86 self._cleanup()
87 (prefix, testtype, result) = f.split("-")
88 expected_res = self._expectedRes(result)
89 cmd = ["update"]
5177f802 90 res = call([self.apt,"-o","Dir::Etc::sourcelist=./%s" % f]+cmd+apt_args,
4aaa50a3
MV
91 stdout=stdout, stderr=stderr)
92 self.assert_(res == expected_res,
93 "test '%s' failed (got %s expected %s" % (f,res,expected_res))
717847f2
MV
94 if expected_res == 0:
95 self.assert_(len(glob.glob("/var/lib/apt/lists/partial/*")) == 0,
96 "partial/ dir has leftover files: %s" % glob.glob("/var/lib/apt/lists/partial/*"))
4aaa50a3 97
4aaa50a3 98
5177f802
MV
99class testLocalRepositories(unittest.TestCase):
100 " test local repository regressions "
4aaa50a3 101
5177f802 102 repo_dir = "local-repo"
4aaa50a3 103 apt = "apt-get"
5177f802 104 pkg = "gdebi-test4"
4aaa50a3 105
5177f802
MV
106 def setUp(self):
107 self.repo = os.path.abspath(os.path.join(os.getcwd(), self.repo_dir))
108 self.sources = os.path.join(self.repo, "sources.list")
109 s = open(self.sources,"w")
110 s.write("deb file://%s/ /\n" % self.repo)
111 s.close()
112
113 def testLocalRepoAuth(self):
114 # two times to get at least one i-m-s hit
115 for i in range(2):
116 self.assert_(os.path.exists(self.sources))
117 cmd = [self.apt,"update","-o", "Dir::Etc::sourcelist=%s" % self.sources]+apt_args
118 res = call(cmd, stdout=stdout, stderr=stderr)
119 self.assertEqual(res, 0, "local repo test failed")
120 self.assert_(os.path.exists(os.path.join(self.repo,"Packages.gz")),
121 "Packages.gz vanished from local repo")
122
717847f2
MV
123 def testLocalRepo2(self):
124 repo = os.path.abspath(os.path.join(os.getcwd(), self.repo_dir+"2"))
125 sources = os.path.join(self.repo, "sources.list")
126 s = open(sources,"w")
127 s.write("deb file://%s/ /\n" % repo)
128 s.close()
129
130 # two times to get at least one i-m-s hit
131 for i in range(2):
132 self.assert_(os.path.exists(sources))
133 cmd = [self.apt,"update","-o", "Dir::Etc::sourcelist=%s" % sources]+apt_args
134 res = call(cmd, stdout=stdout, stderr=stderr)
135 self.assertEqual(res, 0, "local repo2 test failed")
136 self.assert_(os.path.exists(os.path.join(repo,"Packages.gz")),
137 "Packages.gz vanished from local repo")
138
5177f802
MV
139 def testInstallFromLocalRepo(self):
140 apt = [self.apt,"-o", "Dir::Etc::sourcelist=%s"% self.sources]+apt_args
141 cmd = apt+["update"]
142 res = call(cmd, stdout=stdout, stderr=stderr)
143 self.assertEqual(res, 0)
144 res = call(apt+["-y","install","--reinstall",self.pkg],
4aaa50a3
MV
145 stdout=stdout, stderr=stderr)
146 self.assert_(res == 0,
147 "installing %s failed (got %s)" % (self.pkg, res))
5177f802
MV
148 res = call(apt+["-y","remove",self.pkg],
149 stdout=stdout, stderr=stderr)
150 self.assert_(res == 0,
151 "removing %s failed (got %s)" % (self.pkg, res))
152
153 def testPythonAptInLocalRepo(self):
154 import apt, apt_pkg
155 apt_pkg.Config.Set("Dir::Etc::sourcelist",self.sources)
156 cache = apt.Cache()
157 cache.update()
158 pkg = cache["apt"]
159 self.assert_(pkg.name == 'apt')
160
161
4aaa50a3
MV
162
163if __name__ == "__main__":
4b7c5a3f 164 print "Runing simple testsuit on current apt-get and libapt"
4aaa50a3
MV
165 if len(sys.argv) > 1 and sys.argv[1] == "-v":
166 stdout = sys.stdout
167 stderr = sys.stderr
168 unittest.main()
169
170