def test_delegation(self):
        threadlocals.push_frame()
        d = threadlocals.get_thread_locals()
        d["user_kw"] = self.u2
        d["test_kw"] = self.u1

        # Test allowed delegation
        self.assertRaises(PermissionDenied, self.objs[0].get_val_x2,
                          self.objs[0])
        self.assertRaises(PermissionDenied, self.objs[1].get_val_x2,
                          self.objs[1])
        
        give_permission_to("can_get_x2", self.objs[0], self.u2,
                           giver=self.u1, can_delegate=True)
        
        self.assertEqual(self.objs[0].get_val_x2(), 2)
        self.assertRaises(PermissionDenied, self.objs[1].get_val_x2,
                          self.objs[1])

        give_permission_to("can_get_x2", self.objs[1], self.u2,
                           giver=self.u1, can_delegate=False)

        self.assertEqual(self.objs[1].get_val_x2(), 2)
        
        # Test disallowed delegation
        self.assertRaises(PermissionCannotBeDelegated,
                          give_permission_to,
                          "can_get_x3", self.objs[0], self.u1,
                          giver=self.u2, can_delegate=False)
        
        d["user_kw"] = self.u1
        self.assertRaises(PermissionDenied, self.objs[0].get_val_x3_other_val,
                          self.objs[0])
        self.assertRaises(PermissionDenied, self.objs[1].get_val_x3_other_val,
                          self.objs[1])
        
        # Test cross delegation between types
        give_permission_to("can_get_x4", self.objs[0], self.u1,
                           giver=self.o3, can_delegate=False)
        
        self.assertEqual(self.objs[0].get_val_x4(), 4)

        # Test delegation of delegated permission
        self.assertRaises(PermissionCannotBeDelegated,
                          give_permission_to,
                          "can_get_x4", self.objs[0], self.u2,
                          giver=self.u1, can_delegate=False)
        
        give_permission_to("can_get_x2", self.objs[0], self.o3,
                           giver=self.u2, can_delegate=True)
Tests that permission delegation works correctly.
dataset/ETHPy150Open fp7-ofelia/ocf/expedient/src/python/expedient/common/permissions/tests/tests.py/TestObjectPermissions.test_delegation