Back to index

plone3  3.1.7
tests.py
Go to the documentation of this file.
00001 import unittest
00002 import doctest
00003 
00004 from zope.interface import implements
00005 from zope.app.testing import placelesssetup
00006 import zope.testing.doctest
00007 
00008 from Products.Five import zcml
00009 from Products.Five import fiveconfigure
00010 
00011 from Testing import ZopeTestCase as ztc
00012 
00013 from Products.PloneTestCase import PloneTestCase as ptc
00014 from Products.PloneTestCase.layer import onsetup
00015 
00016 import borg.localrole
00017 from borg.localrole import factory_adapter
00018 from borg.localrole import default_adapter
00019 
00020 # there is no install package in Zope 2.9
00021 TEST_INSTALL =True
00022 if not hasattr(ztc, 'installPackage'):
00023     TEST_INSTALL = False
00024 
00025 
00026 class SimpleLocalRoleProvider(object):
00027     implements(borg.localrole.interfaces.ILocalRoleProvider)
00028     def __init__(self, context):
00029         self.context = context
00030 
00031     def getRoles(self, user):
00032         """Grant everyone the 'Foo' role"""
00033         return ('Foo',)
00034 
00035     def getAllRoles(self):
00036         """In the real world we would enumerate all users and
00037         grant the 'Foo' role to each, but we won't"""
00038         yield ('bogus_user', ('Foo',))
00039 
00040 
00041 class DummyUser(object):
00042     def __init__(self, uid, group_ids=()):
00043         self.id = uid
00044         self._groups = group_ids
00045 
00046     def getId(self):
00047         return self.id
00048 
00049     def _check_context(self, obj):
00050         return True
00051 
00052     def getGroups(self):
00053         return self._groups
00054 
00055     def getRoles(self):
00056         return ()
00057 
00058 @onsetup
00059 def setup_product():
00060     """Set up the additional products required for this package.
00061     
00062     The @onsetup decorator causes the execution of this body to be deferred
00063     until the setup of the Plone site testing layer.
00064     """
00065     
00066     # Load the ZCML configuration for dependent packages.
00067     
00068     fiveconfigure.debug_mode = True
00069     zcml.load_config('configure.zcml', borg.localrole)
00070     fiveconfigure.debug_mode = False
00071     
00072     # We need to tell the testing framework that these products
00073     # should be available. This can't happen until after we have loaded
00074     # the ZCML.
00075     if TEST_INSTALL:
00076         ztc.installPackage('borg.localrole')
00077     
00078 # The order here is important: We first call the (deferred) function which
00079 # installs the products we need.Then, we let PloneTestCase set up this 
00080 # product on installation.
00081 
00082 setup_product()
00083 ptc.setupPloneSite(products=['borg.localrole'])
00084 
00085 def test_suite():
00086     suite = []
00087 
00088     if TEST_INSTALL:
00089         suite.extend([
00090             ztc.ZopeDocFileSuite(
00091                         'README.txt', package='borg.localrole',
00092                         test_class=ptc.FunctionalTestCase,
00093                         optionflags=(doctest.ELLIPSIS |
00094                                      doctest.NORMALIZE_WHITESPACE)),
00095             ztc.ZopeDocFileSuite(
00096                         'bbb.txt', package='borg.localrole.bbb',
00097                         test_class=ptc.FunctionalTestCase,
00098                         optionflags=(doctest.ELLIPSIS |
00099                                      doctest.NORMALIZE_WHITESPACE)),
00100             ])
00101 
00102     # Add the tests that register adapters at the end
00103 
00104     suite.extend([
00105         zope.testing.doctest.DocTestSuite(borg.localrole.workspace,
00106             setUp=placelesssetup.setUp(),
00107             tearDown=placelesssetup.tearDown(),
00108             optionflags=zope.testing.doctest.ELLIPSIS |
00109                         zope.testing.doctest.NORMALIZE_WHITESPACE),
00110 
00111         zope.testing.doctest.DocTestSuite(factory_adapter),
00112         zope.testing.doctest.DocTestSuite(default_adapter),
00113         ])
00114 
00115 
00116     return unittest.TestSuite(suite)
00117 
00118 if __name__ == '__main__':
00119     unittest.main(defaultTest='test_suite')