Back to index

plone3  3.1.7
base.py
Go to the documentation of this file.
00001 # -*- coding: latin-1 -*-
00002 # Copyright (c) 2005-2007
00003 # Authors: KSS Project Contributors (see docs/CREDITS.txt)
00004 #
00005 # This program is free software; you can redistribute it and/or modify
00006 # it under the terms of the GNU General Public License version 2 as published
00007 # by the Free Software Foundation.
00008 #
00009 # This program is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 # GNU General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU General Public License
00015 # along with this program; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017 # 02111-1307, USA.
00018 
00019 from textwrap import dedent
00020 
00021 import warnings
00022 from Testing.ZopeTestCase import ZopeTestCase, FunctionalTestCase
00023 
00024 from zope import interface
00025 from zope.publisher.interfaces.browser import IBrowserRequest
00026 #from zope.app.testing import placelesssetup
00027 
00028 import kss.core
00029 from kss.core import KSSView
00030 
00031 class KSSCoreLayer:
00032     @classmethod
00033     def setUp(cls):
00034         try:
00035             import Products.Five
00036         except ImportError:
00037             # probably zope 3
00038             pass
00039             # XXX TODO fix this?? --- never run yet on Z3
00040             from zope.configuration.xmlconfig import XMLConfig
00041             XMLConfig('tests/configure-unittest.zcml', kss.core)()
00042         else:
00043             from Products.Five.zcml import load_string, load_config
00044             load_config('meta.zcml', package=Products.Five)
00045 
00046             try:
00047                 load_config('traversing.zcml', package=Products.Five)
00048             except IOError:
00049                 # Let's try the Zope 2.9 way (zope.app.traversing is
00050                 # moved in 2.10)
00051                 load_string(dedent('''\
00052                 <configure xmlns="http://namespaces.zope.org/zope"
00053                            xmlns:five="http://namespaces.zope.org/five">
00054                   <include package="zope.app.traversing" />
00055                   <adapter
00056                        for="*"
00057                        factory="Products.Five.traversable.FiveTraversable"
00058                        provides="zope.app.traversing.interfaces.ITraversable"
00059                        />
00060                    <adapter
00061                        for="*"
00062                        factory="zope.app.traversing.adapters.Traverser"
00063                        provides="zope.app.traversing.interfaces.ITraverser"
00064                        />
00065                 </configure>'''))
00066             # Load the permissions config, if it's there
00067             try:
00068                 load_config('permissions.zcml', package=Products.Five)
00069             except IOError:
00070                 # Zope 2.10 / Five 1.3.6 does not have it
00071                 pass
00072             load_config('configure-unittest.zcml', package=kss.core.tests)
00073 
00074     @classmethod
00075     def tearDown(cls):
00076         pass # placelesssetup.tearDown()
00077     
00078 
00079 class KSSLayer(KSSCoreLayer):
00080     @classmethod
00081     def setUp(cls):
00082         try:
00083             from Products.Five.zcml import load_config
00084         except ImportError:
00085             raise ImportError("KSSLayer requires Five to be installed.")
00086         load_config('meta.zcml', package=kss.core)
00087         load_config('configure.zcml', package=kss.core)
00088 
00089 # Test view
00090 class TestView(KSSView):
00091     def testMethod(self):
00092         'Yes.'
00093 
00094 # Debug request
00095 # This has a modified render.
00096 
00097 class IDebugRequest(IBrowserRequest):
00098     'The debug request'
00099 
00100 class KSSViewTestCaseMixin:
00101 
00102     def loadCoreConfig(self, kss_core=True):
00103         warnings.warn(
00104             "KSS tests are now using layers.  Please do not use "
00105             "loadCoreConfig anymore.",
00106             DeprecationWarning)
00107     
00108     def createView(self):
00109         "Set up a fake view (with no content)"
00110         self.view = self.folder.restrictedTraverse('testMethod')
00111         return self.view
00112 
00113     def setDebugRequest(self):
00114         'commands will be rendered as test friendly data structures'
00115         request = self.folder.REQUEST
00116         interface.directlyProvides(
00117             request,
00118             interface.directlyProvidedBy(request) + IDebugRequest)
00119 
00120 class KSSViewTestCase(ZopeTestCase, KSSViewTestCaseMixin):
00121     layer = KSSLayer
00122 
00123 class KSSViewFunctionalTestCase(FunctionalTestCase, KSSViewTestCase):
00124     'Functional test base'
00125 
00126 # backward compatibility
00127 class AzaxViewTestCase(KSSViewTestCase):
00128     def __init__(self, *args, **kw):
00129         message = "'AzaxViewTestCase' is deprecated," \
00130             "use 'KSSViewTestCase'- KSS uppercase instead."
00131         warnings.warn(message, DeprecationWarning, 2)
00132         KSSViewTestCase.__init__(self, *args, **kw)
00133 
00134 class KssViewTestCase(KSSViewTestCase):
00135     def __init__(self, *args, **kw):
00136         message = "'KssViewTestCase' is deprecated," \
00137             "use 'KSSViewTestCase'- KSS uppercase instead."
00138         warnings.warn(message, DeprecationWarning, 2)
00139         KSSViewTestCase.__init__(self, *args, **kw)
00140 
00141 class KssViewFunctionalTestCase(KSSViewFunctionalTestCase):
00142     def __init__(self, *args, **kw):
00143         message = "'KssViewFunctionalTestCase' is deprecated," \
00144             "use 'KSSViewFunctionalTestCase'- KSS uppercase instead."
00145         warnings.warn(message, DeprecationWarning, 2)
00146         KSSViewFunctionalTestCase.__init__(self, *args, **kw)
00147 
00148 
00149