Use iface_cache.get_interface() rather than policy.get_interface() in several
[zeroinstall.git] / tests / testtrust.py
blob7b93112b4ef80b16e346461af4ead2e0ee1ce9f9
1 #!/usr/bin/env python2.3
2 import sys, tempfile, os, shutil
3 import unittest
5 thomas_fingerprint = "92429807C9853C0744A68B9AAE07828059A53CC1"
7 sys.path.insert(0, '..')
8 from zeroinstall.injector import trust, basedir
10 class TestTrust(unittest.TestCase):
11 def setUp(self):
12 self.config_home = tempfile.mktemp()
13 os.environ['XDG_CONFIG_HOME'] = self.config_home
14 reload(basedir)
16 assert basedir.xdg_config_home == self.config_home
17 os.mkdir(self.config_home, 0700)
19 def tearDown(self):
20 shutil.rmtree(self.config_home)
22 def testInit(self):
23 assert not trust.trust_db.is_trusted(thomas_fingerprint)
24 assert not trust.trust_db.is_trusted("1234")
25 assert len(trust.trust_db.keys) == 0
27 def testAddInvalid(self):
28 try:
29 trust.trust_db.trust_key("hello")
30 assert 0
31 except ValueError:
32 pass
34 def testAdd(self):
35 assert not trust.trust_db.is_trusted("1234")
36 trust.trust_db.trust_key("1234")
37 assert trust.trust_db.is_trusted("1234")
38 assert not trust.trust_db.is_trusted("1236")
40 trust.trust_db.untrust_key("1234")
41 assert not trust.trust_db.is_trusted("1234")
43 def testParallel(self):
44 a = trust.TrustDB()
45 b = trust.TrustDB()
46 a.trust_key("1")
47 assert b.is_trusted("1")
48 b.trust_key("2")
49 a.untrust_key("1")
50 assert not a.is_trusted("1")
51 assert a.is_trusted("2")
53 suite = unittest.makeSuite(TestTrust)
54 if __name__ == '__main__':
55 sys.argv.append('-v')
56 unittest.main()