Back to index

plone3  3.1.7
testing.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit test mixin classes and layers.
00014 
00015 $Id: testing.py 80863 2007-10-13 16:02:33Z shh $
00016 """
00017 
00018 from OFS.SimpleItem import SimpleItem
00019 from Products.Five import zcml
00020 from zope.app.component.hooks import setHooks
00021 from zope.component import adapts
00022 from zope.i18n.interfaces import IUserPreferredLanguages
00023 from zope.interface import implements
00024 from zope.publisher.interfaces.http import IHTTPRequest
00025 from zope.testing import testrunner
00026 from zope.testing.cleanup import cleanUp
00027 
00028 from Products.CMFCore.interfaces import IWorkflowDefinition
00029 from Products.GenericSetup.utils import BodyAdapterBase
00030 
00031 
00032 class ConformsToFolder:
00033 
00034     def test_folder_z2interfaces(self):
00035         from Interface.Verify import verifyClass
00036         from webdav.WriteLockInterface import WriteLockInterface
00037         from Products.CMFCore.interfaces.Dynamic \
00038                 import DynamicType as IDynamicType
00039         from Products.CMFCore.interfaces.Folderish \
00040                 import Folderish as IFolderish
00041 
00042         verifyClass(IDynamicType, self._getTargetClass())
00043         verifyClass(IFolderish, self._getTargetClass())
00044         verifyClass(WriteLockInterface, self._getTargetClass())
00045 
00046     def test_folder_z3interfaces(self):
00047         from zope.interface.verify import verifyClass
00048         from webdav.interfaces import IWriteLock
00049         from Products.CMFCore.interfaces import IDynamicType
00050         from Products.CMFCore.interfaces import IFolderish
00051         from Products.CMFCore.interfaces import IMutableMinimalDublinCore
00052 
00053         verifyClass(IDynamicType, self._getTargetClass())
00054         verifyClass(IFolderish, self._getTargetClass())
00055         verifyClass(IMutableMinimalDublinCore, self._getTargetClass())
00056         verifyClass(IWriteLock, self._getTargetClass())
00057 
00058 
00059 class ConformsToContent:
00060 
00061     def test_content_z2interfaces(self):
00062         from Interface.Verify import verifyClass
00063         from Products.CMFCore.interfaces.Contentish \
00064                 import Contentish as IContentish
00065         from Products.CMFCore.interfaces.DublinCore \
00066                 import CatalogableDublinCore as ICatalogableDublinCore
00067         from Products.CMFCore.interfaces.DublinCore \
00068                 import DublinCore as IDublinCore
00069         from Products.CMFCore.interfaces.DublinCore \
00070                 import MutableDublinCore as IMutableDublinCore
00071         from Products.CMFCore.interfaces.Dynamic \
00072                 import DynamicType as IDynamicType
00073 
00074         verifyClass(ICatalogableDublinCore, self._getTargetClass())
00075         verifyClass(IContentish, self._getTargetClass())
00076         verifyClass(IDublinCore, self._getTargetClass())
00077         verifyClass(IDynamicType, self._getTargetClass())
00078         verifyClass(IMutableDublinCore, self._getTargetClass())
00079 
00080     def test_content_z3interfaces(self):
00081         from zope.interface.verify import verifyClass
00082         from Products.CMFCore.interfaces import ICatalogableDublinCore
00083         from Products.CMFCore.interfaces import IContentish
00084         from Products.CMFCore.interfaces import IDublinCore
00085         from Products.CMFCore.interfaces import IDynamicType
00086         from Products.CMFCore.interfaces import IMutableDublinCore
00087         from Products.GenericSetup.interfaces import IDAVAware
00088 
00089         verifyClass(ICatalogableDublinCore, self._getTargetClass())
00090         verifyClass(IContentish, self._getTargetClass())
00091         verifyClass(IDAVAware, self._getTargetClass())
00092         verifyClass(IDublinCore, self._getTargetClass())
00093         verifyClass(IDynamicType, self._getTargetClass())
00094         verifyClass(IMutableDublinCore, self._getTargetClass())
00095 
00096 
00097 class BrowserLanguages(object):
00098 
00099     implements(IUserPreferredLanguages)
00100     adapts(IHTTPRequest)
00101 
00102     def __init__(self, context):
00103         self.context = context
00104 
00105     def getPreferredLanguages(self):
00106         return ('test',)
00107 
00108 
00109 class EventZCMLLayer:
00110 
00111     @classmethod
00112     def testSetUp(cls):
00113         import Products
00114 
00115         zcml.load_config('meta.zcml', Products.Five)
00116         zcml.load_config('event.zcml', Products.Five)
00117         zcml.load_config('event.zcml', Products.CMFCore)
00118         setHooks()
00119 
00120     @classmethod
00121     def testTearDown(cls):
00122         cleanUp()
00123 
00124 
00125 class TraversingZCMLLayer:
00126 
00127     @classmethod
00128     def testSetUp(cls):
00129         import Products.Five
00130 
00131         zcml.load_config('meta.zcml', Products.Five)
00132         zcml.load_config('traversing.zcml', Products.Five)
00133         setHooks()
00134 
00135     @classmethod
00136     def testTearDown(cls):
00137         cleanUp()
00138 
00139 
00140 class TraversingEventZCMLLayer:
00141 
00142     @classmethod
00143     def testSetUp(cls):
00144         import Products.Five
00145 
00146         zcml.load_config('meta.zcml', Products.Five)
00147         zcml.load_config('traversing.zcml', Products.Five)
00148         zcml.load_config('event.zcml', Products.Five)
00149         zcml.load_config('event.zcml', Products.CMFCore)
00150         setHooks()
00151 
00152     @classmethod
00153     def testTearDown(cls):
00154         cleanUp()
00155 
00156 
00157 class FunctionalZCMLLayer:
00158 
00159     @classmethod
00160     def setUp(cls):
00161         import Products
00162 
00163         zcml.load_config('testing.zcml', Products.CMFCore)
00164         setHooks()
00165 
00166     @classmethod
00167     def tearDown(cls):
00168         cleanUp()
00169 
00170 
00171 _DUMMY_ZCML = """\
00172 <configure
00173     xmlns="http://namespaces.zope.org/zope"
00174     xmlns:five="http://namespaces.zope.org/five"
00175     i18n_domain="dummy">
00176   <permission id="dummy.add" title="Add Dummy Workflow"/>
00177   <five:registerClass
00178       class="Products.CMFCore.testing.DummyWorkflow"
00179       meta_type="Dummy Workflow"
00180       permission="dummy.add"
00181       addview="addDummyWorkflow.html"
00182       global="false"
00183       />
00184   <adapter
00185       factory="Products.CMFCore.testing.DummyWorkflowBodyAdapter"
00186       provides="Products.GenericSetup.interfaces.IBody"
00187       for="Products.CMFCore.interfaces.IWorkflowDefinition
00188            Products.GenericSetup.interfaces.ISetupEnviron"
00189       />
00190 </configure>
00191 """
00192 
00193 
00194 class DummyWorkflow(SimpleItem):
00195 
00196     implements(IWorkflowDefinition)
00197 
00198     meta_type = 'Dummy Workflow'
00199 
00200     def __init__(self, id):
00201         self._id = id
00202 
00203     def getId(self):
00204         return self._id
00205 
00206 
00207 class DummyWorkflowBodyAdapter(BodyAdapterBase):
00208 
00209     body = property(BodyAdapterBase._exportBody, BodyAdapterBase._importBody)
00210 
00211 
00212 class ExportImportZCMLLayer:
00213 
00214     @classmethod
00215     def testSetUp(cls):
00216         import Products.Five
00217         import Products.GenericSetup
00218         import Products.CMFCore
00219         import Products.CMFCore.exportimport
00220 
00221         zcml.load_config('meta.zcml', Products.Five)
00222         zcml.load_config('permissions.zcml', Products.Five)
00223         zcml.load_config('configure.zcml', Products.GenericSetup)
00224         zcml.load_config('tool.zcml', Products.CMFCore)
00225         zcml.load_config('configure.zcml', Products.CMFCore.exportimport)
00226         zcml.load_string(_DUMMY_ZCML)
00227         setHooks()
00228 
00229     @classmethod
00230     def testTearDown(cls):
00231         cleanUp()
00232 
00233 
00234 # Derive from ZopeLite layer if available
00235 try:
00236     from Testing.ZopeTestCase.layer import ZopeLite
00237 except ImportError:
00238     pass # Zope < 2.11
00239 else:
00240     EventZCMLLayer.__bases__ = (ZopeLite,)
00241     TraversingZCMLLayer.__bases__ = (ZopeLite,)
00242     TraversingEventZCMLLayer.__bases__ = (ZopeLite,)
00243     FunctionalZCMLLayer.__bases__ = (ZopeLite,)
00244     ExportImportZCMLLayer.__bases__ = (ZopeLite,)
00245 
00246 
00247 def run(test_suite):
00248     options = testrunner.get_options()
00249     options.resume_layer = None
00250     options.resume_number = 0
00251     testrunner.run_with_options(options, test_suite)