Commit 1cb8e3c6 authored by Vincent Pelletier's avatar Vincent Pelletier

tests: Also change Owner local role on accounting_zuite_preference.

Also, reindex modified documents, as ownership and Owner role are
present in catalog.
parent 4dfafbc9
......@@ -5259,9 +5259,9 @@ class TestAccountingReportsWithAnalytic(AccountingTestCase, ERP5ReportTestCase):
self.login()
# change ownership of the preference
self.portal.portal_preferences.accounting_zuite_preference.changeOwnership(
getSecurityManager().getUser(),
True,
self.setSubtreeOwner(
document_value=self.portal.portal_preferences.accounting_zuite_preference,
user=getSecurityManager().getUser(),
)
# create some functions
......
......@@ -37,9 +37,9 @@ class TestRenderJSAccountingReport(ERP5TypeFunctionalTestCase):
def afterSetUp(self):
# change ownership of the preference
self.portal.portal_preferences.accounting_zuite_preference.changeOwnership(
getSecurityManager().getUser(),
True,
self.setSubtreeOwner(
document_value=self.portal.portal_preferences.accounting_zuite_preference,
user=getSecurityManager().getUser(),
)
super(TestRenderJSAccountingReport, self).afterSetUp()
......
......@@ -915,6 +915,67 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
)
self.tic()
def setDocumentOwner(self, document_value, user):
"""
Change both ownership and Owner local role on given document to given
user.
"""
try:
_, old_owner_user_id = document_value.getOwnerTuple()
except ValueError:
pass
else:
old_owner_local_role_set = list(document_value.get_local_roles_for_userid(
old_owner_user_id,
))
try:
old_owner_local_role_set.remove('Owner')
except ValueError:
pass
else:
if old_owner_local_role_set:
document_value.manage_setLocalRoles(
old_owner_user_id,
tuple(old_owner_local_role_set),
)
else:
document_value.manage_delLocalRoles(old_owner_user_id)
document_value.changeOwnership(user)
user_id = user.getId()
document_value.manage_setLocalRoles(
user_id,
document_value.get_local_roles_for_userid(user_id) + ('Owner', ),
)
document_value.reindexObject()
def immediateRecursiveCall(self, document_value, callback):
"""
Call given callback on document and all its subdocuments.
Obviously not scalable to large document trees (and hence is only in
tests and not in the regular ERP5 document API).
"""
stack = [document_value]
while stack:
document_value = stack.pop()
callback(document_value)
stack.extend(getattr(document_value, 'objectValues', lambda: ())())
stack.extend(getattr(document_value, 'opaqueValues', lambda: ())())
def setSubtreeOwner(self, document_value, user):
"""
Change owner of document_value and all its subdocuments to user.
See also setDocumentOwner.
"""
setDocumentOwner = self.setDocumentOwner
self.immediateRecursiveCall(
document_value=document_value,
callback=lambda document_value: setDocumentOwner(
document_value=document_value,
user=user,
),
)
class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
__original_ZMySQLDA_connect = None
......
......@@ -43,7 +43,10 @@ class TestZeleniumCore(ERP5TypeFunctionalTestCase):
None,
)
if pref is not None:
pref.changeOwnership(getSecurityManager().getUser(), True)
self.setSubtreeOwner(
document_value=pref,
user=getSecurityManager().getUser(),
)
super(TestZeleniumCore, self).afterSetUp()
def getBusinessTemplateList(self):
......
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