Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
DCWorkflow.tests.test_guard.TestGuard Class Reference

List of all members.

Public Member Functions

def setUp
def test_BaseGuardAPI
def test_checkGuardExpr
def test_checkWithKwargs

Public Attributes

 site

Private Member Functions

def _getDummyWorkflow

Detailed Description

Definition at line 34 of file test_guard.py.


Member Function Documentation

Definition at line 46 of file test_guard.py.

00046 
00047     def _getDummyWorkflow(self):
00048         return self.site.portal_workflow['wf']

Here is the caller graph for this function:

Definition at line 36 of file test_guard.py.

00036 
00037     def setUp(self):
00038         self.site = DummySite('site')
00039         self.site._setObject( 'portal_types', DummyTool() )
00040         self.site._setObject( 'portal_workflow', WorkflowTool() )
00041 
00042         # Construct a workflow
00043         wftool = self.site.portal_workflow
00044         wftool._setObject('wf', DCWorkflowDefinition('wf'))
00045         wftool.setDefaultChain('wf')

Definition at line 49 of file test_guard.py.

00049 
00050     def test_BaseGuardAPI(self):
00051 
00052         #
00053         # Test guard basic API
00054         #
00055 
00056         guard = Guard()
00057         self.assertNotEqual(guard, None)
00058 
00059         # Test default values
00060         self.assertEqual(guard.getPermissionsText(), '')
00061         self.assertEqual(guard.getRolesText(), '')
00062         self.assertEqual(guard.getExprText(), '')
00063 
00064         # Initialize the guard with empty values
00065         # not initialization
00066         guard_props = {'guard_permissions':'',
00067                        'guard_roles':'',
00068                        'guard_expr' :''}
00069         res = guard.changeFromProperties(guard_props)
00070         self.assert_(res==0)
00071 
00072         # Test default values
00073         self.assertEqual(guard.getPermissionsText(), '')
00074         self.assertEqual(guard.getRolesText(), '')
00075         self.assertEqual(guard.getExprText(), '')
00076 
00077         # Change guard
00078         guard_props = {'guard_roles':'Manager',
00079                        'guard_permissions':'',
00080                        'guard_expr' :''}
00081         res = guard.changeFromProperties(guard_props)
00082         self.assert_(res==1)
00083         self.assertEqual(guard.getRolesText(), 'Manager')
00084         self.assertEqual(guard.getPermissionsText(), '')
00085         self.assertEqual(guard.getExprText(), '')
00086 
00087         # Change guard
00088         guard_props = {'guard_roles':'Manager;',
00089                        'guard_permissions':'',
00090                        'guard_expr' :''}
00091         res = guard.changeFromProperties(guard_props)
00092         self.assert_(res==1)
00093         # With one space after the ';'
00094         self.assertEqual(guard.getRolesText(), 'Manager; ')
00095         self.assertEqual(guard.getPermissionsText(), '')
00096         self.assertEqual(guard.getExprText(), '')
00097 
00098         # Change guard
00099         guard_props = {'guard_roles':'Manager;Member',
00100                        'guard_permissions':'',
00101                        'guard_expr' :''}
00102         res = guard.changeFromProperties(guard_props)
00103         self.assert_(res==1)
00104         # With one space after the ';'
00105         self.assertEqual(guard.getRolesText(), 'Manager; Member')
00106         self.assertEqual(guard.getPermissionsText(), '')
00107         self.assertEqual(guard.getExprText(), '')
00108 
00109         # Change guard
00110         guard_props = {'guard_roles':'Manager;Member',
00111                        'guard_permissions':'',
00112                        'guard_expr' :''}
00113         res = guard.changeFromProperties(guard_props)
00114         self.assert_(res==1)
00115         # With one space after the ';'
00116         self.assertEqual(guard.getRolesText(), 'Manager; Member')
00117         self.assertEqual(guard.getPermissionsText(), '')
00118         self.assertEqual(guard.getExprText(), '')
00119 
00120         # Change guard
00121         guard_props = {'guard_roles':'Manager',
00122                        'guard_permissions':'',
00123                        'guard_expr' :''}
00124         res = guard.changeFromProperties(guard_props)
00125         self.assert_(res==1)
00126         self.assertEqual(guard.getRolesText(), 'Manager')
00127         self.assertEqual(guard.getPermissionsText(), '')
00128         self.assertEqual(guard.getExprText(), '')
00129 
00130         # Change guard
00131         guard_props = {'guard_roles':'Manager',
00132                        'guard_permissions':'ManagePortal;',
00133                        'guard_expr' :''}
00134         res = guard.changeFromProperties(guard_props)
00135         self.assert_(res==1)
00136         self.assertEqual(guard.getRolesText(), 'Manager')
00137         self.assertEqual(guard.getPermissionsText(), 'ManagePortal; ')
00138         self.assertEqual(guard.getExprText(), '')
00139 
00140         # Change guard
00141         guard_props = {'guard_roles':'Manager',
00142                        'guard_permissions':'ManagePortal',
00143                        'guard_expr' :''}
00144         res = guard.changeFromProperties(guard_props)
00145         self.assert_(res==1)
00146         self.assertEqual(guard.getRolesText(), 'Manager')
00147         self.assertEqual(guard.getPermissionsText(), 'ManagePortal')
00148         self.assertEqual(guard.getExprText(), '')
00149 
00150         # Change guard
00151         guard_props = {'guard_roles':'Manager',
00152                        'guard_permissions':'ManagePortal',
00153                        'guard_expr' :'python:1'}
00154         res = guard.changeFromProperties(guard_props)
00155         self.assert_(res==1)
00156         self.assertEqual(guard.getRolesText(), 'Manager')
00157         self.assertEqual(guard.getPermissionsText(), 'ManagePortal')
00158         self.assertEqual(guard.getExprText(), 'python:1')
00159 
00160         # Change guard
00161         guard_props = {'guard_roles':'Manager',
00162                        'guard_permissions':'ManagePortal',
00163                        'guard_expr' :'string:'}
00164         res = guard.changeFromProperties(guard_props)
00165         self.assert_(res==1)
00166         self.assertEqual(guard.getRolesText(), 'Manager')
00167         self.assertEqual(guard.getPermissionsText(), 'ManagePortal')
00168         self.assertEqual(guard.getExprText(), 'string:')
00169 
00170         # Change guard with wrong TALES
00171         guard_props = {'guard_roles':'Manager',
00172                        'guard_permissions':'ManagePortal',
00173                        'guard_expr' :'python:'}
00174         self.assertRaises(CompilerError,
00175                           guard.changeFromProperties, guard_props)
00176 
00177         self.assertEqual(guard.getRolesText(), 'Manager')
00178         self.assertEqual(guard.getPermissionsText(), 'ManagePortal')
00179         self.assertEqual(guard.getExprText(), 'string:')
00180 
00181         # reinit the guard
00182         guard_props = {'guard_permissions':'',
00183                        'guard_roles':'',
00184                        'guard_expr' :''}
00185         res = guard.changeFromProperties(guard_props)
00186         self.assert_(res==0)
00187 
00188         # No API on DCWorkflow guard to reset properly....
00189         guard.permissions = ''
00190         guard.roles = ''
00191         guard.expr = None
00192 
00193         # Test default values
00194         self.assertEqual(guard.getPermissionsText(), '')
00195         self.assertEqual(guard.getRolesText(), '')
00196         self.assertEqual(guard.getExprText(), '')
00197 
00198         # XXX more tests with permissions and roles

Definition at line 199 of file test_guard.py.

00199 
00200     def test_checkGuardExpr(self):
00201 
00202         #
00203         # Basic checks.
00204         #
00205 
00206         guard = Guard()
00207 
00208         # Create compulsory context elements
00209         sm = getSecurityManager()
00210         self.site._setObject('dummy', DummyContent('dummy'))
00211         ob = self.site.dummy
00212         wf_def = self._getDummyWorkflow()
00213 
00214         # Initialize the guard with an ok guard
00215         guard_props = {'guard_permissions':'',
00216                        'guard_roles':'',
00217                        'guard_expr' :'python:1'}
00218 
00219         res = guard.changeFromProperties(guard_props)
00220         self.assert_(res)
00221         self.assert_(guard.check(sm, wf_def, ob))
00222 
00223         # Initialize the guard with a not ok guard
00224         guard_props = {'guard_permissions':'',
00225                        'guard_roles':'',
00226                        'guard_expr' :'python:0'}
00227         res = guard.changeFromProperties(guard_props)
00228         self.assert_(res)
00229         self.assert_(not guard.check(sm, wf_def, ob))
00230 
00231         # XXX more tests with permissions and roles

Here is the call graph for this function:

Definition at line 232 of file test_guard.py.

00232 
00233     def test_checkWithKwargs(self):
00234 
00235         #
00236         # Checks with kwargs
00237         #
00238 
00239         guard = Guard()
00240 
00241         # Create compulsory context elements
00242         sm = getSecurityManager()
00243         self.site._setObject('dummy', DummyContent('dummy'))
00244         ob = self.site.dummy
00245         wf_def = self._getDummyWorkflow()
00246 
00247         # Initialize the guard with an ok guard
00248         guard_props = {'guard_permissions':'',
00249                        'guard_roles':'',
00250                        'guard_expr' :'python:1'}
00251 
00252         res = guard.changeFromProperties(guard_props)
00253         self.assert_(res)
00254         self.assert_(guard.check(sm, wf_def, ob, arg1=1, arg2=2))
00255 
00256         # Initialize the guard with a not ok guard
00257         guard_props = {'guard_permissions':'',
00258                        'guard_roles':'',
00259                        'guard_expr' :'python:0'}
00260         res = guard.changeFromProperties(guard_props)
00261         self.assert_(res)
00262         self.assert_(not guard.check(sm, wf_def, ob, arg1=1, arg2=2))
00263 
00264         # XXX more tests with permissions and roles
00265 

Here is the call graph for this function:


Member Data Documentation

Definition at line 37 of file test_guard.py.


The documentation for this class was generated from the following file: