Back to index

plone3  3.1.7
test_action_move.py
Go to the documentation of this file.
00001 from zope.interface import implements, Interface
00002 from zope.component import getUtility, getMultiAdapter
00003 
00004 from plone.contentrules.engine.interfaces import IRuleStorage
00005 from plone.contentrules.rule.interfaces import IRuleAction
00006 from plone.contentrules.rule.interfaces import IExecutable
00007 
00008 from plone.app.contentrules.actions.move import MoveAction
00009 from plone.app.contentrules.actions.move import MoveEditForm
00010 
00011 from plone.app.contentrules.rule import Rule
00012 
00013 from plone.app.contentrules.tests.base import ContentRulesTestCase
00014 
00015 from zope.component.interfaces import IObjectEvent
00016 
00017 from Products.PloneTestCase.setup import default_user
00018 
00019 class DummyEvent(object):
00020     implements(IObjectEvent)
00021     
00022     def __init__(self, object):
00023         self.object = object
00024 
00025 class TestMoveAction(ContentRulesTestCase):
00026 
00027     def afterSetUp(self):
00028         self.loginAsPortalOwner()
00029         self.portal.invokeFactory('Folder', 'target')
00030         self.login(default_user)
00031         self.folder.invokeFactory('Document', 'd1')
00032 
00033     def testRegistered(self): 
00034         element = getUtility(IRuleAction, name='plone.actions.Move')
00035         self.assertEquals('plone.actions.Move', element.addview)
00036         self.assertEquals('edit', element.editview)
00037         self.assertEquals(None, element.for_)
00038         self.assertEquals(IObjectEvent, element.event)
00039     
00040     def testInvokeAddView(self): 
00041         element = getUtility(IRuleAction, name='plone.actions.Move')
00042         storage = getUtility(IRuleStorage)
00043         storage[u'foo'] = Rule()
00044         rule = self.portal.restrictedTraverse('++rule++foo')
00045         
00046         adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action')
00047         addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview)
00048         
00049         addview.createAndAdd(data={'target_folder' : '/target',})
00050         
00051         e = rule.actions[0]
00052         self.failUnless(isinstance(e, MoveAction))
00053         self.assertEquals('/target', e.target_folder)
00054     
00055     def testInvokeEditView(self): 
00056         element = getUtility(IRuleAction, name='plone.actions.Move')
00057         e = MoveAction()
00058         editview = getMultiAdapter((e, self.folder.REQUEST), name=element.editview)
00059         self.failUnless(isinstance(editview, MoveEditForm))
00060 
00061     def testExecute(self): 
00062         e = MoveAction()
00063         e.target_folder = '/target'
00064         
00065         ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable)
00066         self.assertEquals(True, ex())
00067         
00068         self.failIf('d1' in self.folder.objectIds())
00069         self.failUnless('d1' in self.portal.target.objectIds())
00070         
00071     def testExecuteWithError(self): 
00072         e = MoveAction()
00073         e.target_folder = '/dummy'
00074         
00075         ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable)
00076         self.assertEquals(False, ex())
00077         
00078         self.failUnless('d1' in self.folder.objectIds())
00079         self.failIf('d1' in self.portal.target.objectIds())
00080         
00081     def testExecuteWithoutPermissionsOnTarget(self):
00082         self.setRoles(('Member',))
00083         
00084         e = MoveAction()
00085         e.target_folder = '/target'
00086         
00087         ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable)
00088         self.assertEquals(True, ex())
00089         
00090         self.failIf('d1' in self.folder.objectIds())
00091         self.failUnless('d1' in self.portal.target.objectIds())
00092         
00093     def testExecuteWithNamingConflict(self):
00094         self.setRoles(('Manager',))
00095         self.portal.target.invokeFactory('Document', 'd1')
00096         self.setRoles(('Member',))
00097         
00098         e = MoveAction()
00099         e.target_folder = '/target'
00100         
00101         ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable)
00102         self.assertEquals(True, ex())
00103         
00104         self.failIf('d1' in self.folder.objectIds())
00105         self.failUnless('d1' in self.portal.target.objectIds())
00106         self.failUnless('d1.1' in self.portal.target.objectIds())
00107         
00108     def testExecuteWithSameSourceAndTargetFolder(self):
00109         self.setRoles(('Manager',))
00110         self.portal.target.invokeFactory('Document', 'd1')
00111         self.setRoles(('Member',))
00112         
00113         e = MoveAction()
00114         e.target_folder = '/target'
00115         
00116         ex = getMultiAdapter((self.portal.target, e, DummyEvent(self.portal.target.d1)), IExecutable)
00117         self.assertEquals(True, ex())
00118         
00119         self.assertEquals(['d1'], list(self.portal.target.objectIds()))
00120         
00121 def test_suite():
00122     from unittest import TestSuite, makeSuite
00123     suite = TestSuite()
00124     suite.addTest(makeSuite(TestMoveAction))
00125     return suite