def test_portlet_remove(self): self.loginAsPortalOwner() self.create_portlet(u'review', ReviewAssignment()) event = ActionSucceededEvent(self.folder, None, None, None) event.old_state, event.new_state = 'pending', 'published' workflowTriggersReviewPortletReload(self.portal, self.view, event) result = self.view.render() command = result[0] self.failUnless(command.has_key('selector')) self.failUnless(command['selector'].startswith('portletwrapper')) self.failUnless(command.has_key('name')) self.assertEqual(command['name'], 'deleteNode')
def testExecute(self): e = WorkflowTransitionCondition() e.wf_transitions = ['publish', 'hide'] ex = getMultiAdapter( ( self.portal, e, ActionSucceededEvent( self.folder, 'dummy_workflow', 'publish', None, ) ), IExecutable, ) self.assertTrue(ex()) ex = getMultiAdapter( ( self.portal, e, ActionSucceededEvent( self.folder, 'dummy_workflow', 'retract', None, ) ), IExecutable, ) self.assertFalse(ex()) ex = getMultiAdapter( ( self.portal, e, ActionSucceededEvent( self.folder, 'dummy_workflow', 'hide', None, ) ), IExecutable, ) self.assertTrue(ex())
def XtestBrowseOldVersion(self): from euphorie.content.survey import handleSurveyPublish self.loginAsPortalOwner() survey = self.createSurvey() handleSurveyPublish( survey, ActionSucceededEvent(survey, None, "publish", None)) self.assertEqual( self.portal.client["nl"]["sector"]["test-survey"]["1"].title, "Module one") survey["1"].title = "Module two" handleSurveyPublish(survey, ActionSucceededEvent(survey, None, "update", None)) self.assertEqual( self.portal.client["nl"]["sector"]["test-survey"]["1"].title, "Module two")
def notifySuccess(self, ob, action, result=None): """ Notify all applicable workflows that an action has taken place. """ wfs = self.getWorkflowsFor(ob) for wf in wfs: wf.notifySuccess(ob, action, result) notify(ActionSucceededEvent(ob, wf, action, result))
def _invokeWithNotification(self, wfs, ob, action, func, args, kw): """ Private utility method: call 'func', and deal with exceptions indicating that the object has been deleted or moved. """ reindex = 1 for w in wfs: w.notifyBefore(ob, action) notify(ActionWillBeInvokedEvent(ob, w, action)) try: res = func(*args, **kw) except ObjectDeleted as ex: res = ex.getResult() reindex = 0 except ObjectMoved as ex: res = ex.getResult() ob = ex.getNewObject() except Exception: exc = sys.exc_info() try: for w in wfs: w.notifyException(ob, action, exc) notify(ActionRaisedExceptionEvent(ob, w, action, exc)) raise exc[0](exc[1]).with_traceback(exc[2]) finally: exc = None for w in wfs: w.notifySuccess(ob, action, res) notify(ActionSucceededEvent(ob, w, action, res)) if reindex: self._reindexWorkflowVariables(ob) return res
def testUnpublishAction(self): surveygroup = self.createSurveyGroup() survey = self._create(surveygroup, "euphorie.survey", "survey") notify(ActionSucceededEvent(survey, None, "publish", None)) self.assertEqual(surveygroup.published, "survey") request = survey.REQUEST unpublishview = component.getMultiAdapter( (surveygroup, request), name="unpublish" ) unpublishview.unpublish() self.assertEqual(surveygroup.published, None)
def testDeletePublishedSurvey(self): """Validation should fail when trying to delete a published survey""" surveygroup = self.createSurveyGroup() self._create(surveygroup, "euphorie.survey", "dummy") survey = self._create(surveygroup, "euphorie.survey", "survey") notify(ActionSucceededEvent(survey, None, "update", None)) self.assertEqual(surveygroup.published, "survey") deleteaction = component.getMultiAdapter( (survey, survey.REQUEST), name="delete" ) self.assertEqual(deleteaction.verify(surveygroup, survey), False)
def test_update_of_review_portlet(self): self.loginAsPortalOwner() portal = self.portal self.portal.invokeFactory('Document', 'test-page') portal.portal_workflow.doActionFor(self.portal['test-page'], 'submit') self.create_portlet(u'review', ReviewAssignment()) event = ActionSucceededEvent(self.folder, None, None, None) event.old_state, event.new_state = 'private', 'pending' workflowTriggersReviewPortletReload(self.portal, self.view, event) result = self.view.render() command = result[0] self.failUnless(command.has_key('selector')) self.failUnless(command['selector'].startswith('portletwrapper')) self.failUnless(command.has_key('name')) self.assertEqual(command['name'], 'replaceInnerHTML') self.failUnless(command.has_key('params')) params = result[0]['params'] self.failUnless(params.has_key('html')) html = params['html'] self.failUnless('portletWorkflowReview' in html) self.failUnless(command.has_key('selectorType')) self.assertEqual(command['selectorType'], 'htmlid')
def testDeleteUnPublishedSurvey(self): """It should be possible to delete unpublished surveys""" surveygroup = self.createSurveyGroup() self._create(surveygroup, "euphorie.survey", "dummy") survey = self._create(surveygroup, "euphorie.survey", "survey") deleteaction = component.getMultiAdapter( (survey, survey.REQUEST), name="delete" ) notify(ActionSucceededEvent(survey, None, "update", None)) self.assertEqual(surveygroup.published, "survey") unpublishview = component.getMultiAdapter( (surveygroup, survey.REQUEST), name="unpublish" ) unpublishview.unpublish() self.assertEqual(surveygroup.published, None) self.assertEqual(deleteaction.verify(surveygroup, survey), True)
def _invokeWithNotification(self, wfs, ob, action, func, args, kw): """ Private utility method: call 'func', and deal with exceptions indicating that the object has been deleted or moved. """ from zope.event import notify from Products.CMFCore.WorkflowCore import ActionRaisedExceptionEvent from Products.CMFCore.WorkflowCore import ActionSucceededEvent from Products.CMFCore.WorkflowCore import ActionWillBeInvokedEvent from Products.CMFCore.WorkflowCore import ObjectDeleted from Products.CMFCore.WorkflowCore import ObjectMoved from Products.CMFCore.WorkflowCore import WorkflowException reindex = 1 for w in wfs: w.notifyBefore(ob, action) notify(ActionWillBeInvokedEvent(ob, w, action)) try: res = func(*args, **kw) except ObjectDeleted as ex: res = ex.getResult() reindex = 0 except ObjectMoved as ex: res = ex.getResult() ob = ex.getNewObject() except: import sys exc = sys.exc_info() try: for w in wfs: w.notifyException(ob, action, exc) notify(ActionRaisedExceptionEvent(ob, w, action, exc)) reraise(*exc) finally: exc = None for w in wfs: w.notifySuccess(ob, action, res) notify(ActionSucceededEvent(ob, w, action, res)) if reindex: self._reindexWorkflowVariables(ob) return res
except ObjectMoved, ex: res = ex.getResult() ob = ex.getNewObject() except: import sys exc = sys.exc_info() try: for w in wfs: w.notifyException(ob, action, exc) notify(ActionRaisedExceptionEvent(ob, w, action, exc)) reraise(*exc) finally: exc = None for w in wfs: w.notifySuccess(ob, action, res) notify(ActionSucceededEvent(ob, w, action, res)) if reindex: self._reindexWorkflowVariables(ob) return res security.declarePublic('doActionFor') def doActionFor(self, ob, action, wf_id=None, *args, **kw): workflow_id = wf_id workflow_list = self.getWorkflowValueListFor(ob.getPortalType()) if workflow_id is None: if not workflow_list: raise WorkflowException(Message(u'No workflows found.')) for workflow in workflow_list: is_action_supported = workflow.isActionSupported( ob, action, **kw)
def testUpdateAction(self): surveygroup = self.createSurveyGroup() survey = self._create(surveygroup, "euphorie.survey", "survey") notify(ActionSucceededEvent(survey, None, "update", None)) self.assertEqual(surveygroup.published, "survey")
def testUnknownWorkflowAction(self): surveygroup = self.createSurveyGroup() survey = self._create(surveygroup, "euphorie.survey", "survey") notify(ActionSucceededEvent(survey, None, "bogus", None)) self.assertEqual(surveygroup.published, None)
def publish(self, survey): # XXX: this should use the event system to give a more accurate test, # but for some reason the history is lost if we do that. notify(ActionSucceededEvent(survey, None, "publish", None))
def test_integration_document_events(self): """ Trigger every event of a document at least one times and check the journalentries. Attention: we always have to check the parent. If we add a document to a dossier, the dossier is modified. So on the dossiers journal there are two new entries, one for the new document and one for the changed dossier. We just have to check the entry of the new document on the dossiers journal """ portal = self.layer['portal'] comment = 'my comment' registry = getUtility(IRegistry) proxy = registry.forInterface(IClientConfiguration) proxy.client_id = u'Test' dossier = createContentInContainer( portal, 'opengever.dossier.businesscasedossier', 'd1') # Add-Event document = createContentInContainer(dossier, 'opengever.document.document', 'd1', title=u'Doc\xfcment') self.check_object_added(document, 'Document added', 'Document added: %s' % document.title_or_id(), dossier) # Modified-Event - nothing changed length_document = get_journal_length(document) length_dossier = get_journal_length(dossier) notify(ObjectModifiedEvent(document)) self.assertTrue(length_document == get_journal_length(document)) self.assertTrue(length_dossier == get_journal_length(dossier)) # Modified-Event - file changed notify(ObjectModifiedEvent(document, Attributes(Interface, 'file'))) self.check_document_modified(document, dossier, 'file') # Modified-Event - meta changed notify(ObjectModifiedEvent(document, Attributes(Interface, 'meta'))) self.check_document_modified(document, dossier, 'meta') # Modified-Event - file and meta changed notify( ObjectModifiedEvent(document, Attributes(Interface, 'file', 'meta'))) self.check_document_modified(document, dossier, 'file_meta') # Get the workflow for the document to test the ActionSucceededEvent wftool = getToolByName(document, 'portal_workflow') workflow = wftool.get('simple_publication_workflow') # Action-Succeeded-Event with skipped transaction length = get_journal_length(document) notify( ActionSucceededEvent( document, workflow, 'check_out', 'checked_out', )) self.assertTrue(length == get_journal_length(document)) # Action-Succeeded-Event notify( ActionSucceededEvent( document, workflow, 'publish', 'published', )) self.check_document_actionsucceeded(document) # Object Checked-Out-Event notify(ObjectCheckedOutEvent(document, comment)) self.check_document_checkedout(document, comment) # Object Checked-In-Event notify(ObjectCheckedInEvent(document, comment)) self.check_document_checkedin(document, comment) # Object Checked-Out-Canceled-Event notify(ObjectCheckoutCanceledEvent(document)) self.check_document_checkoutcanceled(document) # Object Reverted-To-Version-Event with fail length = get_journal_length(document) notify(ObjectRevertedToVersion(document, '', '')) self.assertTrue(length == get_journal_length(document)) # Object Reverted-To-Version-Event notify(ObjectRevertedToVersion(document, 'v1', 'v1')) self.check_document_revertedtoversion(document) # Object Sent Document Event notify( DocumentSent(dossier, TEST_USER_ID, '*****@*****.**', 'test mail', 'Mymessage', [document])) self.check_document_sent(dossier, document) # Object downloaded file-copy Event notify(FileCopyDownloadedEvent(document)) self.check_document_copy_downloaded(document)
def notifyActionSucceeded(state_change): """Called from workflow after scripts.""" notify( ActionSucceededEvent(state_change.object, state_change.workflow, state_change.transition.getId(), None))
def test_integration_dossier_events(self): """ Trigger every event of a dossier at least one times and check the journalentries. """ portal = self.layer['portal'] # Add-Event dossier = createContentInContainer( portal, 'opengever.dossier.businesscasedossier', 'd1') self.check_object_added( dossier, 'Dossier added', 'Dossier added: %s' % dossier.title_or_id(), ) # Modified-Event notify(ObjectModifiedEvent(dossier)) # Check self.check_annotation(dossier, action_type='Dossier modified', action_title='Dossier modified: %s' % (dossier.title_or_id())) # Get the workflow for the dossier to test the ActionSucceededEvent wftool = getToolByName(dossier, 'portal_workflow') workflow = wftool.get('simple_publication_workflow') # Action-Succeeded-Event notify( ActionSucceededEvent( dossier, workflow, 'publish', 'published', )) # Check self.check_annotation( dossier, action_type='Dossier state changed', action_title='Dossier state changed to published') # Local roles Aquisition Blocked-Event notify(LocalRolesAcquisitionBlocked(dossier, )) # Check self.check_annotation(dossier, action_type='Local roles Aquisition Blocked', action_title='Local roles aquistion blocked.') # Local roles Aquisition Activated-Event notify(LocalRolesAcquisitionActivated(dossier, )) # Check self.check_annotation(dossier, action_type='Local roles Aquisition Activated', action_title='Local roles aquistion activated.') # Local roles Modified notify( LocalRolesModified(dossier, 'old roles', ( ['catman', ['Owner']], ['ratman', ['Owner', 'Reader']], ['test_user', ['Reader', 'Publisher']], ))) # CheckLocalRolesModified self.check_annotation( dossier, action_type='Local roles modified', action_title='Local roles modified.', comment='ratman: sharing_dossier_reader; test_user: '******'sharing_dossier_reader, sharing_dossier_publisher')
def publish(self, survey): # XXX: this should use the event system to give a more accurate test, # but for some reason the history is lost if we do that. from Products.CMFCore.WorkflowCore import ActionSucceededEvent from zope.event import notify notify(ActionSucceededEvent(survey, None, "publish", None))