Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
PluggableAuthService.tests.test_Caching.PluggableAuthServiceCachingTests Class Reference

List of all members.

Public Member Functions

def tearDown
def test_empty
def test_caching_in_PAS

Private Member Functions

def _getTargetClass
def _makeOne
def _makePlugins
def _makeAndFill

Detailed Description

Definition at line 46 of file test_Caching.py.


Member Function Documentation

Definition at line 52 of file test_Caching.py.

00052 
00053     def _getTargetClass( self ):
00054 
00055         from Products.PluggableAuthService.PluggableAuthService \
00056             import PluggableAuthService
00057 
00058         return PluggableAuthService

Definition at line 86 of file test_Caching.py.

00086 
00087     def _makeAndFill(self):
00088 
00089         from Products.PluggableAuthService.plugins import ZODBUserManager
00090         from Products.PluggableAuthService.plugins import ZODBRoleManager
00091 
00092         plugin_registry = self._makePlugins()
00093         user_source = ZODBUserManager.ZODBUserManager('zodb_users')
00094         roles_source = ZODBRoleManager.ZODBRoleManager('zodb_roles')
00095         pas_instance = self._makeOne(plugins=plugin_registry)
00096         pas_instance._setObject('zodb_users', user_source)
00097         pas_instance._setObject('zodb_roles', roles_source)
00098 
00099         return pas_instance

Here is the caller graph for this function:

def PluggableAuthService.tests.test_Caching.PluggableAuthServiceCachingTests._makeOne (   self,
  plugins = None,
  args,
  kw 
) [private]

Definition at line 59 of file test_Caching.py.

00059 
00060     def _makeOne( self, plugins=None, *args, **kw ):
00061 
00062         zcuf = self._getTargetClass()( *args, **kw )
00063 
00064         if plugins is not None:
00065             zcuf._setObject( 'plugins', plugins )
00066 
00067         rcm = RAMCacheManager('ramcache')
00068         zcuf._setObject('ramcache', rcm)
00069 
00070         return zcuf

def PluggableAuthService.tests.test_Caching.PluggableAuthServiceCachingTests._makePlugins (   self,
  plugin_type_info = None 
) [private]

Definition at line 71 of file test_Caching.py.

00071 
00072     def _makePlugins( self, plugin_type_info=None ):
00073 
00074         from Products.PluggableAuthService.PluggableAuthService \
00075             import _PLUGIN_TYPE_INFO
00076         from Products.PluginRegistry.PluginRegistry import PluginRegistry
00077 
00078         if plugin_type_info is None:
00079             plugin_type_info = _PLUGIN_TYPE_INFO
00080 
00081         reg = PluginRegistry( plugin_type_info=plugin_type_info )
00082         reg._setId( 'plugins' )
00083         reg._plugins = {}
00084 
00085         return reg

Definition at line 48 of file test_Caching.py.

00048 
00049     def tearDown( self ):
00050         pass
00051 

Definition at line 118 of file test_Caching.py.

00118 
00119     def test_caching_in_PAS(self):
00120         zcuf = self._makeAndFill()
00121         rcm = getattr(zcuf, 'ramcache')
00122         plugin_registry = getattr(zcuf, 'plugins')
00123         user_source = getattr(zcuf, 'zodb_users')
00124         roles_source = getattr(zcuf, 'zodb_roles')
00125 
00126         # This is needed because some underlying ZCacheable code wants to
00127         # use self.REQUEST :/
00128         setattr(zcuf, 'REQUEST', FauxRequest())
00129 
00130         # First, we register the ZODBUserManager as a plugin suitable
00131         # for storing and returning user objects and the ZODBRoleManager
00132         # for roles. Basic scaffolding to be able to store and retrieve users.
00133         from Products.PluggableAuthService.interfaces import plugins
00134 
00135         plugin_registry.activatePlugin( plugins.IUserEnumerationPlugin
00136                                       , user_source.getId()
00137                                       )
00138         plugin_registry.activatePlugin( plugins.IUserAdderPlugin
00139                                       , user_source.getId()
00140                                       )
00141         plugin_registry.activatePlugin( plugins.IRolesPlugin
00142                                       , roles_source.getId()
00143                                       )
00144         plugin_registry.activatePlugin( plugins.IRoleEnumerationPlugin
00145                                       , roles_source.getId()
00146                                       )
00147         plugin_registry.activatePlugin( plugins.IRoleAssignerPlugin
00148                                       , roles_source.getId()
00149                                       )
00150 
00151         # Now add a user and make sure it's there
00152         zcuf._doAddUser('testlogin', 'secret', ['Member', 'Anonymous'], [])
00153         self.failIf(zcuf.getUser('testlogin') is None)
00154 
00155         # Then we activate caching for the PAS instance itself
00156         zcuf.ZCacheable_setManagerId(rcm.getId())
00157 
00158         # Make sure the PAS instance is associated with the cache
00159         self.failUnless(aq_base(zcuf.ZCacheable_getManager()) is aq_base(rcm))
00160 
00161         # Now we can see if the cache is getting used. Test for emptiness
00162         # first, then retrieve a user, and the cache should have content.
00163         # Then test again to see if the cache entries are being used.
00164         # This is a bit nasty because I am relying on knowing the structure
00165         # of the cache report, which is really an internal implementation
00166         # detail.
00167 
00168         # First check: The cache must be empty
00169         report = rcm.getCacheReport()
00170         self.failUnless(len(report) == 0)
00171 
00172         # The user is being requested once. At this point there must be one
00173         # entry for the PAS instance. The number of "misses" must be >0 because
00174         # the first cache check will have failed. The number of cache hits must
00175         # be zero.
00176         zcuf.getUser('testlogin')
00177         report = rcm.getCacheReport()
00178         self.failUnless(len(report) == 1)
00179         report_item = report[0]
00180         firstpass_misses = report_item.get('misses')
00181         firstpass_hits = report_item.get('hits')
00182         firstpass_entries = report_item.get('entries')
00183         self.failUnless(firstpass_misses > 0)
00184         self.failUnless(firstpass_hits == 0)
00185 
00186         # The user is requested again. This request should produce a cache hit,
00187         # so the number of "misses" must have stayed the same as after the
00188         # first pass, but the number of hits must now be >0. Also, the number
00189         # of in-memory entries must have remained the same to prove that we are
00190         # reusing the same cache entries.
00191         zcuf.getUser('testlogin')
00192         report = rcm.getCacheReport()
00193         self.failUnless(len(report) == 1)
00194         report_item = report[0]
00195         self.failIf(report_item.get('misses') != firstpass_misses)
00196         self.failUnless(report_item.get('hits') > firstpass_hits)
00197         self.failIf(report_item.get('entries') != firstpass_entries)
00198 

Here is the call graph for this function:

Definition at line 100 of file test_Caching.py.

00100 
00101     def test_empty( self ):
00102         zcuf = self._makeOne()
00103         rcm = getattr(zcuf, 'ramcache')
00104 
00105         # This is needed because some underlying ZCacheable code wants to
00106         # use self.REQUEST :/
00107         setattr(rcm, 'REQUEST', FauxRequest())
00108 
00109         # Make sure the PAS instance itself is Cacheable
00110         self.assert_(isCacheable(zcuf))
00111 
00112         # Make sure the PAS instance is not associated with any cache manager
00113         # by default
00114         self.assert_(zcuf.ZCacheable_getManager() is None)
00115 
00116         # Make sure the RAMCacheManager is empty
00117         self.assert_(len(rcm.getCacheReport()) == 0)


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