def install(self): out = StringIO() self._addRole("Procurement") self._addRole("Finance") for account in config.accounts.keys(): self.acl_users.userFolderAddGroup(utils.getGroupFromAccount(account), ()) installTypes(self, out, atapi.listTypes(config.PROJECTNAME), config.PROJECTNAME) install_subskin(self, out, config.GLOBALS) wf_tool = getToolByName(self, "portal_workflow") wf_tool.setChainForPortalTypes( [t['portal_type'] for t in atapi.listTypes(config.PROJECTNAME)], "alphaflow_fake") alf = getToolByName(self, 'workflow_manager') id = "procurement" if id in alf.processes.objectIds(): IProcessWriteContainer(alf.processes).remove(id) wf_dir = os.path.abspath( os.path.join( os.path.split(config.GLOBALS['__file__'])[0], "workflows")) importer = zope.component.getUtility(IWorkflowImporter, name='xml') version = importer(file(os.path.join(wf_dir, "simple.alf"))) process = IProcessWriteContainer(alf.processes).add(id, Process(id)) process.editable(version) process.update()
def install_process_definitions(self, out, globals): alf = getToolByName(self, 'workflow_manager') wf_dir = None for dir in config.WORKFLOW_DIRS: candidate = os.path.abspath( os.path.join(os.path.split(globals['__file__'])[0], dir)) if os.path.isdir(candidate): wf_dir = candidate break if wf_dir is None: raise KeyError, "No workflow directory exists: %s" \ % config.WORKFLOW_DIRS for wf_basename in os.listdir(wf_dir): base, ext = os.path.splitext(wf_basename) wf_filename = os.path.join(wf_dir, wf_basename) if ext != '.alf': continue if base in alf.processes.objectIds(): del alf.processes[base] print >> out, "Installing %r workflow" % base importer = zope.component.getUtility(IWorkflowImporter, name='xml') version = importer(file(wf_filename)) alf.processes[base] = Process(base) process = alf.processes[base] process.editable(version) process.update()
def test_get_process(self): # XXX This test might be superfluous. portal = self.portal alf = getToolByName(portal, 'workflow_manager') pid = get_random_id() alf.processes[pid] = Process(pid) process = alf.processes[pid] process.editable(ProcessVersion()) process.update() current = process.current() self.assert_(IProcessVersion.providedBy(current))
def test_use_timelimit_template(self): wftool = self.portal.workflow_manager wftool.processes['dummy'] = Process('dummy') wftool.processes["dummy"].editable(ProcessVersion()) wftool.processes["dummy"].update() process = wftool.processes['dummy'].current() # Load form self.assertPublish("@@template-timelimit", process) # Submit form self.assertEquals(0, len(process.objectIds())) self.assertPublish("@@template-timelimit?form.actions.apply=Save&form.assignment=decision&form.assignment-empty-marker=1&form.title=Irgendwas", process) self.assertEquals(5, len(process.objectIds()))
def test_use_parallel_review_template(self): wftool = self.portal.workflow_manager wftool.processes['dummy'] = Process('dummy') wftool.processes["dummy"].editable(ProcessVersion()) wftool.processes["dummy"].update() process = wftool.processes['dummy'].current() # Load form self.assertPublish("@@template-parallelreview", process) # Submit form self.assertEquals(0, len(process.objectIds())) self.assertPublish( "@@template-parallelreview?form.actions.apply=Save&form.reviews=3&form.title=Review", process) self.assertEquals(6, len(process.objectIds()))
def _import_wf(self, path="workflows/multi_review.alf", id="test", valid=False): wftool = getToolByName(self.portal, "workflow_manager") f = open(os.path.join(os.path.dirname(__file__), path)) importer = zope.component.getUtility(IWorkflowImporter, name='xml') version = importer(f) if id in wftool.processes.objectIds(): wftool.processes.manage_delObjects([id]) wftool.processes[id] = Process(id) process = wftool.processes[id] process.editable(version) process.update() self.test_process = process.current() f.close() if valid: process_ = wftool.processes[id].current() self.failIf(process_.validation_errors)
def test_canRenderWorkflow(self): request = zope.publisher.browser.TestRequest() pm = self.portal.workflow_manager pm.processes['asdf'] = Process('asdf') process = pm.processes["asdf"].editable(ProcessVersion()) process.title = "test" editorview = Editor(process, request) add_activity = EditActivity(process, request).add add_activity('ntask') act1 = process.objectValues()[0] add_activity('ntask') act2 = list(set(process.objectValues()) - set([act1]))[0] # we should have two activities in this process self.assertEquals(2, len(process.objectIds())) self.assertEquals(False, editorview.canRenderWorkflow()) # now connect those and we should be able to display a graph act1[gocept.alphaflow.config.CHECKPOINT_START].activities += ( act2.id, ) self.assertEquals(True, editorview.canRenderWorkflow())
def test_definition_(self): # Creates a simple workflow portal = self.portal self._create_test_users() self.loginAsPortalOwner() wftool = getToolByName(portal, 'workflow_manager') # Create a new process definition wftool.processes["myProcess"] = Process('myProcess') wftool.processes["myProcess"].editable(ProcessVersion()) wftool.processes["myProcess"].update() process = wftool.processes['myProcess'].current() process.setTitle("My demo process") process.setDescription("A process that demonstrates the new" "workflow tool") process.startActivity = ("write_document",) def add_activity(process, id, name): factory = zope.component.getUtility(IActivityClass, name=name) process[id] = factory() activity = process[id] activity.id = id return activity # "task" is a special kind of activity to ask people to do # something write_document = add_activity(process, "write_document", "ntask") cp_complete = ExitDefinition() cp_complete.activities = ("check_document", ) cp_complete.id = "complete" write_document._setObject("complete", cp_complete) # "vote" is an activity, that asks people if something should # proceed or not check_document = add_activity(process, "check_document", "decision") check_document.decision_modus = 'all_yes' check_document.decision_notice = u'Decide something!' # Let's create some content portal.createObject("testdocument", "DummyContent") # Initialize the process doc = portal.testdocument # error on not existing process id self.assertRaises(AttributeError, doc.assignProcess, 'not existing processId') doc.assignProcess(wftool.processes['myProcess'].current()) instance = doc.getInstance() instance.edit(write_document_assignees="author", write_document_task="Bitte eine" "Pressemitteilung zum Thema Drogenpraevention 2004 schreiben", check_document_assignees=["editor1", "editor2"]) controller = ILifeCycleController(instance) controller.start("testing") self.assertEquals(controller.state, "active") # Check for the correct error if an non-existing activity is created self.assertRaises(UnknownActivityError, instance.createWorkItems, ['nonexistent'], instance) wftool.processes["other_process"] = Process('other_process') wftool.processes["other_process"].editable(ProcessVersion()) wftool.processes["other_process"].update() # If a process is already assigned, we can not assign another: self.assertRaises(Exception, doc.assignProcess, wftool.processes['other_process'].current()) new_instance = doc.getInstance() self.failUnless(instance.aq_base is new_instance.aq_base) self.login("author") write_document_wi = doc.getWorkItemsForCurrentUser()[0] # Test for instance.getWorkItems with optional activity_id parameter instance = doc.getInstance() self.assertEquals([], instance.getWorkItems(activity_id="michgibtsnich")) self.assertEquals([write_document_wi], instance.getWorkItems(activity_id="write_document")) write_document_wi.complete('complete') self.login("editor1") doc.getWorkItemsForCurrentUser()[0].accept() self.login("editor2") doc.getWorkItemsForCurrentUser()[0].accept() self.loginAsPortalOwner() self.assertEquals(0, len(instance.getWorkItems())) self.assertEquals(False, doc.hasInstanceAssigned())