Commit 423fe30f authored by Julien Muchembled's avatar Julien Muchembled

testERP5Security: test multiple assignements

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33124 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d1c1aa0c
...@@ -375,7 +375,7 @@ class TestLocalRoleManagement(ERP5TypeTestCase): ...@@ -375,7 +375,7 @@ class TestLocalRoleManagement(ERP5TypeTestCase):
# add another function subcategory. # add another function subcategory.
self.getCategoryTool()['function'].newContent(portal_type='Category', self.getCategoryTool()['function'].newContent(portal_type='Category',
id='another_subcat', id='another_subcat',
codification='Function2') codification='F2')
self.defined_category = "group/subcat\n"\ self.defined_category = "group/subcat\n"\
"site/subcat\n"\ "site/subcat\n"\
"function/subcat" "function/subcat"
...@@ -455,33 +455,60 @@ class TestLocalRoleManagement(ERP5TypeTestCase): ...@@ -455,33 +455,60 @@ class TestLocalRoleManagement(ERP5TypeTestCase):
role_name='Assignor', role_name='Assignor',
description='desc.', description='desc.',
title='an Assignor role for testing', title='an Assignor role for testing',
role_category=self.defined_category, role_category=self.defined_category)
role_base_category_script_id='ERP5Type_getSecurityCategoryFromAssignment')
obj = self._makeOne()
self.assertEquals(['Assignor'], obj.__ac_local_roles__.get('F1_G1_S1'))
self.loginAsUser(self.username) self.loginAsUser(self.username)
self.failUnless('Assignor' in user = getSecurityManager().getUser()
getSecurityManager().getUser().getRolesInContext(obj))
obj = self._makeOne()
self.assertEqual(['Assignor'], obj.__ac_local_roles__.get('F1_G1_S1'))
self.assertTrue('Assignor' in user.getRolesInContext(obj))
self.assertFalse('Assignee' in user.getRolesInContext(obj))
transaction.abort()
def testDynamicLocalRole(self): def testDynamicLocalRole(self):
"""Test simple case of setting a dynamic role. """Test simple case of setting a dynamic role.
The site category is not defined explictly the role, and will have the The site category is not defined explictly the role, and will have the
current site of the user. current site of the user.
""" """
for role, function in (('Assignee', 'subcat'),
('Assignor', 'another_subcat')):
self._getTypeInfo().newContent(portal_type='Role Information', self._getTypeInfo().newContent(portal_type='Role Information',
role_name='Assignor', role_name=role,
description='desc.',
title='an Assignor role for testing', title='an Assignor role for testing',
role_category_list=('group/subcat', 'function/subcat'), role_category_list=('group/subcat', 'function/' + function),
role_base_category_script_id='ERP5Type_getSecurityCategoryFromAssignment', role_base_category_script_id='ERP5Type_getSecurityCategoryFromAssignment',
role_base_category='site') role_base_category='site')
self.loginAsUser(self.username)
user = getSecurityManager().getUser()
obj = self._makeOne()
self.assertEqual(['Assignee'], obj.__ac_local_roles__.get('F1_G1_S1'))
self.assertEqual(['Assignor'], obj.__ac_local_roles__.get('F2_G1_S1'))
self.assertTrue('Assignee' in user.getRolesInContext(obj))
self.assertFalse('Assignor' in user.getRolesInContext(obj))
transaction.abort()
def testSeveralFunctionsOnASingleAssignment(self):
"""Test dynamic role generation when an assignment defines several functions
"""
assignment, = self.portal.portal_catalog(portal_type='Assignment',
parent_reference=self.username)
assignment.setFunctionList(('subcat', 'another_subcat'))
self._getTypeInfo().newContent(portal_type='Role Information',
role_name='Assignee',
title='an Assignor role for testing',
role_category_list=('group/subcat', 'site/subcat'),
role_base_category_script_id='ERP5Type_getSecurityCategoryFromAssignment',
role_base_category='function')
self.loginAsUser(self.username) self.loginAsUser(self.username)
user = getSecurityManager().getUser()
obj = self._makeOne() obj = self._makeOne()
self.assertEquals(['Assignor'], obj.__ac_local_roles__.get('F1_G1_S1')) self.assertEqual(['Assignee'], obj.__ac_local_roles__.get('F1_G1_S1'))
self.failUnless('Assignor' in self.assertEqual(['Assignee'], obj.__ac_local_roles__.get('F2_G1_S1'))
getSecurityManager().getUser().getRolesInContext(obj)) self.assertTrue('Assignee' in user.getRolesInContext(obj))
self.assertFalse('Assignor' in user.getRolesInContext(obj))
transaction.abort()
def testAcquireLocalRoles(self): def testAcquireLocalRoles(self):
"""Tests that document does not acquire loal roles from their parents if """Tests that document does not acquire loal roles from their parents if
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment