Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better test coverage

svn path=/plone.app.workflowmanager/trunk/; revision=51912
  • Loading branch information...
commit 25abd2b5eaedc2a57d15e1cac57cacf940edf350 1 parent 8c473d3
@vangheem vangheem authored
View
17 src/plone/app/workflowmanager/actionmanager.py
@@ -24,18 +24,6 @@ def __init__(self, rule, transition):
@property
- def valid(self):
- """
- check if rule is activated and has the right condition set.
- """
- transitions = set([])
- for condition in self.rule.conditions:
- if IWorkflowTransitionCondition.providedBy(condition):
- transitions |= condition.wf_transitions
- return transitions
-
-
- @property
@memoize
def portal(self):
return getToolByName(self.transition, 'portal_url').getPortalObject()
@@ -58,11 +46,6 @@ def activate(self):
assignments = get_assignments(self.rule)
if not path in assignments:
assignments.insert(path)
-
-
- @property
- def name(self):
- return self.rule.__name__
@property
View
10 src/plone/app/workflowmanager/browser/controlpanel.py
@@ -112,8 +112,6 @@ def selected_workflow(self):
if selected and selected in self.portal_workflow.objectIds():
return self.portal_workflow[selected]
- else:
- return None
@property
@@ -126,8 +124,6 @@ def selected_state(self):
if state in self.selected_workflow.states.objectIds():
return self.selected_workflow.states[state]
- return None
-
@property
@memoize
@@ -139,8 +135,6 @@ def selected_transition(self):
if transition in self.selected_workflow.transitions.objectIds():
return self.selected_workflow.transitions[transition]
- return None
-
@property
@memoize
@@ -179,10 +173,8 @@ def render_transitions_template(self):
def get_transition(self, id):
- if id in self.selected_workflow.transition.objectIds():
+ if id in self.selected_workflow.transitions.objectIds():
return self.selected_workflow.transitions[id]
- else:
- return None
@property
View
3  src/plone/app/workflowmanager/testing.py
@@ -90,10 +90,11 @@ def getRequest(self, form={}, authentic=False):
if authentic:
form['_authenticator'] = self.genAuthString()
- return TestRequest(form=form, environ={
+ req = TestRequest(form=form, environ={
'SERVER_URL' : 'http://nohost',
'HTTP_HOST' : 'nohost'
})
+ return req
def genAuthString(self):
manager=getUtility(IKeyManager)
View
95 src/plone/app/workflowmanager/tests/test_actions.py
@@ -1,11 +1,18 @@
import unittest2 as unittest
+from zope.component import getUtility, getMultiAdapter
+
+from Products.CMFCore.utils import getToolByName
+
from plone.app.testing import TEST_USER_NAME, \
login
+from plone.contentrules.rule.interfaces import IRuleAction
+
from plone.app.workflowmanager.testing import INTEGRATION_MANAGER_TESTING, BaseTest
from plone.app.workflowmanager.browser.actions import AddActionView, DeleteActionView
from plone.app.workflowmanager.actionmanager import ActionManager
+from plone.app.workflowmanager.actionmanager import RuleAdapter
class TestActions(BaseTest):
@@ -85,7 +92,95 @@ def test_cancel_removing_action(self):
rule = am.get_rule(view.selected_transition)
self.assertEquals(len(rule.actions), 1)
+ def test_action_manager_to_create_action(self):
+ portal = self.layer['portal']
+ am = ActionManager()
+ pw = getToolByName(portal, 'portal_workflow')
+ workflow = pw['simple_publication_workflow']
+ transition = workflow.transitions['publish']
+ am.delete_rule_for(transition)
+ rule = am.create(transition)
+ element = getUtility(IRuleAction, name='plone.actions.Copy')
+ adding = getMultiAdapter((rule.rule, self.layer['request']), name='+action')
+ addview = getMultiAdapter((adding, self.layer['request']), name=element.addview)
+
+ addview.createAndAdd(data={'target_folder' : '/target',})
+
+ self.assertEquals(len(rule.actions), 1)
+
+ def test_action_manager_get_action(self):
+ portal = self.layer['portal']
+ am = ActionManager()
+ pw = getToolByName(portal, 'portal_workflow')
+ workflow = pw['simple_publication_workflow']
+ transition = workflow.transitions['publish']
+ am.delete_rule_for(transition)
+ rule = am.create(transition)
+
+ element = getUtility(IRuleAction, name='plone.actions.Copy')
+ adding = getMultiAdapter((rule.rule, self.layer['request']), name='+action')
+ addview = getMultiAdapter((adding, self.layer['request']), name=element.addview)
+
+ addview.createAndAdd(data={'target_folder' : '/target',})
+
+ ra = RuleAdapter(rule, transition)
+ action = ra.get_action(0)
+ self.assertEquals(action.element, 'plone.actions.Copy')
+
+ def test_action_manager_action_index(self):
+ portal = self.layer['portal']
+ am = ActionManager()
+ pw = getToolByName(portal, 'portal_workflow')
+ workflow = pw['simple_publication_workflow']
+ transition = workflow.transitions['publish']
+ rule = am.create(transition)
+
+ element = getUtility(IRuleAction, name='plone.actions.Copy')
+ adding = getMultiAdapter((rule.rule, self.layer['request']), name='+action')
+ addview = getMultiAdapter((adding, self.layer['request']), name=element.addview)
+
+ addview.createAndAdd(data={'target_folder' : '/target',})
+
+ ra = RuleAdapter(rule, transition)
+ action = ra.get_action(0)
+ self.assertEquals(ra.action_index(action), 0)
+
+ def test_action_manager_action_url(self):
+ portal = self.layer['portal']
+ am = ActionManager()
+ pw = getToolByName(portal, 'portal_workflow')
+ workflow = pw['simple_publication_workflow']
+ transition = workflow.transitions['publish']
+ rule = am.create(transition)
+
+ element = getUtility(IRuleAction, name='plone.actions.Copy')
+ adding = getMultiAdapter((rule.rule, self.layer['request']), name='+action')
+ addview = getMultiAdapter((adding, self.layer['request']), name=element.addview)
+
+ addview.createAndAdd(data={'target_folder' : '/target',})
+
+ ra = RuleAdapter(rule, transition)
+ action = ra.get_action(0)
+ self.assertTrue(rule.rule.id in ra.action_url(action) and '++0' in ra.action_url(action))
+
+ def test_action_manager_available_actions(self):
+ portal = self.layer['portal']
+ am = ActionManager()
+ action_names = [a.title for a in am.available_actions]
+ self.assertTrue(action_names == [u'Logger', u'Notify user', u'Copy to folder',
+ u'Move to folder', u'Delete object', u'Transition workflow state', u'Send email'])
+
+ def test_action_manager_delete_rule(self):
+ portal = self.layer['portal']
+ am = ActionManager()
+ pw = getToolByName(portal, 'portal_workflow')
+ workflow = pw['simple_publication_workflow']
+ transition = workflow.transitions['publish']
+ rule = am.create(transition)
+
+ am.delete_rule_for(transition)
+ self.assertEquals(am.get_rule(transition), None)
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
View
53 src/plone/app/workflowmanager/tests/test_controlpanel.py
@@ -0,0 +1,53 @@
+import unittest2 as unittest
+
+from AccessControl import Unauthorized
+
+from plone.app.workflowmanager.testing import INTEGRATION_MANAGER_TESTING, BaseTest
+from plone.app.workflowmanager.browser.controlpanel import Base
+
+
+class TestControlPanel(BaseTest):
+
+ layer = INTEGRATION_MANAGER_TESTING
+
+ def test_base_defaults_to_first_workflow_if_list(self):
+ view = Base(self.layer['portal'], self.getRequest({'selected-workflow' : ['simple_publication_workflow']}))
+ self.assertTrue(view.selected_workflow is not None)
+
+ def test_base_defaults_to_first_state_if_list(self):
+ view = Base(self.layer['portal'], self.getRequest({
+ 'selected-workflow' : ['simple_publication_workflow'],
+ 'selected-state' : ['published']}))
+ self.assertTrue(view.selected_state is not None)
+
+ def test_base_defaults_to_first_transition_if_list(self):
+ view = Base(self.layer['portal'], self.getRequest({
+ 'selected-workflow' : ['simple_publication_workflow'],
+ 'selected-transition' : ['publish']}))
+ self.assertTrue(view.selected_transition is not None)
+
+ def test_base_available_transitions_always_returns_a_list(self):
+ view = Base(self.layer['portal'], self.getRequest({
+ 'selected-workflow' : ['one_state_workflow']}))
+ self.assertEquals(type(view.available_transitions), list)
+
+ def test_base_available_states_always_returns_a_list(self):
+ view = Base(self.layer['portal'], self.getRequest({}))
+ self.assertEquals(type(view.available_states), list)
+
+ def test_authorize_raises_unauthorized(self):
+ view = Base(self.layer['portal'], self.getRequest({}))
+ self.assertRaises(Unauthorized, view.authorize)
+
+ def test_get_transition(self):
+ view = Base(self.layer['portal'], self.getRequest({
+ 'selected-workflow' : ['simple_publication_workflow']}))
+ self.assertTrue(view.get_transition('publish') is not None)
+
+ def test_get_transition_is_none_if_not_found(self):
+ view = Base(self.layer['portal'], self.getRequest({
+ 'selected-workflow' : ['simple_publication_workflow']}))
+ self.assertTrue(view.get_transition('foobar') is None)
+
+def test_suite():
+ return unittest.defaultTestLoader.loadTestsFromName(__name__)

0 comments on commit 25abd2b

Please sign in to comment.
Something went wrong with that request. Please try again.