Commit 31b55e4c authored by Romain Courteaud's avatar Romain Courteaud

Remove created worklist at the end of the test, in order to prevent other tests

to fail.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27757 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 943cf756
...@@ -174,6 +174,10 @@ class TestWorklist(ERP5TypeTestCase): ...@@ -174,6 +174,10 @@ class TestWorklist(ERP5TypeTestCase):
(k.startswith('guard_') and k or 'var_match_'+k, v) (k.startswith('guard_') and k or 'var_match_'+k, v)
for k, v in kw.iteritems())) for k, v in kw.iteritems()))
def removeWorklist(self, workflow_id, worklist_id_list):
worklists = self.getWorkflowTool()[workflow_id].worklists
worklists.deleteWorklists(worklist_id_list)
def createWorklists(self): def createWorklists(self):
for worklist_id, actbox_name, role, expr, state, int_variable in [ for worklist_id, actbox_name, role, expr, state, int_variable in [
(self.worklist_assignor_id, self.actbox_assignor_name, (self.worklist_assignor_id, self.actbox_assignor_name,
...@@ -195,6 +199,16 @@ class TestWorklist(ERP5TypeTestCase): ...@@ -195,6 +199,16 @@ class TestWorklist(ERP5TypeTestCase):
validation_state=state, validation_state=state,
**{self.int_catalogued_variable_id: int_variable}) **{self.int_catalogued_variable_id: int_variable})
def removeWorklists(self):
self.removeWorklist(self.checked_workflow, [
self.worklist_assignor_id,
self.worklist_owner_id,
self.worklist_desactivated_id,
self.worklist_wrong_state_id,
self.worklist_assignor_owner_id,
self.worklist_int_variable_id,
])
def clearCache(self): def clearCache(self):
self.portal.portal_caches.clearAllCache() self.portal.portal_caches.clearAllCache()
...@@ -222,124 +236,127 @@ class TestWorklist(ERP5TypeTestCase): ...@@ -222,124 +236,127 @@ class TestWorklist(ERP5TypeTestCase):
self.addWorkflowCataloguedVariable(self.checked_workflow, self.addWorkflowCataloguedVariable(self.checked_workflow,
self.int_catalogued_variable_id) self.int_catalogued_variable_id)
self.createWorklists() self.createWorklists()
self.logMessage("Create document as Manager") try:
document = self.createDocument() self.logMessage("Create document as Manager")
document = self.createDocument()
transaction.commit()
self.tic()
self.clearCache()
result = workflow_tool.listActions(object=document) transaction.commit()
self.tic()
self.clearCache()
# Users can not see worklist as they are not Assignor
for user_id in ('manager', ):
self.login(user_id)
result = workflow_tool.listActions(object=document) result = workflow_tool.listActions(object=document)
self.logMessage("Check %s worklist as Assignor" % user_id)
self.checkWorklist(result, self.actbox_assignor_name, 0) # Users can not see worklist as they are not Assignor
self.logMessage("Check %s worklist as Owner" % user_id) for user_id in ('manager', ):
self.checkWorklist(result, self.actbox_owner_name, 1) self.login(user_id)
for user_id in ('foo', 'bar'): result = workflow_tool.listActions(object=document)
self.logMessage("Check %s worklist" % user_id) self.logMessage("Check %s worklist as Assignor" % user_id)
self.checkWorklist(result, self.actbox_assignor_name, 0)
self.logMessage("Check %s worklist as Owner" % user_id)
self.checkWorklist(result, self.actbox_owner_name, 1)
for user_id in ('foo', 'bar'):
self.logMessage("Check %s worklist" % user_id)
self.login(user_id)
result = workflow_tool.listActions(object=document)
self.assertEquals(result, [])
for role, user_id_list in (('Assignor', ('foo', 'manager')),
('Assignee', ('foo', 'bar'))):
self.login('manager')
for user_id in user_id_list:
self.logMessage("Give %s %s role" % (user_id, role))
document.manage_addLocalRoles(user_id, [role])
document.reindexObject()
transaction.commit()
self.tic()
self.clearCache()
for user_id, assignor, owner, both in (('manager', 1, 1, 1),
('bar' , 0, 0, 0),
('foo' , 1, 0, 1)):
self.login(user_id)
result = workflow_tool.listActions(object=document)
self.logMessage(" Check %s worklist as Assignor" % user_id)
self.checkWorklist(result, self.actbox_assignor_name, assignor)
self.logMessage(" Check %s worklist as Owner" % user_id)
self.checkWorklist(result, self.actbox_owner_name, owner)
self.logMessage(" Check %s worklist as Owner and Assignor" % user_id)
self.checkWorklist(result, self.actbox_assignor_owner_name, both)
# Check if int variable are managed by the worklist
user_id = 'manager'
self.login(user_id) self.login(user_id)
result = workflow_tool.listActions(object=document) result = workflow_tool.listActions(object=document)
self.assertEquals(result, []) self.logMessage("Check %s worklist with int value as %s" % \
(user_id, self.int_value))
self.checkWorklist(result, self.actbox_int_variable_name, 1)
for role, user_id_list in (('Assignor', ('foo', 'manager')), # Change int value on document
('Assignee', ('foo', 'bar'))): new_value = self.int_value + 1
self.login('manager') document.setProperty(self.int_catalogued_variable_id, new_value)
for user_id in user_id_list:
self.logMessage("Give %s %s role" % (user_id, role))
document.manage_addLocalRoles(user_id, [role])
document.reindexObject()
transaction.commit() transaction.commit()
self.tic() self.tic()
self.clearCache() self.clearCache()
for user_id, assignor, owner, both in (('manager', 1, 1, 1), result = workflow_tool.listActions(object=document)
('bar' , 0, 0, 0), self.logMessage("Check %s worklist with int value as %s" % \
('foo' , 1, 0, 1)): (user_id, new_value))
self.login(user_id) self.checkWorklist(result, self.actbox_int_variable_name, 0)
result = workflow_tool.listActions(object=document)
self.logMessage(" Check %s worklist as Assignor" % user_id)
self.checkWorklist(result, self.actbox_assignor_name, assignor)
self.logMessage(" Check %s worklist as Owner" % user_id)
self.checkWorklist(result, self.actbox_owner_name, owner)
self.logMessage(" Check %s worklist as Owner and Assignor" % user_id)
self.checkWorklist(result, self.actbox_assignor_owner_name, both)
# Check if int variable are managed by the worklist
user_id = 'manager'
self.login(user_id)
result = workflow_tool.listActions(object=document)
self.logMessage("Check %s worklist with int value as %s" % \
(user_id, self.int_value))
self.checkWorklist(result, self.actbox_int_variable_name, 1)
# Change int value on document
new_value = self.int_value + 1
document.setProperty(self.int_catalogued_variable_id, new_value)
transaction.commit()
self.tic()
self.clearCache()
result = workflow_tool.listActions(object=document) #
self.logMessage("Check %s worklist with int value as %s" % \ # Check monovalued security role
(user_id, new_value)) #
self.checkWorklist(result, self.actbox_int_variable_name, 0) self.login('manager')
module = self.getPortal().getDefaultModule(self.checked_portal_type)
module.manage_setLocalRoles('bar', ['Author'])
# self.login('bar')
# Check monovalued security role
#
self.login('manager')
module = self.getPortal().getDefaultModule(self.checked_portal_type)
module.manage_setLocalRoles('bar', ['Author'])
self.login('bar') bar_document = self.createDocument()
bar_document.manage_permission('View', ['Owner', 'Assignee'], 0)
bar_document = self.createDocument() bar_assignee_document = self.createDocument()
bar_document.manage_permission('View', ['Owner', 'Assignee'], 0) bar_assignee_document.manage_setLocalRoles('manager', ['Assignee'])
bar_assignee_document.manage_permission('View', ['Owner', 'Assignee'], 0)
bar_assignee_document = self.createDocument() user_id = 'manager'
bar_assignee_document.manage_setLocalRoles('manager', ['Assignee']) self.login(user_id)
bar_assignee_document.manage_permission('View', ['Owner', 'Assignee'], 0)
user_id = 'manager' module.manage_delLocalRoles('bar')
self.login(user_id)
module.manage_delLocalRoles('bar') def test(*count_list):
local_role_list = 'Assignee', 'Owner'
document.manage_setLocalRoles('manager', local_role_list)
def test(*count_list): for i, count in enumerate(count_list):
local_role_list = 'Assignee', 'Owner' document.manage_permission('View', local_role_list[:i], 0)
document.manage_setLocalRoles('manager', local_role_list) document.reindexObject()
transaction.commit()
self.tic()
self.clearCache()
for i, count in enumerate(count_list): result = workflow_tool.listActions(object=document)
document.manage_permission('View', local_role_list[:i], 0) self.logMessage("Check %s worklist as Owner (%s)" % (user_id, count))
document.reindexObject() self.checkWorklist(result, self.actbox_owner_name, count)
transaction.commit()
self.tic()
self.clearCache()
result = workflow_tool.listActions(object=document)
self.logMessage("Check %s worklist as Owner (%s)" % (user_id, count))
self.checkWorklist(result, self.actbox_owner_name, count)
test(0, 0, 1) test(0, 0, 1)
# Define a local role key # Define a local role key
sql_catalog = self.portal.portal_catalog.getSQLCatalog() sql_catalog = self.portal.portal_catalog.getSQLCatalog()
current_sql_catalog_local_role_keys = \ current_sql_catalog_local_role_keys = \
sql_catalog.sql_catalog_local_role_keys sql_catalog.sql_catalog_local_role_keys
sql_catalog.sql_catalog_local_role_keys = ('Owner | owner', ) sql_catalog.sql_catalog_local_role_keys = ('Owner | owner', )
transaction.commit() transaction.commit()
self.portal.portal_caches.clearAllCache() self.portal.portal_caches.clearAllCache()
try: try:
test(0, 1, 1) test(0, 1, 1)
finally:
sql_catalog.sql_catalog_local_role_keys = \
current_sql_catalog_local_role_keys
transaction.commit()
finally: finally:
sql_catalog.sql_catalog_local_role_keys = \ self.removeWorklists()
current_sql_catalog_local_role_keys
transaction.commit()
def test_02_related_key(self, quiet=0, run=run_all_test): def test_02_related_key(self, quiet=0, run=run_all_test):
""" """
...@@ -369,28 +386,32 @@ class TestWorklist(ERP5TypeTestCase): ...@@ -369,28 +386,32 @@ class TestWorklist(ERP5TypeTestCase):
portal_type=self.checked_portal_type, portal_type=self.checked_portal_type,
base_category_id='role') base_category_id='role')
document = self.createDocument() try:
transaction.commit() document = self.createDocument()
self.tic() transaction.commit()
self.clearCache() self.tic()
self.logMessage(" Check no document has region/role categories defined") self.clearCache()
result = workflow_tool.listActions(object=document) self.logMessage(" Check no document has region/role categories defined")
self.checkWorklist(result, 'has_region', 0) result = workflow_tool.listActions(object=document)
self.checkWorklist(result, 'has_role', 0) self.checkWorklist(result, 'has_region', 0)
self.checkWorklist(result, 'has_role', 0)
self.logMessage(" Creates documents with region/role categories defined") self.logMessage(" Creates documents with region/role categories defined")
self.createDocument(role='client') self.createDocument(role='client')
self.createDocument(region='somewhere') self.createDocument(region='somewhere')
self.createDocument(region='elsewhere') self.createDocument(region='elsewhere')
transaction.commit() transaction.commit()
self.tic() self.tic()
self.clearCache() self.clearCache()
self.logMessage( self.logMessage(
" Check there are documents with region/role categories defined") " Check there are documents with region/role categories defined")
result = workflow_tool.listActions(object=document) result = workflow_tool.listActions(object=document)
self.checkWorklist(result, 'has_region', 2) self.checkWorklist(result, 'has_region', 2)
self.checkWorklist(result, 'has_role', 1) self.checkWorklist(result, 'has_role', 1)
finally:
self.removeWorklist(self.checked_workflow,
['region_worklist', 'role_worklist'])
def test_03_worklist_guard(self, quiet=0, run=run_all_test): def test_03_worklist_guard(self, quiet=0, run=run_all_test):
""" """
...@@ -411,28 +432,32 @@ class TestWorklist(ERP5TypeTestCase): ...@@ -411,28 +432,32 @@ class TestWorklist(ERP5TypeTestCase):
guard_roles="Associate", guard_roles="Associate",
guard_expr='python: user.getId() == "bar"') guard_expr='python: user.getId() == "bar"')
document = self.createDocument() try:
document.manage_addLocalRoles("bar", ["Associate"]) document = self.createDocument()
document.manage_addLocalRoles("foo", ["Associate"]) document.manage_addLocalRoles("bar", ["Associate"])
document.validate() document.manage_addLocalRoles("foo", ["Associate"])
document.reindexObject() document.validate()
transaction.commit() document.reindexObject()
self.tic() transaction.commit()
self.clearCache() self.tic()
self.clearCache()
self.logMessage(" Check that manager can not access worklist") self.logMessage(" Check that manager can not access worklist")
result = workflow_tool.listActions(object=document) result = workflow_tool.listActions(object=document)
self.checkWorklist(result, 'valid_guard_expression', 0) self.checkWorklist(result, 'valid_guard_expression', 0)
self.logMessage(" Check that user bar can access worklist") self.logMessage(" Check that user bar can access worklist")
self.login('bar') self.login('bar')
result = workflow_tool.listActions(object=document) result = workflow_tool.listActions(object=document)
self.checkWorklist(result, 'valid_guard_expression', 1) self.checkWorklist(result, 'valid_guard_expression', 1)
self.logMessage(" Check that user foo can not access worklist") self.logMessage(" Check that user foo can not access worklist")
self.login('foo') self.login('foo')
result = workflow_tool.listActions(object=document) result = workflow_tool.listActions(object=document)
self.checkWorklist(result, 'valid_guard_expression', 0) self.checkWorklist(result, 'valid_guard_expression', 0)
finally:
self.removeWorklist(self.checked_workflow,
['guard_expression_worklist'])
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
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