Back to index

plone3  3.1.7
test_ttwapi.py
Go to the documentation of this file.
00001 import unittest
00002 
00003 from Testing import ZopeTestCase
00004 ZopeTestCase.installProduct('PythonScripts')
00005 
00006 from AccessControl import allow_module
00007 allow_module('kss.core.tests.help_ttwapi')
00008 
00009 import Products.Five.component
00010 from Products.Five import zcml
00011 
00012 from zope import component
00013 from zope.lifecycleevent import ObjectModifiedEvent
00014 from zope.app.component.hooks import setHooks
00015 
00016 from kss.core import KSSView
00017 from kss.core.tests.base import KSSViewTestCase
00018 
00019 class TTWTestCase(KSSViewTestCase):
00020 
00021     class layer(KSSViewTestCase.layer):
00022         @classmethod
00023         def setUp(cls):
00024             configure_zcml = '''\
00025             <configure
00026                  xmlns="http://namespaces.zope.org/zope"
00027                  xmlns:browser="http://namespaces.zope.org/browser"
00028                  package="kss.core.tests.test_ttwapi">
00029               <subscriber handler=".objectModifiedThruKSSView" />
00030             </configure>'''
00031             zcml.load_string(configure_zcml)
00032 
00033     def afterSetUp(self):
00034         KSSViewTestCase.afterSetUp(self)
00035         setHooks()
00036         self.app.manage_addProduct['PythonScripts'].manage_addPythonScript(
00037             'kss_test')
00038         self.setDebugRequest()
00039 
00040     def test_scriptWithCore(self):
00041         pythonScriptCode = '''
00042 from kss.core.ttwapi import startKSSCommands
00043 from kss.core.ttwapi import getKSSCommandSet
00044 from kss.core.ttwapi import renderKSSCommands
00045 startKSSCommands(context, context.REQUEST)
00046 core = getKSSCommandSet('core')
00047 core.replaceInnerHTML('#test', '<p>Done</p>')
00048 return renderKSSCommands()
00049 '''
00050         self.app.kss_test.ZPythonScript_edit('', pythonScriptCode)
00051         result = self.app.kss_test() 
00052         self.assertEquals(len(result), 1)
00053         command = result[0]
00054         self.assertEquals(command['selector'], '#test')
00055         self.assertEquals(command['name'], 'replaceInnerHTML')
00056 
00057     def test_scriptWithEffect(self):
00058         pythonScriptCode = '''
00059 from kss.core.ttwapi import startKSSCommands
00060 from kss.core.ttwapi import getKSSCommandSet
00061 from kss.core.ttwapi import renderKSSCommands
00062 startKSSCommands(context, context.REQUEST)
00063 commandSet = getKSSCommandSet('effects')
00064 commandSet.effect('#test', 'fade')
00065 return renderKSSCommands()
00066 '''
00067         self.app.kss_test.ZPythonScript_edit('', pythonScriptCode)
00068         result = self.app.kss_test() 
00069         self.assertEquals(len(result), 1)
00070         command = result[0]
00071         self.assertEquals(command['selector'], '#test')
00072         self.assertEquals(command['name'], 'effect')
00073         self.assertEquals(command['params']['type'], 'fade')
00074 
00075     def test_scriptWithEvents(self):
00076         pythonScriptCode = '''
00077 from kss.core.ttwapi import startKSSCommands
00078 from kss.core.ttwapi import getKSSCommandSet
00079 from kss.core.ttwapi import renderKSSCommands
00080 from kss.core.tests.help_ttwapi import objectModified
00081 startKSSCommands(context, context.REQUEST)
00082 core = getKSSCommandSet('core')
00083 core.replaceInnerHTML('#test', '<p>Done</p>')
00084 objectModified(context)
00085 return renderKSSCommands()
00086 '''
00087         self.app.kss_test.ZPythonScript_edit('', pythonScriptCode)
00088         result = self.app.kss_test()
00089         self.assertEquals(len(result), 2)
00090         command = result[0]
00091         self.assertEquals(command['selector'], '#test')
00092         self.assertEquals(command['name'], 'replaceInnerHTML')
00093         command = result[1]
00094         self.assertEquals(command['selector'], '#event')
00095         self.assertEquals(command['name'], 'replaceInnerHTML')
00096 
00097 @component.adapter(None, KSSView, ObjectModifiedEvent)
00098 def objectModifiedThruKSSView(obj, view, event):
00099     view.getCommandSet('core').replaceInnerHTML(
00100         "#event", "Event subscriber was here.")
00101 
00102 def test_suite():
00103     suites = []
00104     suites.append(unittest.makeSuite(TTWTestCase))
00105     return unittest.TestSuite(suites)