Back to index

plone3  3.1.7
test_roles.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2004 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests of role-mapping machinery.
00014 
00015 $Id: test_roles.py 68496 2006-06-05 16:30:18Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from OFS.Folder import Folder
00022 from OFS.Application import Application
00023 from Products.DCWorkflow.utils \
00024      import modifyRolesForPermission, modifyRolesForGroup
00025 
00026 
00027 class RoleMapTests(unittest.TestCase):
00028 
00029     def setUp(self):
00030         self.app = Application()
00031         self.app.ob = Folder()
00032         self.ob = self.app.ob
00033         self.ob.__ac_local_roles__ = {
00034             '(Group) Administrators': ['Manager', 'Member'],
00035             '(Group) Users': ['Member'],
00036             }
00037         self.ob._View_Permission = ('Member', 'Manager')
00038         self.ob._View_management_screens_Permission = ('Manager',)
00039 
00040     def testModifyRolesForGroup(self):
00041         modifyRolesForGroup(
00042             self.ob, '(Group) Administrators', ['Owner'], ['Member', 'Owner'])
00043         modifyRolesForGroup(
00044             self.ob, '(Group) Users', [], ['Member'])
00045         self.assertEqual(self.ob.__ac_local_roles__, {
00046             '(Group) Administrators': ['Manager', 'Owner'],
00047             })
00048         modifyRolesForGroup(
00049             self.ob, '(Group) Administrators', ['Member'], ['Member', 'Owner'])
00050         modifyRolesForGroup(
00051             self.ob, '(Group) Users', ['Member'], ['Member'])
00052         self.assertEqual(self.ob.__ac_local_roles__, {
00053             '(Group) Administrators': ['Manager', 'Member'],
00054             '(Group) Users': ['Member'],
00055             })
00056 
00057     def testModifyRolesForPermission(self):
00058         modifyRolesForPermission(self.ob, 'View', ['Manager'])
00059         modifyRolesForPermission(
00060             self.ob, 'View management screens', ['Member'])
00061         self.assertEqual(self.ob._View_Permission, ['Manager'])
00062         self.assertEqual(
00063             self.ob._View_management_screens_Permission, ['Member'])
00064 
00065 
00066 def test_suite():
00067     return unittest.TestSuite((
00068         unittest.makeSuite(RoleMapTests),
00069         ))
00070 
00071 if __name__ == '__main__':
00072     unittest.main(defaultTest='test_suite')