]> git.saurik.com Git - apt.git/blame - test/pre-upload-check.py
* apt-pkg/deb/dpkgpm.cc:
[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
MV
17class testAuthentication(unittest.TestCase):
18
19 # some class wide data
20 apt = "apt-get"
4aaa50a3
MV
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",
5177f802 49 "-o","Dir::Etc::sourcelist=./%s" % f]+apt_args,
4aaa50a3
MV
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"]
5177f802 55 res = call([self.apt, "-o","Dir::Etc::sourcelist=./%s" % f]+cmd+apt_args,
4aaa50a3
MV
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",
5177f802 68 "-o","Dir::Etc::sourcelist=./%s" % f]+apt_args,
4aaa50a3
MV
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]+
5177f802 75 cmd+apt_args,
4aaa50a3
MV
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"]
5177f802 86 res = call([self.apt,"-o","Dir::Etc::sourcelist=./%s" % f]+cmd+apt_args,
4aaa50a3
MV
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
4aaa50a3 92
5177f802
MV
93class testLocalRepositories(unittest.TestCase):
94 " test local repository regressions "
4aaa50a3 95
5177f802 96 repo_dir = "local-repo"
4aaa50a3 97 apt = "apt-get"
5177f802 98 pkg = "gdebi-test4"
4aaa50a3 99
5177f802
MV
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],
4aaa50a3
MV
123 stdout=stdout, stderr=stderr)
124 self.assert_(res == 0,
125 "installing %s failed (got %s)" % (self.pkg, res))
5177f802
MV
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
4aaa50a3
MV
140
141if __name__ == "__main__":
4b7c5a3f 142 print "Runing simple testsuit on current apt-get and libapt"
4aaa50a3
MV
143 if len(sys.argv) > 1 and sys.argv[1] == "-v":
144 stdout = sys.stdout
145 stderr = sys.stderr
146 unittest.main()
147
148