def test_simpledecision(self): doc = self._init_object() instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start("testing") self.assertEqual(controller.state, "active") wis = instance.getWorkItems(state='active') self.assertEqual(1, len(wis)) # configuration self.assertEqual('config_deci_1', wis[0].getActivity().getId()) instance.deci_1_assignees = ["editor1", "editor3"] wis[0].configure() wis = instance.getWorkItems(state='active') self.assertEqual(2, len(wis)) wis[0].reject() wis[1].accept() wis = instance.getWorkItems(state='active') self.assertEqual(3, len(wis)) wis[0].accept() wis[1].accept() wis[2].reject() wis = instance.getWorkItems(state='active') self.assertEqual(2, len(wis)) wis[0].accept() wis[1].accept() wis = instance.getWorkItems(state='active') self.assertEqual(0, len(wis)) self.assertEqual('ended', controller.state)
def test_delayed_discriminator(self): portal = self.portal self._create_test_users() self.loginAsPortalOwner() self._import_wf('workflows/routing_delayed_discriminator.alf') wftool = getToolByName(portal, 'workflow_manager') # Create object for instanciation of this process portal.createObject("testdocument", "DummyContent") # Initialize the process doc = portal.testdocument doc.assignProcess(self.test_process) process = doc.getInstance() controller = ILifeCycleController(process) controller.start("testing") self.assertEquals(controller.state, "active") self.login("author") doc.getWorkItemsForCurrentUser()[0].accept() doc.getWorkItemsForCurrentUser()[0].accept() doc.getWorkItemsForCurrentUser()[0].accept() self.assertEquals(controller.state, "ended") self.assertEquals(controller.completed, True) wis = process.getWorkItems(state=None) for wi in wis: self.failIfEqual(wi.state, "failed") # Do the same process but reject this time self.loginAsPortalOwner() doc.assignProcess(self.test_process) process = doc.getInstance() controller = ILifeCycleController(process) controller.start("testing") self.assertEquals(controller.state, "active") self.login("author") doc.getWorkItemsForCurrentUser()[0].reject() self.assertEquals(controller.state, "active") doc.getWorkItemsForCurrentUser()[0].accept() doc.getWorkItemsForCurrentUser()[0].accept() self.assertEquals(controller.state, "ended") self.assertEquals(controller.completed, True) wis = process.getWorkItems(state=None) for wi in wis: self.failIfEqual(wi.state, "failed")
def test_grouped_schema_not_all(self): self._import_wf("workflows/configuration.alf") portal = self.portal alf = getToolByName(portal, 'workflow_manager') doc = self.create(portal, "DummyContent", "doc") doc.assignProcess(self.test_process) instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start('test') wis = instance.getWorkItems() self.assertEqual(1, len(wis)) gs = wis[0].getGroupedSchema() act_ids_expected = ['write_doc', 'review', 'assign_task'] act_ids_expected.sort() act_ids_got = [g.activity_id for g in gs] act_ids_got.sort() self.assertEquals(act_ids_expected, act_ids_got)
def test_show(self): doc = self._init_object(workflow="workflows/task_show.alf") instance = doc.getInstance() process = instance.getProcess() self.assertEquals(True, process['visible'].showInWorkList) self.assertEquals(False, process['hidden'].showInWorkList) controller = ILifeCycleController(instance) controller.start("testing") self.assertEquals(2, len(instance.getWorkItems())) wftool = getToolByName(self.portal, 'workflow_manager') worklist = wftool.queryWorkItemsForCurrentUser() self.assertEquals(1, len(worklist)) wi = worklist[0]['wi'].getObject() self.assertEquals('visible', wi.getActivity().getId())
def test_grouped_schema_all(self): self._create_test_users() self._import_wf('workflows/multi_review_with_config.alf') portal = self.portal alf = getToolByName(portal, 'workflow_manager') portal.invokeFactory("DummyContent", "doc") doc = portal.doc doc.assignProcess(self.test_process) instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start('test') wis = instance.getWorkItems() self.assertEqual(1, len(wis)) gs = wis[0].getGroupedSchema() act_ids_expected = sorted(['write_document', 'review_document1', 'review_document2', 'config_at_start']) act_ids_got = sorted([g.activity_id for g in gs]) self.assertEquals(act_ids_expected, act_ids_got) self.assertEquals(gs[0].Title(), 'Dokument schreiben')
def test_multiple_filtered_configuration(self): self._import_wf('workflows/simple_review_choose_reviewer.alf') portal = self.portal alf = getToolByName(portal, 'workflow_manager') portal.invokeFactory("DummyFolder", "testfolder") doc = portal.testfolder doc.assignProcess(self.test_process) instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start('test') wis = instance.getWorkItems() self.assertEqual(1, len(wis)) gs = wis[0].getGroupedSchema() # We have to check the normal Schema of the activity as well. # One bug once had the correct grouped schema but the normal # Schema() method which AT uses still included _all_ possible # configuration items. Stupid. schema_fields = wis[0].Schema().keys() self.failIf("review_draft_assignees" in schema_fields, "review_draft_assginees should not be available")
def test_1yes_part(self): doc = self._init_object() instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start("testing") self.assertEqual(controller.state, "active") wis = instance.getWorkItems(state='active') self.assertEqual(len(wis), 1) # deci_1 self.assertEqual(wis[0].getActivity().getId(), "deci_1") # test what happened to the commentfield # should be not required, but hidden wischema = wis[0].Schema() expected = {'edit':-1, 'view':-1} self.assertEqual(wischema['comment'].required, False) self.assertEqual(wischema['comment'].widget.visible, expected) # test first yes self.login('editor2') doc = self._get_object() self._decide(doc, 'accept') instance = doc.getInstance() wis = instance.getWorkItems(state='active') self.assertEqual(len(wis), 1) # deci_n self.assertEqual(wis[0].getActivity().getId(), "deci_n") # test what happened to the commentfield # should be not required, but hidden wischema = wis[0].Schema() expected = {'edit':'visible', 'view':'visible'} self.assertEqual(wischema['comment'].required, True) self.assertEqual(wischema['comment'].widget.visible, expected) # test all yes self.login('editor1') doc = self._get_object() self._decide(doc, 'accept') instance = doc.getInstance() wis = instance.getWorkItems(state='active') self.assertEqual(len(wis), 1) # deci_n self.assertEqual(wis[0].getActivity().getId(), "deci_n") self.login('editor3') doc = self._get_object() self._decide(doc, 'accept') instance = doc.getInstance() wis = instance.getWorkItems(state='active') self.assertEqual(len(wis), 1) # deci_n self.assertEqual(wis[0].getActivity().getId(), "deci_n") # Log entry support entry = Products.AlphaFlow.activities.decision.DecisionLogEntry(wis[0]) self.assertEquals(3, len(entry.users)) self.assertEquals('editor3: accepted<br/>editor1: accepted', entry.annotation) self.login('editor2') doc = self._get_object() self._decide(doc, 'accept') instance = doc.getInstance() self.failUnless(instance is None)
def test_definition(self): portal = self.portal wftool = getToolByName(portal, 'workflow_manager') doc = self._init_object() instance = doc.getInstance() controller = ILifeCycleController(instance) controller.start("testing") self.assertEquals("active", controller.state) wis = instance.getWorkItems() self.assertEquals(1, len(wis)) ntaskitem = wis[0] self.assert_(INTaskWorkItem.providedBy(ntaskitem)) actions = ntaskitem.getActions() self.assertEquals(5, len(actions)) self.assertEquals([True, True, True, False, False], [action.enabled for action in actions]) expected_titles = [ "Freigeben", "Mach alles kaputt", "Privat schalten", "Prufen lassen", "Wirf nen KeyError" ] titles_got = sorted(x.title for x in actions) self.assertEquals(expected_titles, titles_got) controller.terminate("peng!") def checkExit(action, result_state): doc.assignProcess(self.test_process) instance = doc.getInstance() ILifeCycleController(instance).start("wuff") ntaskitem = instance.getWorkItems()[0] try: ntaskitem.complete(exit=action) except: ILifeCycleController(instance).terminate('error') raise result = ntaskitem.getGeneratedWorkItems() self.assertEquals(0, len(result)) result_exits = [ cp for cp in ntaskitem.objectValues() if IExitDefinition.providedBy(cp.getDefinition()) ] self.assertEquals(1, len(result_exits)) self.assertEquals(1, len(result_exits[0].objectValues())) result_aspect = result_exits[0].objectValues()[0].getDefinition() self.assertEquals(result_aspect.aspect_type, "dcworkflow") self.assertEquals(result_aspect.status, result_state) self.assertEquals(ILifeCycleController(ntaskitem).state, "ended") self.assertEquals(ILifeCycleController(ntaskitem).completed, True) # Check all exits checkExit("make_public", "published") checkExit("make_pending", "pending") checkExit("make_private", "private") self.assertRaises(RuntimeError, checkExit, "explode", "") self.assertRaises(RuntimeError, checkExit, "broken", "")