Commit 376c1b5f authored by Sebastien Robin's avatar Sebastien Robin

unit test: refactor code setting ERP5TypeTestCase user

Also by default this user will have random password
parent 2774123b
...@@ -14,6 +14,7 @@ import os ...@@ -14,6 +14,7 @@ import os
import random import random
import re import re
import socket import socket
import string
import sys import sys
import time import time
import traceback import traceback
...@@ -228,6 +229,18 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -228,6 +229,18 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
""" """
return str(self.__class__) return str(self.__class__)
def addERP5TypeTestCaseUser(self, password=None, user_folder=None):
if password is None:
password = self.newPassword()
if user_folder is None:
user_folder = self.portal.acl_users
user_folder._doAddUser('ERP5TypeTestCase', password, ['Manager', 'Member', 'Assignee',
'Assignor', 'Author', 'Auditor', 'Associate'], [])
def newPassword(self):
""" Generate a password """
return ''.join(random.SystemRandom().sample(string.letters + string.digits, 20))
def login(self, user_name='ERP5TypeTestCase', quiet=0): def login(self, user_name='ERP5TypeTestCase', quiet=0):
""" """
Most of the time, we need to login before doing anything Most of the time, we need to login before doing anything
...@@ -235,9 +248,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -235,9 +248,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
try: try:
PortalTestCase.login(self, user_name) PortalTestCase.login(self, user_name)
except AttributeError: except AttributeError:
uf = self.portal.acl_users self.addERP5TypeTestCaseUser()
uf._doAddUser('ERP5TypeTestCase', '', ['Manager', 'Member', 'Assignee',
'Assignor', 'Author', 'Auditor', 'Associate'], [])
return PortalTestCase.login(self, user_name) return PortalTestCase.login(self, user_name)
def changeSkin(self, skin_name): def changeSkin(self, skin_name):
...@@ -261,7 +272,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -261,7 +272,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
uf = self.portal.acl_users uf = self.portal.acl_users
# do nothing if the user already exists # do nothing if the user already exists
if not uf.getUserById(user_name): if not uf.getUserById(user_name):
uf._doAddUser(user_name, 'secret', ['Member'], []) uf._doAddUser(user_name, self.newPassword(), ['Member'], [])
def _setUpDummyMailHost(self): def _setUpDummyMailHost(self):
"""Replace Original Mail Host by Dummy Mail Host in a non-persistent way """Replace Original Mail Host by Dummy Mail Host in a non-persistent way
...@@ -717,6 +728,9 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -717,6 +728,9 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
def addERP5TypeTestCaseUser(self, password=None, **kw):
return super(ERP5TypeCommandLineTestCase, self).addERP5TypeTestCaseUser(password='', **kw)
def getPortalName(self): def getPortalName(self):
""" """
Return the name of a portal for this test case. Return the name of a portal for this test case.
...@@ -1035,8 +1049,7 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): ...@@ -1035,8 +1049,7 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
if not quiet: if not quiet:
ZopeTestCase._print('Adding ERP5TypeTestCase user ...\n') ZopeTestCase._print('Adding ERP5TypeTestCase user ...\n')
uf = app.acl_users uf = app.acl_users
uf._doAddUser('ERP5TypeTestCase', '', ['Manager', 'Member', 'Assignee', self.addERP5TypeTestCaseUser(user_folder=uf)
'Assignor', 'Author', 'Auditor', 'Associate'], [])
user = uf.getUserById('ERP5TypeTestCase').__of__(uf) user = uf.getUserById('ERP5TypeTestCase').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
...@@ -1097,8 +1110,7 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): ...@@ -1097,8 +1110,7 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
self._updateMemcachedConfiguration() self._updateMemcachedConfiguration()
# Create a Manager user at the Portal level # Create a Manager user at the Portal level
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('ERP5TypeTestCase', '', ['Manager', 'Member', 'Assignee', self.addERP5TypeTestCaseUser()
'Assignor', 'Author', 'Auditor', 'Associate'], [])
user = uf.getUserById('ERP5TypeTestCase').__of__(uf) user = uf.getUserById('ERP5TypeTestCase').__of__(uf)
self._callSetUpOnce() self._callSetUpOnce()
......
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