restart all 3 service upon make sync
[sfa.git] / tests / testRights.py
1 import unittest
2 from sfa.trust.rights import *
3
4 class TestRight(unittest.TestCase):
5    def setUp(self):
6       pass
7
8    def testRightInit(self):
9       right = Right("embed")
10       self.assertEqual(right.kind, "embed")
11
12    def testRightCanPerform(self):
13       right = Right("embed")
14       self.assertTrue(right.can_perform("getticket"))
15       self.assertTrue(not right.can_perform("resolve"))
16
17    def testIsSuperset(self):
18       pright = Right("sa")
19       cright = Right("embed")
20       self.assertTrue(pright.is_superset(cright))
21       self.assertTrue(not cright.is_superset(pright))
22
23       pright = Right("embed")
24       cright = Right("embed")
25       self.assertTrue(pright.is_superset(cright))
26       self.assertTrue(cright.is_superset(pright))
27
28       pright = Right("control")
29       cright = Right("embed")
30       self.assertTrue(not pright.is_superset(cright))
31       self.assertTrue(not cright.is_superset(pright))
32
33 class TestRights(unittest.TestCase):
34     def setUp(self):
35         pass
36
37     def testInit(self):
38         # create a blank right list
39         rightList = Rights()
40
41         # create a right list with "embed" in it
42         rightList = Rights(string="embed")
43
44     def testAsString(self):
45         rightList = Rights()
46         self.assertEqual(rightList.save_to_string(), "")
47
48         rightList = Rights(string="embed")
49         self.assertEqual(rightList.save_to_string(), "embed")
50
51         rightList = Rights(string="embed,resolve")
52         self.assertEqual(rightList.save_to_string(), "embed,resolve")
53
54     def testCanPerform(self):
55         rightList = Rights(string="embed")
56         self.assertTrue(rightList.can_perform("getticket"))
57         self.assertTrue(not rightList.can_perform("resolve"))
58
59         rightList = Rights(string="embed,resolve")
60         self.assertTrue(rightList.can_perform("getticket"))
61         self.assertTrue(rightList.can_perform("resolve"))
62
63     def testIsSuperset(self):
64         pRights = Rights(string="sa")
65         cRights = Rights(string="embed")
66         self.assertTrue(pRights.is_superset(cRights))
67         self.assertTrue(not cRights.is_superset(pRights))
68
69         pRights = Rights(string="embed")
70         cRights = Rights(string="embed")
71         self.assertTrue(pRights.is_superset(cRights))
72         self.assertTrue(cRights.is_superset(pRights))
73
74         pRights = Rights(string="control")
75         cRights = Rights(string="embed")
76         self.assertTrue(not pRights.is_superset(cRights))
77         self.assertTrue(not cRights.is_superset(pRights))
78
79         pRights = Rights(string="control,sa")
80         cRights = Rights(string="embed")
81         self.assertTrue(pRights.is_superset(cRights))
82         self.assertTrue(not cRights.is_superset(pRights))
83
84
85 if __name__ == "__main__":
86     unittest.main()