1 #!/usr/bin/env python2.3
2 import sys
, tempfile
, os
, shutil
5 from logging
import getLogger
, DEBUG
, INFO
6 #getLogger().setLevel(DEBUG)
8 sys
.path
.insert(0, '..')
9 from zeroinstall
.injector
import basedir
, download
, model
, gpg
, trust
10 from zeroinstall
.injector
.namespaces
import *
11 from zeroinstall
.injector
.iface_cache
import iface_cache
13 class TestIfaceCache(unittest
.TestCase
):
15 self
.config_home
= tempfile
.mktemp()
16 self
.cache_home
= tempfile
.mktemp()
17 self
.gnupg_home
= tempfile
.mktemp()
18 os
.environ
['XDG_CONFIG_HOME'] = self
.config_home
19 os
.environ
['XDG_CACHE_HOME'] = self
.cache_home
20 os
.environ
['GNUPGHOME'] = self
.gnupg_home
23 os
.mkdir(self
.config_home
, 0700)
24 os
.mkdir(self
.cache_home
, 0700)
25 os
.mkdir(self
.gnupg_home
, 0700)
27 iface_cache
.__init
__()
30 shutil
.rmtree(self
.config_home
)
31 shutil
.rmtree(self
.cache_home
)
32 shutil
.rmtree(self
.gnupg_home
)
35 self
.assertEquals([], iface_cache
.list_all_interfaces())
36 iface_dir
= basedir
.save_cache_path(config_site
, 'interfaces')
37 file(os
.path
.join(iface_dir
, 'http%3a%2f%2ffoo'), 'w').close()
38 self
.assertEquals(['http://foo'],
39 iface_cache
.list_all_interfaces())
40 # TODO: test overrides
42 def testCheckSigned(self
):
43 trust
.trust_db
.trust_key(
44 '92429807C9853C0744A68B9AAE07828059A53CC1')
45 iface
= iface_cache
.get_interface('http://foo')
46 src
= tempfile
.TemporaryFile()
53 iface_cache
.check_signed_data(iface
, src
, None)
55 except model
.SafeException
:
58 stream
= tempfile
.TemporaryFile()
59 stream
.write(data
.thomas_key
)
61 gpg
.import_key(stream
)
65 src
.write(data
.foo_signed
)
68 iface_cache
.check_signed_data(iface
, src
, None)
69 self
.assertEquals(['http://foo'],
70 iface_cache
.list_all_interfaces())
72 suite
= unittest
.makeSuite(TestIfaceCache
)
73 if __name__
== '__main__':