Exemplo n.º 1
0
    def test_task(self):
        portal = self.portal
        self._create_test_users()
        self.loginAsPortalOwner()
        portal = self.portal
        self._import_wf(path="workflows/task.alf")

        portal.invokeFactory('DummyContent', 'doc1')
        doc = portal.doc1
        doc.assignProcess(self.test_process)
        instance = doc.getInstance()

        ILifeCycleController(instance).start('testing')
        wi = instance.getWorkItems()

        # we expect 1 workitem due to wf defintion
        self.assertEquals(1, len(wi))

        # XXX This test should live somewhere else.
        self.assertEquals(None, wi[0].completed_by)

        # tasks should have one action
        actions = wi[0].getActions()
        self.assertEquals(1, len(actions))
        actions[0]()

        controller = ILifeCycleController(wi[0])
        self.assertEquals('ended', controller.state)
        self.assertEquals(True, controller.completed)

        # XXX This test should live somewhere else.
        self.assertEquals('portal_owner', wi[0].completed_by)
    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)
Exemplo n.º 3
0
    def test_recipient_owner(self):
        def _test_recipients(mode, expected_ids, wi):
            got_ids = mode.getRecipientsForWorkItem(wi)
            got_ids.sort()
            expected_ids.sort()
            self.assertEquals(expected_ids, got_ids)

        doc = self._init_object()
        instance = doc.getInstance()
        ILifeCycleController(instance).start("comment")
        wi = instance.getWorkItems(state="ended")[0]
        self.assert_(ILifeCycleController(wi).completed, True)
        self.assert_(IEMailWorkItem.providedBy(wi))

        ro = RecipientOwner('ro')
        rna = RecipientNextAssignees('rna')
        rar = RecipientActualRole('rar')
        rar.roles = ('Editor',)

        _test_recipients(ro, ['author'], wi)
        _test_recipients(rna, ['editor2'], wi)
        _test_recipients(rar, ['editor3'], wi)

        wi = instance.getWorkItems(state="active")[0]
        self.assert_(INTaskWorkItem.providedBy(wi))
        wi_start = wi.objectValues()[0]
        self.assertEquals(config.CHECKPOINT_START,
                          wi_start.getDefinition().getId())
        wi_start_email = wi_start.objectValues()[0]
        self.assert_(IEMailAspect.providedBy(wi_start_email))
        rc = RecipientCurrentAssignees('rc')
        _test_recipients(rc, ['editor2'], wi_start_email)
Exemplo n.º 4
0
        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)
Exemplo n.º 5
0
    def test_definition(self):
        doc = self._init_object()

        # props not existing
        self.assertRaises(AttributeError, getattr, doc, "asdf_asdf_prop_hjkl")
        instance = doc.getInstance()
        controller = ILifeCycleController(instance)
        controller.start("testing")
        self.assertEquals(controller.state, "active")
        self.assertEqual(2, doc.asdf_asdf_prop_hjkl)
        wis = instance.getWorkItems()
        # only the task is left
        self.assertEquals(len(wis), 1)
Exemplo n.º 6
0
 def test_early_continue(self):
     doc = self._init_object(workflow='workflows/early_continue.alf')
     instance = doc.getInstance()
     ILifeCycleController(instance).start("comment")
     wis = instance.getWorkItems(state="active")
     self.assertEquals(1, len(wis))
     self.assertEquals("ntask", wis[0].activity_type)
Exemplo n.º 7
0
    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())
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
    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")
Exemplo n.º 10
0
    def test_runas(self):
        doc = self._init_object('workflows/expression-runas.alf')
        self.login('author')
        instance = doc.getInstance()
        ILifeCycleController(instance).start("testing")

        self.assertEquals('System Processes', doc.run_system)
        self.assertEquals('System Processes', doc.run_system_explicit)
        self.assertEquals('author', doc.run_current)
        self.assertEquals('author', doc.run_author)
Exemplo n.º 11
0
    def test_2no_part1(self):
        doc = self._init_object()
        instance = doc.getInstance()
        ILifeCycleController(instance).start("testing")

        # test first no
        self.login('editor1')
        doc = self._get_object()
        self._decide(doc, 'reject')
        instance = doc.getInstance()
        self.failUnless(instance is None)
Exemplo n.º 12
0
 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')
Exemplo n.º 13
0
    def complete(self, exit, REQUEST=None):
        """Complete this workitem"""
        # Verify that the exit that was triggered is actually enabled.
        for action in self.getActions():
            if action.id == exit and action.enabled:
                break
        else:
            raise RuntimeError('No exit with id `%s` enabled.' % exit)

        self.passCheckpoint(exit)
        ILifeCycleController(self).complete("n/a")
        return "Task completed."
Exemplo n.º 14
0
    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")
Exemplo n.º 15
0
    def test_definition(self):
        doc = self._init_object()

        instance = doc.getInstance()
        ILifeCycleController(instance).start("testing")
        self.assertEquals(instance.state, "active")
        wis = instance.getWorkItems(state="ended")
        self.assertEquals(len(wis), 3)  # switch_ac_1, switch_ac_2, switch_ac_3
        for wi in wis:
            if wi.getActivity().getId() == "switch_ac_1":
                cont_ac_1 = wi
                break
        else:
            self.fail()
        self.assertEqual(cont_ac_1.activity_type, "switch")

        # test wis created by cont_ac_1
        cont_ac_1_wis = cont_ac_1.getGeneratedWorkItems()
        self.assertEqual(len(cont_ac_1_wis), 2)
        cont_ac_2 = cont_ac_1_wis[0]
        self.assertEqual(cont_ac_2.getActivity().getId(), "switch_ac_2")
        self.assertEquals(cont_ac_2.state, "ended")
        self.assertEqual(cont_ac_2.activity_type, "switch")
        cont_ac_3 = cont_ac_1_wis[1]
        self.assertEqual(cont_ac_3.getActivity().getId(), "switch_ac_3")
        self.assertEquals(cont_ac_3.state, "ended")
        self.assertEqual(cont_ac_3.activity_type, "switch")

        # test wis created by cont_ac_2
        cont_ac_2_wis = cont_ac_2.getGeneratedWorkItems()
        self.assertEqual(len(cont_ac_2_wis), 1)
        task1 = cont_ac_2_wis[0]
        self.assertEqual(task1.activity_type, "ntask")
        self.assertEqual(task1.getActivity().getId(), "do_this")

        # test wis created by cont_ac_3
        cont_ac_3_wis = cont_ac_3.getGeneratedWorkItems()
        self.assertEqual(len(cont_ac_3_wis), 2)
        task1 = cont_ac_3_wis[0]
        self.assertEqual(task1.activity_type, "ntask")
        self.assertEqual(task1.getActivity().getId(), "do_this")
        task2 = cont_ac_3_wis[1]
        self.assertEqual(task2.activity_type, "ntask")
        self.assertEqual(task2.getActivity().getId(), "do_that")
Exemplo n.º 16
0
    def test_talescontext(self):
        doc = self._init_object()
        self.login('author')

        instance = doc.getInstance()
        ILifeCycleController(instance).start('test')
        wi = instance.getWorkItems()[0]

        context = getTalesContext(workitem=wi)
        vars = context.vars

        self.assertEquals(doc, vars['content'])
        self.assertEquals(doc, vars['here'])
        self.assertEquals(wi, vars['workitem'])
        self.assertEquals(self.portal, vars['portal'])
        self.assertEquals(wi.getActivity(), vars['activity'])
        self.assertEquals('author',
                          vars['alphaflow']['currentUser'].getUserName())
        self.assertEquals(SpecialUsers.system, vars['alphaflow']['systemUser'])
Exemplo n.º 17
0
    def test_3no_part2(self):
        doc = self._init_object()
        instance = doc.getInstance()
        ILifeCycleController(instance).start("testing")

        # first yes
        self.login('editor2')
        doc = self._get_object()
        self._decide(doc, 'accept')

        # test first no on all_yes
        self.login('editor3')
        doc = self._get_object()
        self._decide(doc, 'accept')

        self.login('editor2')
        doc = self._get_object()
        self._decide(doc, 'reject')
        instance = doc.getInstance()
        self.failUnless(instance is None)
Exemplo n.º 18
0
    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 = gocept.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)
Exemplo n.º 19
0
    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", "")