Commits

Gilson Filho committed 42c78e4

Creating unit test for workflows

  • Participants
  • Parent commits 0171044

Comments (0)

Files changed (20)

File .hgignore

File contents unchanged.

File README.txt

File contents unchanged.

File docs/HISTORY.txt

File contents unchanged.

File docs/INSTALL.txt

File contents unchanged.

File docs/LICENSE.GPL

File contents unchanged.

File docs/LICENSE.txt

File contents unchanged.

File optilux/__init__.py

File contents unchanged.

File optilux/policy/__init__.py

File contents unchanged.

File optilux/policy/configure.zcml

         provides="Products.GenericSetup.interfaces.EXTENSION"
         />
 
+    <genericsetup:importStep
+        name="optilux-various"
+        title="Additional Optilux site policy setup"
+        description="Optilux site policy configuration"
+        handler="optilux.policy.setuphandlers.importVarious">
+
+        <depends name="rolemap" />
+
+    </genericsetup:importStep>
+
 </configure>

File optilux/policy/profiles/default/metadata.xml

File contents unchanged.

File optilux/policy/profiles/default/optilux.policy-various.txt

Empty file added.

File optilux/policy/profiles/default/properties.xml

File contents unchanged.

File optilux/policy/profiles/default/rolemap.xml

+<?xml version="1.0"?>
+<rolemap>
+    <roles>
+        <role name="StaffMember"/>
+    </roles>
+    <permissions>
+        <permission name="View" acquire="True">
+            <role name="Owner" />
+            <role name="Manager" />
+            <role name="Site Administrator" />
+            <role name="Contributor" />
+            <role name="Reader" />
+            <role name="Editor" />
+            <role name="StaffMember" />
+        </permission>
+      </permissions>
+</rolemap>

File optilux/policy/profiles/default/workflows.xml

+<?xml version="1.0"?>
+<object name="portal_workflow" meta_type="Plone Workflow Tool">
+ <object name="optilux_sitecontent_workflow" meta_type="Workflow"/>
+ <bindings>
+  <default>
+   <bound-workflow workflow_id="optilux_sitecontent_workflow"/>
+  </default>
+  <type type_id="File"/>
+  <type type_id="Image"/>
+ </bindings>
+</object>

File optilux/policy/profiles/default/workflows/optilux_sitecontent_workflow/definition.xml

+<?xml version="1.0"?>
+<dc-workflow workflow_id="optilux_sitecontent_workflow" title="Simple Publication Workflow" description="A workflow tailored for the Optilux website" state_variable="review_state" initial_state="draft" manager_bypass="False">
+    <permission>Access contents information</permission>
+    <permission>Change portal events</permission>
+    <permission>Modify portal content</permission>
+    <permission>View</permission>
+    <state state_id="draft" title="Draft">
+        <description>Content is being drafted</description>
+        <exit-transition transition_id="publish"/>
+        <exit-transition transition_id="submit"/>
+        <permission-map name="Access contents information" acquired="True">
+            <permission-role>Contributor</permission-role>
+            <permission-role>Editor</permission-role>
+            <permission-role>Manager</permission-role>
+            <permission-role>Owner</permission-role>
+            <permission-role>Reader</permission-role>
+            <permission-role>Site Administrator</permission-role>
+            <permission-role>StaffMember</permission-role>
+        </permission-map>
+        <permission-map name="Change portal events" acquired="True">
+            <permission-role>Editor</permission-role>
+            <permission-role>Manager</permission-role>
+            <permission-role>Owner</permission-role>
+            <permission-role>Site Administrator</permission-role>
+        </permission-map>
+        <permission-map name="Modify portal content" acquired="True">
+            <permission-role>Editor</permission-role>
+            <permission-role>Manager</permission-role>
+            <permission-role>Owner</permission-role>
+            <permission-role>Site Administrator</permission-role>
+        </permission-map>
+        <permission-map name="View" acquired="True">
+            <permission-role>Contributor</permission-role>
+            <permission-role>Editor</permission-role>
+            <permission-role>Manager</permission-role>
+            <permission-role>Owner</permission-role>
+            <permission-role>Reader</permission-role>
+            <permission-role>Site Administrator</permission-role>
+            <permission-role>StaffMember</permission-role>
+        </permission-map>
+    </state>
+    <state state_id="pending" title="Pending review">
+        <description>Waiting to be reviewed, not editable by the owner.</description>
+        <exit-transition transition_id="make_private"/>
+        <exit-transition transition_id="publish"/>
+        <exit-transition transition_id="reject"/>
+        <exit-transition transition_id="retract"/>
+        <permission-map name="Access contents information" acquired="False">
+            <permission-role>Manager</permission-role>
+            <permission-role>Owner</permission-role>
+            <permission-role>Editor</permission-role>
+            <permission-role>Reader</permission-role>
+            <permission-role>Contributor</permission-role>
+            <permission-role>Reviewer</permission-role>
+            <permission-role>Site Administrator</permission-role>
+        </permission-map>
+        <permission-map name="Change portal events" acquired="False">
+            <permission-role>Manager</permission-role>
+            <permission-role>Reviewer</permission-role>
+            <permission-role>Site Administrator</permission-role>
+        </permission-map>
+        <permission-map name="Modify portal content" acquired="False">
+            <permission-role>Manager</permission-role>
+            <permission-role>Reviewer</permission-role>
+            <permission-role>Site Administrator</permission-role>
+        </permission-map>
+        <permission-map name="View" acquired="False">
+            <permission-role>Manager</permission-role>
+            <permission-role>Owner</permission-role>
+            <permission-role>Editor</permission-role>
+            <permission-role>Reader</permission-role>
+            <permission-role>Contributor</permission-role>
+            <permission-role>Reviewer</permission-role>
+            <permission-role>Site Administrator</permission-role>
+        </permission-map>
+    </state>
+    <state state_id="published" title="Published">
+        <description>Visible to everyone, not editable by the owner.</description>
+        <exit-transition transition_id="retract"/>
+        <exit-transition transition_id="reject"/>
+        <permission-map name="Access contents information" acquired="False">
+            <permission-role>Anonymous</permission-role>
+        </permission-map>
+        <permission-map name="Change portal events" acquired="False">
+            <permission-role>Manager</permission-role>
+            <permission-role>Owner</permission-role>
+            <permission-role>Editor</permission-role>
+            <permission-role>Site Administrator</permission-role>
+        </permission-map>
+        <permission-map name="Modify portal content" acquired="False">
+            <permission-role>Manager</permission-role>
+            <permission-role>Owner</permission-role>
+            <permission-role>Editor</permission-role>
+            <permission-role>Site Administrator</permission-role>
+        </permission-map>
+        <permission-map name="View" acquired="False">
+            <permission-role>Anonymous</permission-role>
+        </permission-map>
+    </state>
+    <transition transition_id="publish" title="Reviewer publishes content" new_state="published" trigger="USER" before_script="" after_script="">
+        <description>Publishing the item makes it visible to other users.</description>
+        <action url="%(content_url)s/content_status_modify?workflow_action=publish" category="workflow" icon="">Publish</action>
+        <guard>
+            <guard-permission>Review portal content</guard-permission>
+        </guard>
+    </transition>
+    <transition transition_id="reject" title="Reviewer send content back for re-drafting" new_state="draft" trigger="USER" before_script="" after_script="">
+        <description>Sending the item back will return the item to the original author instead of publishing it. You should preferably include a reason for why it was not published.</description>
+        <action url="%(content_url)s/content_status_modify?workflow_action=reject" category="workflow" icon="">Send back</action>
+        <guard>
+            <guard-permission>Review portal content</guard-permission>
+        </guard>
+    </transition>
+    <transition transition_id="retract" title="Member retracts submission" new_state="draft" trigger="USER" before_script="" after_script="">
+        <description>If you submitted the item by mistake or want to perform additional edits, this will take it back.</description>
+        <action url="%(content_url)s/content_status_modify?workflow_action=retract" category="workflow" icon="">Retract</action>
+        <guard>
+            <guard-permission>Request review</guard-permission>
+        </guard>
+    </transition>
+    <transition transition_id="submit" title="Member submits content for publication" new_state="pending" trigger="USER" before_script="" after_script="">
+        <description>Puts your item in a review queue, so it can be published on the site.</description>
+        <action url="%(content_url)s/content_status_modify?workflow_action=submit" category="workflow" icon="">Submit for publication</action>
+        <guard>
+            <guard-permission>Request review</guard-permission>
+        </guard>
+    </transition>
+    <worklist worklist_id="reviewer_queue" title="">
+        <description>Reviewer tasks</description>
+        <action url="%(portal_url)s/search?review_state=pending" category="global" icon="">Pending (%(count)d)</action>
+        <guard>
+            <guard-permission>Review portal content</guard-permission>
+        </guard>
+        <match name="review_state" values="pending"/>
+    </worklist>
+    <variable variable_id="action" for_catalog="False" for_status="True" update_always="True">
+        <description>Previous transition</description>
+        <default>
+            <expression>transition/getId|nothing</expression>
+        </default>
+        <guard></guard>
+    </variable>
+    <variable variable_id="actor" for_catalog="False" for_status="True" update_always="True">
+        <description>The ID of the user who performed the previous transition</description>
+        <default>
+            <expression>user/getId</expression>
+        </default>
+        <guard></guard>
+    </variable>
+    <variable variable_id="comments" for_catalog="False" for_status="True" update_always="True">
+        <description>Comment about the last transition</description>
+        <default>
+            <expression>python:state_change.kwargs.get('comment', '')</expression>
+        </default>
+        <guard></guard>
+    </variable>
+    <variable variable_id="review_history" for_catalog="False" for_status="False" update_always="False">
+        <description>Provides access to workflow history</description>
+        <default>
+            <expression>state_change/getHistory</expression>
+        </default>
+        <guard>
+            <guard-permission>Request review</guard-permission>
+            <guard-permission>Review portal content</guard-permission>
+        </guard>
+    </variable>
+    <variable variable_id="time" for_catalog="False" for_status="True" update_always="True">
+        <description>When the previous transition was performed</description>
+        <default>
+            <expression>state_change/getDateTime</expression>
+        </default>
+        <guard></guard>
+    </variable>
+</dc-workflow>

File optilux/policy/setuphandlers.py

+# -*- coding: utf8 -*-
+
+from Products.CMFCore.utils import getToolByName
+
+
+def setupGroups(portal):
+    acl_users = getToolByName(portal, 'acl_users')
+    if not acl_users.searchGroups(name='Staff'):
+        gtool = getToolByName(portal, 'portal_groups')
+        gtool.addGroup('Staff', roles=['StaffMember'])
+
+
+def importVarious(context):
+    """Miscelanous steps import handle
+    """
+    if context.readDataFile('optilux.policy-various.txt') is None:
+        return
+
+    portal = context.getSite()
+
+    setupGroups(portal)

File optilux/policy/testing.py

File contents unchanged.

File optilux/policy/tests.py

 
 import unittest2 as unittest
 
+from Products.CMFCore.utils import getToolByName
+
 from optilux.policy.testing import OPTILUX_POLICY_INTEGRATION_TESTING
 
 
         self.assertEqual("Welcome to Optilux Cinemas",
                          portal.getProperty('description'))
 
+    def test_role_added(self):
+        portal = self.layer['portal']
+        self.assertTrue("StaffMember" in portal.validRoles())
 
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')
+    def test_workflow_installed(self):
+        portal = self.layer['portal']
+        workflow = getToolByName(portal, 'portal_workflow')
+
+        self.assertTrue('optilux_sitecontent_workflow' in workflow)
+
+    def test_workflow_mapped(self):
+        portal = self.layer['portal']
+        workflow = getToolByName(portal, 'portal_workflow')
+
+        self.assertEqual(('optilux_sitecontent_workflow',),
+                         workflow.getDefaultChain())
+
+    def test_view_permission_for_staffmember(self):
+        portal = self.layer['portal']
+
+        self.assertTrue('View' in [role['name']
+                                   for role in
+                                   portal.permissionsOfRole('Contributor')
+                                   if role['selected']])
+
+        self.assertTrue('View' in [role['name']
+                                   for role in
+                                   portal.permissionsOfRole('Editor')
+                                   if role['selected']])
+
+        self.assertTrue('View' in [role['name']
+                                   for role in
+                                   portal.permissionsOfRole('Manager')
+                                   if role['selected']])
+
+        self.assertTrue('View' in [role['name']
+                                   for role in
+                                   portal.permissionsOfRole('Owner')
+                                   if role['selected']])
+
+        self.assertTrue('View' in [role['name']
+                                   for role in
+                                   portal.permissionsOfRole('Reader')
+                                   if role['selected']])
+
+        self.assertTrue('View' in [role['name']
+                                   for role in
+                                   portal.permissionsOfRole(
+                                       'Site Administrator'
+                                   )
+                                   if role['selected']])
+
+        self.assertTrue('View' in [role['name']
+                                   for role in
+                                   portal.permissionsOfRole('StaffMember')
+                                   if role['selected']])
+
+    def test_staffmember_group_added(self):
+        portal = self.layer['portal']
+        acl_users = portal['acl_users']
+
+        self.assertEqual(1, len(acl_users.searchGroups(name='Staff')))

File setup.cfg

File contents unchanged.

File setup.py

File contents unchanged.