Commit fd9ec558 authored by Romain Courteaud's avatar Romain Courteaud

Check the method getUserByLogin.

Keep compatibility with previous implementation in order to accept non iterable
parameter as login.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21240 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 46239494
...@@ -192,6 +192,10 @@ class ERP5UserManager(BasePlugin): ...@@ -192,6 +192,10 @@ class ERP5UserManager(BasePlugin):
def _getUserByLogin(login, exact_match): def _getUserByLogin(login, exact_match):
# because we aren't logged in, we have to create our own # because we aren't logged in, we have to create our own
# SecurityManager to be able to access the Catalog # SecurityManager to be able to access the Catalog
if isinstance(login, list):
login = tuple(login)
elif not isinstance(login, tuple):
login = (str(login),)
sm = getSecurityManager() sm = getSecurityManager()
if sm.getUser().getId() != SUPER_USER: if sm.getUser().getId() != SUPER_USER:
newSecurityManager(self, self.getUser(SUPER_USER)) newSecurityManager(self, self.getUser(SUPER_USER))
......
...@@ -406,6 +406,40 @@ class TestLocalRoleManagement(ERP5TypeTestCase): ...@@ -406,6 +406,40 @@ class TestLocalRoleManagement(ERP5TypeTestCase):
self.failIf('Assignor' in self.failIf('Assignor' in
getSecurityManager().getUser().getRolesInContext(obj)) getSecurityManager().getUser().getRolesInContext(obj))
def testGetUserByLogin(self):
"""Test getUserByLogin method
"""
self.loginAsUser(self.username)
# getUserByLogin accept login as a string
self.portal.portal_caches.clearAllCache()
get_transaction().commit()
person_list = self.portal.acl_users.erp5_users.getUserByLogin(self.username)
self.assertEquals(1, len(person_list))
self.assertEquals(self.username, person_list[0].getReference())
# getUserByLogin accept login as a list
self.portal.portal_caches.clearAllCache()
get_transaction().commit()
person_list = self.portal.acl_users.erp5_users.getUserByLogin([self.username])
self.assertEquals(1, len(person_list))
self.assertEquals(self.username, person_list[0].getReference())
# getUserByLogin accept login as a tuple
self.portal.portal_caches.clearAllCache()
get_transaction().commit()
person_list = self.portal.acl_users.erp5_users.getUserByLogin((self.username,))
self.assertEquals(1, len(person_list))
self.assertEquals(self.username, person_list[0].getReference())
# PreferenceTool pass a user as parameter
user = getSecurityManager().getUser()
self.portal.portal_caches.clearAllCache()
get_transaction().commit()
person_list = self.portal.acl_users.erp5_users.getUserByLogin(user)
self.assertEquals(1, len(person_list))
self.assertEquals(self.username, person_list[0].getReference())
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestUserManagement)) suite.addTest(unittest.makeSuite(TestUserManagement))
......
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