Back to index

plone3  3.1.7
Functions
CMFCore.tests.test_fiveactionstool Namespace Reference

Functions

def test_fiveactionstool
def test_suite

Function Documentation

Test the Five actions tool.

Some basic setup:

  >>> import Products.Five
  >>> import Products.CMFCore
  >>> from Products.Five import zcml
  >>> zcml.load_config('meta.zcml', Products.Five)
  >>> zcml.load_config('permissions.zcml', Products.Five)
  >>> zcml.load_config('meta.zcml', Products.CMFCore)
  >>> folder = self.folder

For menus to work, the request must have defaultSkin.

  >>> from zope.publisher.browser import setDefaultSkin
  >>> setDefaultSkin(self.folder.REQUEST)
  
We need to make Zope 3 use Zope 2s security policy

  >>> from zope.security.management import thread_local
  >>> thread_local.interaction = None
  >>> from Products.Five.security import newInteraction
  >>> newInteraction()

Log in as manager
   
  >>> uf = self.folder.acl_users
  >>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
  >>> self.login('manager')

Let's create a Five actions tool:

  >>> from Products.CMFCore.fiveactionstool import FiveActionsTool
  >>> folder.tool = FiveActionsTool()
  >>> tool = folder.tool # rewrap

Let's create some simple content object providing ISimpleContent:

  >>> from Products.Five.tests.testing.simplecontent import SimpleContent
  >>> id = self.folder._setObject('foo', SimpleContent('foo', 'Foo'))
  >>> foo = self.folder.foo

Now we'll load a configuration file specifying some menu and menu
items for ISimpleContent.

  >>> import Products.CMFCore.tests
  >>> zcml.load_config('fiveactions.zcml', Products.CMFCore.tests)

Let's look what the tool lists as actions for such an object. 

  >>> actions = tool.listActions(object=foo)
  >>> [(action.category, action.id) for action in actions]
  [('mymenu', 'action_foo_public.html'), ('mymenu', 'action_foo_protected.html')]

But if we log in as a user who is not manager, we should not get the
protected menu item, , as it was protected by a more restrictive permission:

  >>> uf = self.folder.acl_users
  >>> uf._doAddUser('user', 'user', [], [])
  >>> self.login('user')
  
  >>> actions = tool.listActions(object=foo)
  >>> [(action.category, action.id) for action in actions]
  [('mymenu', 'action_foo_public.html')]

When looking at an object not implementing ISimpleContent, we see no
actions:

  >>> tool.listActions(object=folder)
  ()

The tool itself doesn't have any actions:

  >>> tool.listActions()
  ()

Cleanup:

  >>> from zope.testing.cleanup import cleanUp
  >>> cleanUp()

Definition at line 22 of file test_fiveactionstool.py.

00022 
00023 def test_fiveactionstool():
00024     """
00025     Test the Five actions tool.
00026 
00027     Some basic setup:
00028 
00029       >>> import Products.Five
00030       >>> import Products.CMFCore
00031       >>> from Products.Five import zcml
00032       >>> zcml.load_config('meta.zcml', Products.Five)
00033       >>> zcml.load_config('permissions.zcml', Products.Five)
00034       >>> zcml.load_config('meta.zcml', Products.CMFCore)
00035       >>> folder = self.folder
00036 
00037     For menus to work, the request must have defaultSkin.
00038     
00039       >>> from zope.publisher.browser import setDefaultSkin
00040       >>> setDefaultSkin(self.folder.REQUEST)
00041       
00042     We need to make Zope 3 use Zope 2s security policy
00043     
00044       >>> from zope.security.management import thread_local
00045       >>> thread_local.interaction = None
00046       >>> from Products.Five.security import newInteraction
00047       >>> newInteraction()
00048 
00049     Log in as manager
00050    
00051       >>> uf = self.folder.acl_users
00052       >>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
00053       >>> self.login('manager')
00054 
00055     Let's create a Five actions tool:
00056 
00057       >>> from Products.CMFCore.fiveactionstool import FiveActionsTool
00058       >>> folder.tool = FiveActionsTool()
00059       >>> tool = folder.tool # rewrap
00060 
00061     Let's create some simple content object providing ISimpleContent:
00062 
00063       >>> from Products.Five.tests.testing.simplecontent import SimpleContent
00064       >>> id = self.folder._setObject('foo', SimpleContent('foo', 'Foo'))
00065       >>> foo = self.folder.foo
00066 
00067     Now we'll load a configuration file specifying some menu and menu
00068     items for ISimpleContent.
00069 
00070       >>> import Products.CMFCore.tests
00071       >>> zcml.load_config('fiveactions.zcml', Products.CMFCore.tests)
00072 
00073     Let's look what the tool lists as actions for such an object. 
00074 
00075       >>> actions = tool.listActions(object=foo)
00076       >>> [(action.category, action.id) for action in actions]
00077       [('mymenu', 'action_foo_public.html'), ('mymenu', 'action_foo_protected.html')]
00078 
00079     But if we log in as a user who is not manager, we should not get the
00080     protected menu item, , as it was protected by a more restrictive permission:
00081     
00082       >>> uf = self.folder.acl_users
00083       >>> uf._doAddUser('user', 'user', [], [])
00084       >>> self.login('user')
00085       
00086       >>> actions = tool.listActions(object=foo)
00087       >>> [(action.category, action.id) for action in actions]
00088       [('mymenu', 'action_foo_public.html')]
00089 
00090     When looking at an object not implementing ISimpleContent, we see no
00091     actions:
00092 
00093       >>> tool.listActions(object=folder)
00094       ()
00095 
00096     The tool itself doesn't have any actions:
00097 
00098       >>> tool.listActions()
00099       ()
00100 
00101     Cleanup:
00102 
00103       >>> from zope.testing.cleanup import cleanUp
00104       >>> cleanUp()
00105     """
00106 

Definition at line 107 of file test_fiveactionstool.py.

00107 
00108 def test_suite():
00109     return unittest.TestSuite((
00110         ZopeTestCase.ZopeDocTestSuite(),
00111         ))