Back to index

plone3  3.1.7
test_action_logger.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.logger import LoggerAction
00009 from plone.app.contentrules.actions.logger import LoggerEditForm
00010 
00011 from plone.app.contentrules.rule import Rule
00012 
00013 from plone.app.contentrules.tests.base import ContentRulesTestCase
00014 
00015 class DummyEvent(object):
00016     implements(Interface)
00017 
00018 class TestLoggerAction(ContentRulesTestCase):
00019 
00020     def afterSetUp(self):
00021         self.setRoles(('Manager',))
00022 
00023     def testRegistered(self): 
00024         element = getUtility(IRuleAction, name='plone.actions.Logger')
00025         self.assertEquals('plone.actions.Logger', element.addview)
00026         self.assertEquals('edit', element.editview)
00027         self.assertEquals(None, element.for_)
00028         self.assertEquals(None, element.event)
00029     
00030     def testInvokeAddView(self): 
00031         element = getUtility(IRuleAction, name='plone.actions.Logger')
00032         storage = getUtility(IRuleStorage)
00033         storage[u'foo'] = Rule()
00034         rule = self.portal.restrictedTraverse('++rule++foo')
00035         
00036         adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action')
00037         addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview)
00038         
00039         addview.createAndAdd(data={'targetLogger' : 'foo', 'loggingLevel' : 10, 'message' : 'bar'})
00040         
00041         e = rule.actions[0]
00042         self.failUnless(isinstance(e, LoggerAction))
00043         self.assertEquals('foo', e.targetLogger)
00044         self.assertEquals(10, e.loggingLevel)
00045         self.assertEquals('bar', e.message)
00046     
00047     def testInvokeEditView(self): 
00048         element = getUtility(IRuleAction, name='plone.actions.Logger')
00049         e = LoggerAction()
00050         editview = getMultiAdapter((e, self.folder.REQUEST), name=element.editview)
00051         self.failUnless(isinstance(editview, LoggerEditForm))
00052 
00053     def testExecute(self): 
00054         e = LoggerAction()
00055         e.targetLogger = 'testing'
00056         e.loggingLevel = 0
00057         e.message = 'Test log event'
00058         
00059         ex = getMultiAdapter((self.folder, e, DummyEvent()), IExecutable)
00060         self.assertEquals(True, ex())
00061         
00062 def test_suite():
00063     from unittest import TestSuite, makeSuite
00064     suite = TestSuite()
00065     suite.addTest(makeSuite(TestLoggerAction))
00066     return suite