Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
PluginRegistry.tests.test_PluginRegistry.PluginRegistryTests Class Reference

List of all members.

Public Member Functions

def test_conformance_to_IPluginRegistry
def test_empty
def test_listPluginTypeInfo
def test_activatePluginNoChild
def test_activatePluginInterfaceNonconformance
def test_activatePlugin
def test_activatePlugin_then_remove_interface
def test_deactivatePlugin
def test_movePluginsUp
def test_movePluginsDown
def test_getAllPlugins
def test_removePluginById

Private Member Functions

def _getTargetClass
def _makeOne

Detailed Description

Definition at line 48 of file test_PluginRegistry.py.


Member Function Documentation

Definition at line 50 of file test_PluginRegistry.py.

00050 
00051     def _getTargetClass( self ):
00052 
00053         from Products.PluginRegistry.PluginRegistry import PluginRegistry
00054 
00055         return PluginRegistry

def PluginRegistry.tests.test_PluginRegistry.PluginRegistryTests._makeOne (   self,
  plugin_info = _PLUGIN_INFO,
  args,
  kw 
) [private]

Definition at line 56 of file test_PluginRegistry.py.

00056 
00057     def _makeOne( self, plugin_info=_PLUGIN_INFO, *args, **kw ):
00058 
00059         return self._getTargetClass()( plugin_info, *args, **kw )

Definition at line 108 of file test_PluginRegistry.py.

00108 
00109     def test_activatePlugin( self ):
00110 
00111         parent = DummyFolder()
00112         foo_plugin = DummyPlugin()
00113         directlyProvides( foo_plugin,  ( IFoo, ) )
00114         parent._setObject( 'foo_plugin', foo_plugin )
00115 
00116         preg = self._makeOne().__of__(parent)
00117 
00118         preg.activatePlugin( IFoo, 'foo_plugin')
00119 
00120         idlist = preg.listPluginIds( IFoo )
00121         self.assertEqual( len( idlist ), 1 )
00122         self.assertEqual( idlist[0], 'foo_plugin' )
00123 
00124         plugins = preg.listPlugins( IFoo )
00125         self.assertEqual( len( plugins ), 1 )
00126         plugin = plugins[0]
00127         self.assertEqual( plugin[0], 'foo_plugin' )
00128         self.assertEqual( plugin[1], preg.foo_plugin )

Definition at line 129 of file test_PluginRegistry.py.

00129 
00130     def test_activatePlugin_then_remove_interface( self ):
00131 
00132         parent = DummyFolder()
00133         foo_plugin = DummyPlugin()
00134         directlyProvides( foo_plugin,  ( IFoo, ) )
00135         parent._setObject( 'foo_plugin', foo_plugin )
00136 
00137         preg = self._makeOne().__of__(parent)
00138 
00139         preg.activatePlugin( IFoo, 'foo_plugin')
00140 
00141         replacement = DummyPlugin()
00142         parent._delObject( 'foo_plugin' )
00143         parent._setObject( 'foo_plugin', replacement )
00144 
00145         idlist = preg.listPluginIds( IFoo )
00146         self.assertEqual( len( idlist ), 1 )  # note discrepancy
00147 
00148         plugins = preg.listPlugins( IFoo )
00149         self.assertEqual( len( plugins ), 0 )

Definition at line 97 of file test_PluginRegistry.py.

00097 
00098     def test_activatePluginInterfaceNonconformance( self ):
00099 
00100         parent = DummyFolder()
00101         foo_plugin = DummyPlugin()
00102         parent._setObject( 'foo_plugin', foo_plugin )
00103 
00104         preg = self._makeOne().__of__(parent)
00105 
00106         self.assertRaises( ValueError, preg.activatePlugin, IFoo,
00107                            'foo_plugin' )

Definition at line 88 of file test_PluginRegistry.py.

00088 
00089     def test_activatePluginNoChild( self ):
00090 
00091         parent = DummyFolder()
00092 
00093         preg = self._makeOne().__of__(parent)
00094 
00095         self.assertRaises( AttributeError, preg.activatePlugin, IFoo,
00096                            'foo_plugin' )

Definition at line 60 of file test_PluginRegistry.py.

00060 
00061     def test_conformance_to_IPluginRegistry( self ):
00062 
00063         from Products.PluginRegistry.interfaces import IPluginRegistry
00064         from Products.PluginRegistry.interfaces import _HAS_Z3_INTERFACES
00065 
00066         if _HAS_Z3_INTERFACES:
00067             from zope.interface.verify import verifyClass
00068         else:
00069             from Interface.Verify import verifyClass
00070 
00071         verifyClass( IPluginRegistry, self._getTargetClass() )

Definition at line 150 of file test_PluginRegistry.py.

00150 
00151     def test_deactivatePlugin( self ):
00152 
00153         parent = DummyFolder()
00154         foo_plugin = DummyPlugin()
00155         directlyProvides( foo_plugin, ( IFoo, ) )
00156         parent._setObject( 'foo_plugin', foo_plugin )
00157 
00158         bar_plugin = DummyPlugin()
00159         directlyProvides( bar_plugin, ( IFoo, ) )
00160         parent._setObject( 'bar_plugin', bar_plugin )
00161 
00162         baz_plugin = DummyPlugin()
00163         directlyProvides( baz_plugin, ( IFoo, ) )
00164         parent._setObject( 'baz_plugin', baz_plugin )
00165 
00166         preg = self._makeOne().__of__(parent)
00167 
00168         preg.activatePlugin( IFoo, 'foo_plugin' )
00169         preg.activatePlugin( IFoo, 'bar_plugin' )
00170         preg.activatePlugin( IFoo, 'baz_plugin' )
00171 
00172         preg.deactivatePlugin( IFoo, 'bar_plugin' )
00173 
00174         idlist = preg.listPluginIds( IFoo )
00175         self.assertEqual( len( idlist ), 2 )
00176         self.assertEqual( idlist[0], 'foo_plugin' )
00177         self.assertEqual( idlist[1], 'baz_plugin' )

Definition at line 72 of file test_PluginRegistry.py.

00072 
00073     def test_empty( self ):
00074 
00075         preg = self._makeOne()
00076 
00077         self.assertRaises( KeyError, preg.listPlugins, INonesuch )
00078         self.assertEqual( len( preg.listPlugins( IFoo ) ), 0 )
00079         self.assertEqual( len( preg.listPluginIds( IFoo ) ), 0 )

Definition at line 244 of file test_PluginRegistry.py.

00244 
00245     def test_getAllPlugins( self ):
00246 
00247         parent = DummyFolder()
00248         foo_plugin = DummyPlugin()
00249         directlyProvides( foo_plugin, ( IFoo, ) )
00250         parent._setObject( 'foo_plugin', foo_plugin )
00251 
00252         bar_plugin = DummyPlugin()
00253         directlyProvides( bar_plugin, ( IFoo, ) )
00254         parent._setObject( 'bar_plugin', bar_plugin )
00255 
00256         baz_plugin = DummyPlugin()
00257         directlyProvides( baz_plugin, ( IFoo, ) )
00258         parent._setObject( 'baz_plugin', baz_plugin )
00259 
00260         preg = self._makeOne().__of__( parent )
00261 
00262         first = preg.getAllPlugins( 'IFoo' )
00263 
00264         self.assertEqual( len( first[ 'active' ] ), 0 )
00265 
00266         self.assertEqual( len( first[ 'available' ] ), 3 )
00267         self.failUnless( 'foo_plugin' in first[ 'available' ] )
00268         self.failUnless( 'bar_plugin' in first[ 'available' ] )
00269         self.failUnless( 'baz_plugin' in first[ 'available' ] )
00270 
00271         preg.activatePlugin( IFoo, 'foo_plugin' )
00272 
00273         second = preg.getAllPlugins( 'IFoo' )
00274 
00275         self.assertEqual( len( second[ 'active' ] ), 1 )
00276         self.failUnless( 'foo_plugin' in second[ 'active' ] )
00277 
00278         self.assertEqual( len( second[ 'available' ] ), 2 )
00279         self.failIf( 'foo_plugin' in second[ 'available' ] )
00280         self.failUnless( 'bar_plugin' in second[ 'available' ] )
00281         self.failUnless( 'baz_plugin' in second[ 'available' ] )
00282 
00283         preg.activatePlugin( IFoo, 'bar_plugin' )
00284         preg.activatePlugin( IFoo, 'baz_plugin' )
00285 
00286         third = preg.getAllPlugins( 'IFoo' )
00287 
00288         self.assertEqual( len( third[ 'active' ] ), 3 )
00289         self.failUnless( 'foo_plugin' in third[ 'active' ] )
00290         self.failUnless( 'bar_plugin' in third[ 'active' ] )
00291         self.failUnless( 'baz_plugin' in third[ 'active' ] )
00292 
00293         self.assertEqual( len( third[ 'available' ] ), 0 )

Definition at line 80 of file test_PluginRegistry.py.

00080 
00081     def test_listPluginTypeInfo( self ):
00082 
00083         pref = self._makeOne()
00084 
00085         pti = pref.listPluginTypeInfo()
00086         self.assertEqual( pti[0]['interface'], IFoo )
00087         self.assertEqual( pti[1]['title'], 'bar' )

Definition at line 211 of file test_PluginRegistry.py.

00211 
00212     def test_movePluginsDown( self ):
00213 
00214         parent = DummyFolder()
00215         foo_plugin = DummyPlugin()
00216         directlyProvides( foo_plugin, ( IFoo, ) )
00217         parent._setObject( 'foo_plugin', foo_plugin )
00218 
00219         bar_plugin = DummyPlugin()
00220         directlyProvides( bar_plugin, ( IFoo, ) )
00221         parent._setObject( 'bar_plugin', bar_plugin )
00222 
00223         baz_plugin = DummyPlugin()
00224         directlyProvides( baz_plugin, ( IFoo, ) )
00225         parent._setObject( 'baz_plugin', baz_plugin )
00226 
00227         preg = self._makeOne().__of__(parent)
00228 
00229         preg.activatePlugin( IFoo, 'foo_plugin' )
00230         preg.activatePlugin( IFoo, 'bar_plugin' )
00231         preg.activatePlugin( IFoo, 'baz_plugin' )
00232 
00233         self.assertRaises( ValueError, preg.movePluginsDown
00234                          , IFoo, ( 'quux_plugin', ) )
00235 
00236         preg.movePluginsDown( IFoo, ( 'foo_plugin', 'bar_plugin' ) )
00237 
00238         idlist = preg.listPluginIds( IFoo )
00239         self.assertEqual( len( idlist ), 3 )
00240 
00241         self.assertEqual( idlist[0], 'baz_plugin' )
00242         self.assertEqual( idlist[1], 'foo_plugin' )
00243         self.assertEqual( idlist[2], 'bar_plugin' )

Definition at line 178 of file test_PluginRegistry.py.

00178 
00179     def test_movePluginsUp( self ):
00180 
00181         parent = DummyFolder()
00182         foo_plugin = DummyPlugin()
00183         directlyProvides( foo_plugin, ( IFoo, ) )
00184         parent._setObject( 'foo_plugin', foo_plugin )
00185 
00186         bar_plugin = DummyPlugin()
00187         directlyProvides( bar_plugin, ( IFoo, ) )
00188         parent._setObject( 'bar_plugin', bar_plugin )
00189 
00190         baz_plugin = DummyPlugin()
00191         directlyProvides( baz_plugin, ( IFoo, ) )
00192         parent._setObject( 'baz_plugin', baz_plugin )
00193 
00194         preg = self._makeOne().__of__(parent)
00195 
00196         preg.activatePlugin( IFoo, 'foo_plugin' )
00197         preg.activatePlugin( IFoo, 'bar_plugin' )
00198         preg.activatePlugin( IFoo, 'baz_plugin' )
00199 
00200         self.assertRaises( ValueError, preg.movePluginsUp
00201                          , IFoo, ( 'quux_plugin', ) )
00202 
00203         preg.movePluginsUp( IFoo, ( 'bar_plugin', 'baz_plugin' ) )
00204 
00205         idlist = preg.listPluginIds( IFoo )
00206         self.assertEqual( len( idlist ), 3 )
00207 
00208         self.assertEqual( idlist[0], 'bar_plugin' )
00209         self.assertEqual( idlist[1], 'baz_plugin' )
00210         self.assertEqual( idlist[2], 'foo_plugin' )

Definition at line 294 of file test_PluginRegistry.py.

00294 
00295     def test_removePluginById( self ):
00296 
00297         parent = DummyFolder()
00298         foo_plugin = DummyPlugin()
00299         directlyProvides( foo_plugin, ( IFoo, IBar ) )
00300         parent._setObject( 'foo_plugin', foo_plugin )
00301 
00302         bar_plugin = DummyPlugin()
00303         directlyProvides( bar_plugin, ( IFoo, ) )
00304         parent._setObject( 'bar_plugin', bar_plugin )
00305 
00306         baz_plugin = DummyPlugin()
00307         directlyProvides( baz_plugin, ( IBar, ) )
00308         parent._setObject( 'baz_plugin', baz_plugin )
00309 
00310         preg = self._makeOne().__of__(parent)
00311 
00312         preg.activatePlugin( IFoo, 'foo_plugin' )
00313         preg.activatePlugin( IBar, 'foo_plugin' )
00314         preg.activatePlugin( IFoo, 'bar_plugin' )
00315         preg.activatePlugin( IBar, 'baz_plugin' )
00316 
00317         preg.removePluginById( 'foo_plugin' )
00318 
00319         idlist = preg.listPluginIds( IFoo )
00320         self.assertEqual( len( idlist ), 1 )
00321         self.assertEqual( idlist[0], 'bar_plugin' )
00322 
00323         idlist = preg.listPluginIds( IBar )
00324         self.assertEqual( len( idlist ), 1 )
00325         self.assertEqual( idlist[0], 'baz_plugin' )


The documentation for this class was generated from the following file: