Back to index

plone3  3.1.7
test_ScriptablePlugin.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights
00004 # Reserved.
00005 #
00006 # This software is subject to the provisions of the Zope Public License,
00007 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this
00008 # distribution.
00009 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00010 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00011 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00012 # FOR A PARTICULAR PURPOSE.
00013 #
00014 ##############################################################################
00015 import unittest
00016 from OFS.Folder import Folder
00017 from OFS.SimpleItem import SimpleItem
00018 
00019 from zope.interface import Interface
00020 from zope.interface import providedBy
00021 
00022 class IFaux( Interface ):
00023 
00024     def faux_method():
00025         pass
00026 
00027 class IFauxTwo( Interface ):
00028 
00029     def two_method():
00030         pass
00031 
00032 class DummyPluginRegistry( Folder ):
00033 
00034     def listPluginIds( self, interface ):
00035         return ()
00036 
00037     def _getInterfaceFromName( self, name ):
00038         if name == 'IFaux':
00039             return IFaux
00040         if name == 'IFauxTwo':
00041             return IFauxTwo
00042 
00043 class ScriptablePluginTests( unittest.TestCase ):
00044 
00045     def _getTargetClass( self ):
00046 
00047         from Products.PluggableAuthService.plugins.ScriptablePlugin \
00048             import ScriptablePlugin
00049 
00050         return ScriptablePlugin
00051 
00052     def _makeOne( self, id='test', *args, **kw ):
00053 
00054         return self._getTargetClass()( id=id, *args, **kw )
00055 
00056     def test_empty( self ):
00057 
00058         scriptable_plugin = self._makeOne()
00059         self.failIf( IFaux in providedBy(scriptable_plugin) )
00060         self.failIf( IFauxTwo in providedBy(scriptable_plugin) )
00061 
00062     def test_withTwo( self ):
00063 
00064         parent = Folder()
00065         parent._setObject( 'plugins', DummyPluginRegistry() )
00066 
00067         scriptable_plugin = self._makeOne().__of__(parent)
00068 
00069         faux_method = SimpleItem( 'faux_method' )
00070         two_method = SimpleItem( 'two_method' )
00071 
00072         scriptable_plugin._setObject( 'faux_method', faux_method )
00073         scriptable_plugin._setObject( 'two_method', two_method )
00074 
00075         scriptable_plugin.manage_updateInterfaces( ['IFaux', 'IFauxTwo'] )
00076 
00077         self.failUnless( IFaux in providedBy(scriptable_plugin) )
00078         self.failUnless( IFauxTwo in providedBy(scriptable_plugin) )
00079 
00080     def test_withTwoOnlyOneWired( self ):
00081 
00082         parent = Folder()
00083         parent._setObject( 'plugins', DummyPluginRegistry() )
00084 
00085         scriptable_plugin = self._makeOne().__of__(parent)
00086 
00087         faux_method = SimpleItem( 'faux_method' )
00088         whatever = SimpleItem( 'whatever' )
00089 
00090         scriptable_plugin._setObject( 'faux_method', faux_method )
00091         scriptable_plugin._setObject( 'whatever', whatever )
00092 
00093         scriptable_plugin.manage_updateInterfaces( ['IFaux',] )
00094 
00095         self.failUnless( IFaux in providedBy(scriptable_plugin) )
00096 
00097     def test_withTwoMinusOne( self ):
00098 
00099         parent = Folder()
00100         parent._setObject( 'plugins', DummyPluginRegistry() )
00101 
00102         scriptable_plugin = self._makeOne().__of__(parent)
00103 
00104         faux_method = SimpleItem( 'faux_method' )
00105         two_method = SimpleItem( 'two_method' )
00106 
00107         scriptable_plugin._setObject( 'faux_method', faux_method )
00108         scriptable_plugin._setObject( 'two_method', two_method )
00109 
00110         scriptable_plugin.manage_updateInterfaces( ['IFaux', 'IFauxTwo'] )
00111 
00112         scriptable_plugin._delObject( 'two_method' )
00113 
00114         self.failUnless( IFaux in providedBy(scriptable_plugin) )
00115         self.failIf( IFauxTwo in providedBy(scriptable_plugin) )
00116 
00117 
00118 if __name__ == '__main__':
00119     unittest.main()
00120 
00121 def test_suite():
00122     return unittest.TestSuite((
00123         unittest.makeSuite( ScriptablePluginTests ),
00124         ))