1 import os
2 import unittest
3 from openid.server.trustroot import TrustRoot
4
7 unittest.TestCase.__init__(self)
8 self.desc = desc + ': ' + repr(case)
9 self.case = case
10 self.sanity = sanity
11
14
16 tr = TrustRoot.parse(self.case)
17 if self.sanity == 'sane':
18 assert tr.isSane(), self.case
19 elif self.sanity == 'insane':
20 assert not tr.isSane(), self.case
21 else:
22 assert tr is None, tr
23
26 unittest.TestCase.__init__(self)
27 tr, rt = line.split()
28 self.desc = desc + ': ' + repr(tr) + ' ' + repr(rt)
29 self.tr = tr
30 self.rt = rt
31 self.match = match
32
35
37 tr = TrustRoot.parse(self.tr)
38 self.failIf(tr is None, self.tr)
39
40 match = tr.validateURL(self.rt)
41 if self.match:
42 assert match
43 else:
44 assert not match
45
47 tests = []
48 top = head.strip()
49 gdat = map(str.strip, dat.split('-' * 40 + '\n'))
50 assert not gdat[0]
51 assert len(gdat) == (len(grps) * 2 + 1), (gdat, grps)
52 i = 1
53 for x in grps:
54 n, desc = gdat[i].split(': ')
55 cases = gdat[i + 1].split('\n')
56 assert len(cases) == int(n)
57 for case in cases:
58 tests.append(t(x, top + ' - ' + desc, case))
59 i += 2
60 return tests
61
63 parts = map(str.strip, data.split('=' * 40 + '\n'))
64 assert not parts[0]
65 _, ph, pdat, mh, mdat = parts
66
67 tests = []
68 tests.extend(getTests(_ParseTest, ['bad', 'insane', 'sane'], ph, pdat))
69 tests.extend(getTests(_MatchTest, [1, 0], mh, mdat))
70 return tests
71
73 here = os.path.dirname(os.path.abspath(__file__))
74 test_data_file_name = os.path.join(here, 'data', 'trustroot.txt')
75 test_data_file = file(test_data_file_name)
76 test_data = test_data_file.read()
77 test_data_file.close()
78
79 tests = parseTests(test_data)
80 return unittest.TestSuite(tests)
81
82 if __name__ == '__main__':
83 suite = pyUnitTests()
84 runner = unittest.TextTestRunner()
85 runner.run(suite)
86