Back to index

plone3  3.1.7
test_condition_portal_type.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 zope.component.interfaces import IObjectEvent
00005 
00006 from plone.contentrules.engine.interfaces import IRuleStorage
00007 from plone.contentrules.rule.interfaces import IRuleCondition
00008 from plone.contentrules.rule.interfaces import IExecutable
00009 
00010 from plone.app.contentrules.conditions.portaltype import PortalTypeCondition
00011 from plone.app.contentrules.conditions.portaltype import PortalTypeEditForm
00012 
00013 from plone.app.contentrules.rule import Rule
00014 
00015 from plone.app.contentrules.tests.base import ContentRulesTestCase
00016 
00017 class DummyEvent(object):
00018     implements(IObjectEvent)
00019     
00020     def __init__(self, obj):
00021         self.object = obj
00022 
00023 class TestPortalTypeCondition(ContentRulesTestCase):
00024 
00025     def afterSetUp(self):
00026         self.setRoles(('Manager',))
00027 
00028     def testRegistered(self): 
00029         element = getUtility(IRuleCondition, name='plone.conditions.PortalType')
00030         self.assertEquals('plone.conditions.PortalType', element.addview)
00031         self.assertEquals('edit', element.editview)
00032         self.assertEquals(None, element.for_)
00033         self.assertEquals(IObjectEvent, element.event)
00034     
00035     def testInvokeAddView(self): 
00036         element = getUtility(IRuleCondition, name='plone.conditions.PortalType')
00037         storage = getUtility(IRuleStorage)
00038         storage[u'foo'] = Rule()
00039         rule = self.portal.restrictedTraverse('++rule++foo')
00040         
00041         adding = getMultiAdapter((rule, self.portal.REQUEST), name='+condition')
00042         addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview)
00043         
00044         addview.createAndAdd(data={'check_types' : ['Folder', 'Image']})
00045         
00046         e = rule.conditions[0]
00047         self.failUnless(isinstance(e, PortalTypeCondition))
00048         self.assertEquals(['Folder', 'Image'], e.check_types)
00049     
00050     def testInvokeEditView(self): 
00051         element = getUtility(IRuleCondition, name='plone.conditions.PortalType')
00052         e = PortalTypeCondition()
00053         editview = getMultiAdapter((e, self.folder.REQUEST), name=element.editview)
00054         self.failUnless(isinstance(editview, PortalTypeEditForm))
00055 
00056     def testExecute(self): 
00057         e = PortalTypeCondition()
00058         e.check_types = ['Folder', 'Image']
00059         
00060         ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)), IExecutable)
00061         self.assertEquals(True, ex())
00062         
00063         ex = getMultiAdapter((self.portal, e, DummyEvent(self.portal)), IExecutable)
00064         self.assertEquals(False, ex())
00065         
00066 def test_suite():
00067     from unittest import TestSuite, makeSuite
00068     suite = TestSuite()
00069     suite.addTest(makeSuite(TestPortalTypeCondition))
00070     return suite