Moved a load of common setup and teardown code into the new basetest.py.
[zeroinstall.git] / tests / testtrust.py
blob5373270961f05e7170c87b5f4169b80ab5644383
1 #!/usr/bin/env python2.3
2 from basetest import BaseTest
3 import sys, tempfile, os, shutil
4 import unittest
6 thomas_fingerprint = "92429807C9853C0744A68B9AAE07828059A53CC1"
8 sys.path.insert(0, '..')
9 from zeroinstall.injector import trust, basedir
11 class TestTrust(BaseTest):
12 def testInit(self):
13 assert not trust.trust_db.is_trusted(thomas_fingerprint)
14 assert not trust.trust_db.is_trusted("1234")
15 assert len(trust.trust_db.keys) == 0
17 def testAddInvalid(self):
18 try:
19 trust.trust_db.trust_key("hello")
20 assert 0
21 except ValueError:
22 pass
24 def testAdd(self):
25 assert not trust.trust_db.is_trusted("1234")
26 trust.trust_db.trust_key("1234")
27 assert trust.trust_db.is_trusted("1234")
28 assert not trust.trust_db.is_trusted("1236")
30 trust.trust_db.untrust_key("1234")
31 assert not trust.trust_db.is_trusted("1234")
33 def testParallel(self):
34 a = trust.TrustDB()
35 b = trust.TrustDB()
36 a.trust_key("1")
37 assert b.is_trusted("1")
38 b.trust_key("2")
39 a.untrust_key("1")
40 assert not a.is_trusted("1")
41 assert a.is_trusted("2")
43 suite = unittest.makeSuite(TestTrust)
44 if __name__ == '__main__':
45 sys.argv.append('-v')
46 unittest.main()