Commit 3472e9e9 authored by Łukasz Nowak's avatar Łukasz Nowak

- separate test data, so that it is not needed to delete person module

   between tests


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39186 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8633169a
...@@ -103,7 +103,6 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -103,7 +103,6 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
erp5_remote_manager_id = 'erp5_remote_user_manager' erp5_remote_manager_id = 'erp5_remote_user_manager'
system_preference_id = 'TestERP5RemoteUserManager' system_preference_id = 'TestERP5RemoteUserManager'
def setUpRemoteUserManager(self): def setUpRemoteUserManager(self):
acl_users = self.portal.acl_users acl_users = self.portal.acl_users
addERP5RemoteUserManager(acl_users, self.erp5_remote_manager_id) addERP5RemoteUserManager(acl_users, self.erp5_remote_manager_id)
...@@ -114,6 +113,8 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -114,6 +113,8 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
transaction.commit() transaction.commit()
def afterSetUp(self): def afterSetUp(self):
self.login = self.id()
self.password = self.login + 'password'
self.portal = self.getPortalObject() self.portal = self.getPortalObject()
self.createDummyWitchTool() self.createDummyWitchTool()
self.setUpRemoteUserManager() self.setUpRemoteUserManager()
...@@ -132,9 +133,6 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -132,9 +133,6 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
self.removeAuthenticationServerPreferences() self.removeAuthenticationServerPreferences()
transaction.commit() transaction.commit()
self.tic() self.tic()
self.person_module.deleteContent(list(self.person_module.objectIds()))
transaction.commit()
self.tic()
def removeAuthenticationServerPreferences(self): def removeAuthenticationServerPreferences(self):
portal_preferences = self.portal.portal_preferences portal_preferences = self.portal.portal_preferences
...@@ -184,32 +182,26 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -184,32 +182,26 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
############################################################################ ############################################################################
def test_correct_login(self): def test_correct_login(self):
"""Checks typical login scenario""" """Checks typical login scenario"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
def test_incorrect_login(self): def test_incorrect_login(self):
"""Checks that incorrect login does not work""" """Checks that incorrect login does not work"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': 'another_password'} kw = {'login':self.login, 'password': 'another_password'}
self.checkLogin(None, kw) self.checkLogin(None, kw)
def test_incorrect_login_in_case_of_no_connection(self): def test_incorrect_login_in_case_of_no_connection(self):
"""Checks that in case if there is no authentication server defined it is not possible to login""" """Checks that in case if there is no authentication server defined it is not possible to login"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
self.removeAuthenticationServerPreferences() self.removeAuthenticationServerPreferences()
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -217,13 +209,11 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -217,13 +209,11 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
def test_loggable_in_case_of_server_socket_error(self): def test_loggable_in_case_of_server_socket_error(self):
"""Check that in case if socket.error is raised login works from ZODB cache""" """Check that in case if socket.error is raised login works from ZODB cache"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -231,19 +221,17 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -231,19 +221,17 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
WizardTool.callRemoteProxyMethod = raises_socket_error WizardTool.callRemoteProxyMethod = raises_socket_error
self.assertRaises(socket.error, self.assertRaises(socket.error,
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
def test_loggable_in_case_of_server_socket_sslerror(self): def test_loggable_in_case_of_server_socket_sslerror(self):
"""Check that in case if socket.sslerror is raised login works from ZODB cache""" """Check that in case if socket.sslerror is raised login works from ZODB cache"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -251,19 +239,17 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -251,19 +239,17 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
WizardTool.callRemoteProxyMethod = raises_socket_sslerror WizardTool.callRemoteProxyMethod = raises_socket_sslerror
self.assertRaises(socket.sslerror, self.assertRaises(socket.sslerror,
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
def test_not_loggable_in_case_of_server_raises_anything_else(self): def test_not_loggable_in_case_of_server_raises_anything_else(self):
"""Check that in case if non socket is raised login does not works""" """Check that in case if non socket is raised login does not works"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -273,7 +259,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -273,7 +259,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.checkLogin(None, kw) self.checkLogin(None, kw)
# assert that ZODB cache is emptied # assert that ZODB cache is emptied
self.assertFalse(login in \ self.assertFalse(self.login in \
self.erp5_remote_manager.remote_authentication_cache) self.erp5_remote_manager.remote_authentication_cache)
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
...@@ -281,13 +267,11 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -281,13 +267,11 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
def test_loggable_in_case_of_server_socket_error_with_failed_login_between( def test_loggable_in_case_of_server_socket_error_with_failed_login_between(
self): self):
"""Check that in case if socket.sslerror is raised login works from ZODB cache, when wrong credentials was passed""" """Check that in case if socket.sslerror is raised login works from ZODB cache, when wrong credentials was passed"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -295,21 +279,19 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -295,21 +279,19 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
WizardTool.callRemoteProxyMethod = raises_socket_error WizardTool.callRemoteProxyMethod = raises_socket_error
self.assertRaises(socket.error, self.assertRaises(socket.error,
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
self.checkLogin(None, {'login':kw['login'], 'password':'wrong_password'}) self.checkLogin(None, {'login':kw['login'], 'password':'wrong_password'})
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
def test_loggable_in_case_of_server_socket_timeout(self): def test_loggable_in_case_of_server_socket_timeout(self):
"""Check that in case if socket.timeout is raised login works from ZODB cache""" """Check that in case if socket.timeout is raised login works from ZODB cache"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -317,19 +299,17 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -317,19 +299,17 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
WizardTool.callRemoteProxyMethod = raises_socket_timeout WizardTool.callRemoteProxyMethod = raises_socket_timeout
self.assertRaises(socket.timeout, self.assertRaises(socket.timeout,
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
def test_loggable_in_case_of_server_gaierror(self): def test_loggable_in_case_of_server_gaierror(self):
"""Check that in case if socket.gaierror is raised login works from ZODB cache""" """Check that in case if socket.gaierror is raised login works from ZODB cache"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -337,19 +317,17 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -337,19 +317,17 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
WizardTool.callRemoteProxyMethod = raises_socket_gaierror WizardTool.callRemoteProxyMethod = raises_socket_gaierror
self.assertRaises(socket.gaierror, self.assertRaises(socket.gaierror,
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
def test_loggable_in_case_of_server_gaierror_normal_cache(self): def test_loggable_in_case_of_server_gaierror_normal_cache(self):
"""Check that in case if socket.gaierror is raised login works from usual cache""" """Check that in case if socket.gaierror is raised login works from usual cache"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
expected = (login, login) expected = (self.login, self.login)
sent = kw sent = kw
self.assertEqual(expected, self.assertEqual(expected,
self.erp5_remote_manager.authenticateCredentials(sent)) self.erp5_remote_manager.authenticateCredentials(sent))
...@@ -367,13 +345,11 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -367,13 +345,11 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
def test_loggable_in_case_of_server_raises_anythin_else_normal_cache(self): def test_loggable_in_case_of_server_raises_anythin_else_normal_cache(self):
"""Check that in case if non socket is raised login works from usual cache""" """Check that in case if non socket is raised login works from usual cache"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
expected = (login, login) expected = (self.login, self.login)
sent = kw sent = kw
self.assertEqual(expected, self.assertEqual(expected,
self.erp5_remote_manager.authenticateCredentials(sent)) self.erp5_remote_manager.authenticateCredentials(sent))
...@@ -391,12 +367,10 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -391,12 +367,10 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
def test_not_loggable_in_case_of_server_gaierror_no_log_before(self): def test_not_loggable_in_case_of_server_gaierror_no_log_before(self):
"""Check that in case if socket.gaierror is raised login does not work in case of empty ZODB cache""" """Check that in case if socket.gaierror is raised login does not work in case of empty ZODB cache"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -410,17 +384,15 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -410,17 +384,15 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
def test_wrong_login_clears_zodb_cache(self): def test_wrong_login_clears_zodb_cache(self):
"""Check that wrong login attempt clears ZODB cache""" """Check that wrong login attempt clears ZODB cache"""
login = 'someone' self.createPerson(self.login, self.password)
password = 'somepass'
self.createPerson(login, password)
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':self.login, 'password': self.password}
self.checkLogin((login, login), kw) self.checkLogin((self.login, self.login), kw)
self.assertTrue(login in \ self.assertTrue(self.login in \
self.erp5_remote_manager.remote_authentication_cache) self.erp5_remote_manager.remote_authentication_cache)
self.checkLogin(None, {'login':kw['login'], 'password':'wrong_password'}) self.checkLogin(None, {'login':kw['login'], 'password':'wrong_password'})
self.assertFalse(login in \ self.assertFalse(self.login in \
self.erp5_remote_manager.remote_authentication_cache) self.erp5_remote_manager.remote_authentication_cache)
def test_suite(): def test_suite():
......
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