Back to index

plone3  3.1.7
test_kssview_functional.py
Go to the documentation of this file.
00001 #
00002 # This program is free software; you can redistribute it and/or modify
00003 # it under the terms of the GNU General Public License version 2 as published
00004 # by the Free Software Foundation.
00005 #
00006 # This program is distributed in the hope that it will be useful,
00007 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00008 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00009 # GNU General Public License for more details.
00010 #
00011 # You should have received a copy of the GNU General Public License
00012 # along with this program; if not, write to the Free Software
00013 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00014 # 02111-1307, USA.
00015 #
00016 import unittest
00017 
00018 import Products.Five
00019 from Products.Five import zcml
00020 from Testing.ZopeTestCase import FunctionalDocTestSuite
00021 
00022 from zope import event, component
00023 from zope.testing.cleanup import cleanUp
00024 from zope.lifecycleevent import ObjectModifiedEvent
00025 from zope.app.component.hooks import getSite, setHooks
00026 
00027 from kss.core import KSSView
00028 
00029 class TestKSSView(KSSView):
00030 
00031     def __call__(self):
00032         self.messages = []
00033         if getSite() == self:
00034             self.messages.append("I'm the current site.")
00035         if component.getSiteManager() == self.getSiteManager():
00036             self.messages.append("I have the current site manager.")
00037         event.notify(ObjectModifiedEvent(self.context))
00038         return "\n".join(self.messages)
00039 
00040 @component.adapter(None, KSSView, ObjectModifiedEvent)
00041 def objectModifiedThruKSSView(obj, view, event):
00042     view.messages.append("Event subscriber was here.")
00043 
00044 def setUp(test=None):
00045     configure_zcml = '''\
00046     <configure
00047          xmlns="http://namespaces.zope.org/zope"
00048          xmlns:browser="http://namespaces.zope.org/browser"
00049          package="kss.core.tests.test_kssview_functional">
00050       <browser:page
00051           for="*"
00052           name="testkssview"
00053           class=".TestKSSView"
00054           permission="zope.Public"
00055           />
00056       <subscriber handler=".objectModifiedThruKSSView" />
00057     </configure>'''
00058     zcml.load_config('configure.zcml', Products.Five)
00059     zcml.load_string(configure_zcml)
00060     setHooks()
00061 
00062 def tearDown(test=None):
00063     cleanUp()
00064 
00065 def ftest_kssview():
00066     """
00067     Let's verify that a KSSView actually is the current site when it's
00068     being traversed to.  Also, let's make sure that if in the course
00069     of this view, an object event is fired, the view will dispatch to
00070     KSS-specific subscribers:
00071     
00072       >>> from Products.Five.testbrowser import Browser
00073       >>> browser = Browser('http://localhost:8080/testkssview')
00074       >>> print browser.contents
00075       I'm the current site.
00076       I have the current site manager.
00077       Event subscriber was here.
00078     """
00079 
00080 def test_suite():
00081     return unittest.TestSuite([
00082         FunctionalDocTestSuite(setUp=setUp, tearDown=tearDown),
00083         ])