]>
git.saurik.com Git - apt.git/blob - test/pre-upload-check.py
7 from subprocess
import call
, PIPE
11 stdout
= os
.open("/dev/null",0) #sys.stdout
12 stderr
= os
.open("/dev/null",0) # sys.stderr
14 apt_args
= [] # ["-o","Debug::pkgAcquire::Auth=true"]
17 class testAuthentication(unittest
.TestCase
):
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/
24 # some class wide data
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"
31 for f
in glob
.glob("testkeys/*,key"):
32 call(["apt-key", "add", f
], stdout
=stdout
, stderr
=stderr
)
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
)
40 def _expectedRes(self
, resultstr
):
43 elif resultstr
== 'broken':
47 def testPackages(self
):
48 for f
in glob
.glob("testsources.list/sources.list*package*"):
50 (prefix
, testtype
, result
) = f
.split("-")
51 expected_res
= self
._expectedRes
(result
)
53 call([self
.apt
,"update",
54 "-o","Dir::Etc::sourcelist=./%s" % f
]+apt_args
,
55 stdout
=stdout
, stderr
=stderr
)
57 cmd
= ["install", "-y", "-d", "--reinstall",
58 "%s=%s" % (self
.pkg
, self
.pkgver
),
59 "-o","Dir::state::Status=./fake-status"]
60 res
= call([self
.apt
, "-o","Dir::Etc::sourcelist=./%s" % f
]+cmd
+apt_args
,
61 stdout
=stdout
, stderr
=stderr
)
62 self
.assert_(res
== expected_res
,
63 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
67 for f
in glob
.glob("testsources.list/sources.list*gpg*"):
69 (prefix
, testtype
, result
) = f
.split("-")
70 expected_res
= self
._expectedRes
(result
)
72 call([self
.apt
,"update",
73 "-o","Dir::Etc::sourcelist=./%s" % f
]+apt_args
,
74 stdout
=stdout
, stderr
=stderr
)
76 cmd
= ["install", "-y", "-d", "--reinstall",
77 "%s=%s" % (self
.pkg
, self
.pkgver
),
78 "-o","Dir::state::Status=./fake-status"]
79 res
= call([self
.apt
, "-o","Dir::Etc::sourcelist=./%s" % f
]+
81 stdout
=stdout
, stderr
=stderr
)
82 self
.assert_(res
== expected_res
,
83 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
85 def testRelease(self
):
86 for f
in glob
.glob("testsources.list/sources.list*release*"):
88 (prefix
, testtype
, result
) = f
.split("-")
89 expected_res
= self
._expectedRes
(result
)
91 res
= call([self
.apt
,"-o","Dir::Etc::sourcelist=./%s" % f
]+cmd
+apt_args
,
92 stdout
=stdout
, stderr
=stderr
)
93 self
.assert_(res
== expected_res
,
94 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
98 class testLocalRepositories(unittest
.TestCase
):
99 " test local repository regressions "
101 repo_dir
= "local-repo"
106 self
.repo
= os
.path
.abspath(os
.path
.join(os
.getcwd(), self
.repo_dir
))
107 self
.sources
= os
.path
.join(self
.repo
, "sources.list")
108 s
= open(self
.sources
,"w")
109 s
.write("deb file://%s/ /\n" % self
.repo
)
112 def testLocalRepoAuth(self
):
113 # two times to get at least one i-m-s hit
115 self
.assert_(os
.path
.exists(self
.sources
))
116 cmd
= [self
.apt
,"update","-o", "Dir::Etc::sourcelist=%s" % self
.sources
]+apt_args
117 res
= call(cmd
, stdout
=stdout
, stderr
=stderr
)
118 self
.assertEqual(res
, 0, "local repo test failed")
119 self
.assert_(os
.path
.exists(os
.path
.join(self
.repo
,"Packages.gz")),
120 "Packages.gz vanished from local repo")
122 def testInstallFromLocalRepo(self
):
123 apt
= [self
.apt
,"-o", "Dir::Etc::sourcelist=%s"% self
.sources
]+apt_args
125 res
= call(cmd
, stdout
=stdout
, stderr
=stderr
)
126 self
.assertEqual(res
, 0)
127 res
= call(apt
+["-y","install","--reinstall",self
.pkg
],
128 stdout
=stdout
, stderr
=stderr
)
129 self
.assert_(res
== 0,
130 "installing %s failed (got %s)" % (self
.pkg
, res
))
131 res
= call(apt
+["-y","remove",self
.pkg
],
132 stdout
=stdout
, stderr
=stderr
)
133 self
.assert_(res
== 0,
134 "removing %s failed (got %s)" % (self
.pkg
, res
))
136 def testPythonAptInLocalRepo(self
):
138 apt_pkg
.Config
.Set("Dir::Etc::sourcelist",self
.sources
)
142 self
.assert_(pkg
.name
== 'apt')
146 if __name__
== "__main__":
147 print "Runing simple testsuit on current apt-get and libapt"
148 if len(sys
.argv
) > 1 and sys
.argv
[1] == "-v":