Commit 69ee3928 authored by Jérome Perrin's avatar Jérome Perrin

- use self.login instead of manually setting a security manager

- fix test title


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31640 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b18aa690
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
import unittest import unittest
import transaction import transaction
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.SecurityManagement import getSecurityManager from AccessControl.SecurityManagement import getSecurityManager
from zExceptions import Unauthorized from zExceptions import Unauthorized
...@@ -49,13 +48,12 @@ default_large_image_height, = [pref.get('default') ...@@ -49,13 +48,12 @@ default_large_image_height, = [pref.get('default')
class TestPreferences(ERP5TypeTestCase): class TestPreferences(ERP5TypeTestCase):
def getTitle(self): def getTitle(self):
return "Portal Preference" return "Portal Preferences"
def afterSetUp(self): def afterSetUp(self):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('manager', '', ['Manager', 'Assignor', ], []) uf._doAddUser('manager', '', ['Manager', 'Assignor', ], [])
user = uf.getUserById('manager').__of__(uf) self.login('manager')
newSecurityManager(None, user)
self.createPreferences() self.createPreferences()
def beforeTearDown(self): def beforeTearDown(self):
...@@ -286,12 +284,9 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -286,12 +284,9 @@ class TestPreferences(ERP5TypeTestCase):
# create 2 users: user_a and user_b # create 2 users: user_a and user_b
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('user_a', '', ['Member', ], []) uf._doAddUser('user_a', '', ['Member', ], [])
user_a = uf.getUserById('user_a').__of__(uf)
uf._doAddUser('user_b', '', ['Member', ], []) uf._doAddUser('user_b', '', ['Member', ], [])
user_b = uf.getUserById('user_b').__of__(uf)
# log as user_a self.login('user_a')
newSecurityManager(None, user_a)
# create 2 prefs as user_a # create 2 prefs as user_a
user_a_1 = portal_preferences.newContent( user_a_1 = portal_preferences.newContent(
...@@ -306,8 +301,7 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -306,8 +301,7 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEquals(user_a_1.getPreferenceState(), 'enabled') self.assertEquals(user_a_1.getPreferenceState(), 'enabled')
self.assertEquals(user_a_2.getPreferenceState(), 'disabled') self.assertEquals(user_a_2.getPreferenceState(), 'disabled')
# log as user_b self.login('user_b')
newSecurityManager(None, user_b)
# create a pref for user_b # create a pref for user_b
user_b_1 = portal_preferences.newContent( user_b_1 = portal_preferences.newContent(
...@@ -326,8 +320,7 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -326,8 +320,7 @@ class TestPreferences(ERP5TypeTestCase):
# Checks that a manager preference doesn't disable any other user # Checks that a manager preference doesn't disable any other user
# preferences # preferences
# log as manager self.login('manager')
newSecurityManager(None, uf.getUserById('manager').__of__(uf))
self.assert_('Manager' in self.assert_('Manager' in
getSecurityManager().getUser().getRolesInContext(portal_preferences)) getSecurityManager().getUser().getRolesInContext(portal_preferences))
...@@ -409,7 +402,7 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -409,7 +402,7 @@ class TestPreferences(ERP5TypeTestCase):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('member', '', ['Member', ], []) uf._doAddUser('member', '', ['Member', ], [])
member = uf.getUserById('member').__of__(uf) member = uf.getUserById('member').__of__(uf)
newSecurityManager(None, member) self.login('member')
user_pref = preference_tool.newContent(portal_type='Preference') user_pref = preference_tool.newContent(portal_type='Preference')
# Members can copy & paste existing preferences # Members can copy & paste existing preferences
...@@ -465,8 +458,7 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -465,8 +458,7 @@ class TestPreferences(ERP5TypeTestCase):
# Members can't add new system preferences # Members can't add new system preferences
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('member', '', ['Member', ], []) uf._doAddUser('member', '', ['Member', ], [])
member = uf.getUserById('member').__of__(uf) self.login('member')
newSecurityManager(None, member)
self.assertRaises(Unauthorized, preference_tool.newContent, portal_type='System Preference') self.assertRaises(Unauthorized, preference_tool.newContent, portal_type='System Preference')
# But they can see others # But they can see others
system_pref.view() system_pref.view()
......
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