[Checkins] SVN: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py Add tests for searchUsers.
Maurits van Rees
cvs-admin at zope.org
Thu Jan 3 14:11:17 UTC 2013
Log message for revision 128994:
Add tests for searchUsers.
Change DummyUserEnumerator to be able to handle sequences of ids or logins.
Changed:
U Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py
-=-
Modified: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py
===================================================================
--- Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py 2013-01-03 13:23:31 UTC (rev 128993)
+++ Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/tests/test_PluggableAuthService.py 2013-01-03 14:11:16 UTC (rev 128994)
@@ -58,10 +58,17 @@
, 'pluginid' : self.PLUGINID
} ]
- if kw.get( 'id' ) == _id:
+ # Both id and login can be strings or sequences.
+ user_id = kw.get( 'id' )
+ if isinstance( user_id, basestring ):
+ user_id = [ user_id ]
+ if user_id and _id in user_id:
return tuple(result)
- if kw.get( 'login' ) == self._login:
+ login = kw.get( 'login' )
+ if isinstance( login, basestring ):
+ login = [ login ]
+ if login and self._login in login:
return tuple(result)
return ()
@@ -2231,6 +2238,89 @@
self.failIf( plugins.listPlugins( IAuthenticationPlugin ) )
self.failIf( plugins.listPlugins( IUserEnumerationPlugin ) )
+ def test_searchUsers( self ):
+
+ from Products.PluggableAuthService.interfaces.plugins \
+ import IUserEnumerationPlugin
+
+ plugins = self._makePlugins()
+ zcuf = self._makeOne( plugins )
+
+ foo = self._makeUserEnumerator( 'foo' )
+ zcuf._setObject( 'foo', foo )
+
+ plugins = zcuf._getOb( 'plugins' )
+ plugins.activatePlugin( IUserEnumerationPlugin, 'foo' )
+
+ # Search by id
+ self.failIf( zcuf.searchUsers( id='zope' ) )
+ self.failUnless( zcuf.searchUsers( id='foo' ) )
+ self.failUnless( len( zcuf.searchUsers( id='foo' )) == 1 )
+
+ # Search by login name
+ self.failIf( zcuf.searchUsers( name='zope' ) )
+ self.failUnless( zcuf.searchUsers( name='foo' ) )
+ self.failUnless( len( zcuf.searchUsers( name='foo' )) == 1 )
+
+ # Login name can be a sequence
+ self.failIf( zcuf.searchUsers( name=['zope'] ) )
+ self.failUnless( zcuf.searchUsers( name=['foo'] ) )
+ self.failUnless( len( zcuf.searchUsers( name=['foo'] )) == 1 )
+ self.failIf( zcuf.searchUsers( name=('zope', ) ) )
+ self.failUnless( zcuf.searchUsers( name=('foo', ) ) )
+ self.failUnless( len( zcuf.searchUsers( name=('foo', ) )) == 1 )
+ self.failUnless( zcuf.searchUsers( name=('foo', 'bar' ) ) )
+ self.failUnless( len( zcuf.searchUsers( name=('foo', 'bar') )) == 1 )
+
+ def test_searchUsers_transform( self ):
+
+ from Products.PluggableAuthService.interfaces.plugins \
+ import IUserEnumerationPlugin
+
+ plugins = self._makePlugins()
+ zcuf = self._makeOne( plugins )
+ zcuf.login_transform = 'lower'
+
+ # user id upper case, login name lower case
+ foo = self._makeUserEnumerator( 'FOO', 'foo' )
+ zcuf._setObject( 'foo', foo )
+ bar = self._makeUserEnumerator( 'BAR', 'bar' )
+ zcuf._setObject( 'bar', bar )
+
+ plugins = zcuf._getOb( 'plugins' )
+ # Note: we only activate 'foo' for now.
+ plugins.activatePlugin( IUserEnumerationPlugin, 'foo' )
+
+ # Search by id
+ self.failIf( zcuf.searchUsers( id='ZOPE' ) )
+ self.failUnless( zcuf.searchUsers( id='FOO' ) )
+ self.failUnless( len( zcuf.searchUsers( id='FOO' )) == 1 )
+
+ # Search by login name
+ self.failIf( zcuf.searchUsers( name='Zope' ) )
+ self.failUnless( zcuf.searchUsers( name='Foo' ) )
+ self.failUnless( len( zcuf.searchUsers( name='Foo' )) == 1 )
+
+ # Login name can be a sequence
+ self.failIf( zcuf.searchUsers( name=['Zope'] ) )
+ self.failUnless( zcuf.searchUsers( name=['Foo'] ) )
+ self.failUnless( len( zcuf.searchUsers( name=['Foo'] )) == 1 )
+ self.failIf( zcuf.searchUsers( name=('Zope', ) ) )
+ self.failUnless( zcuf.searchUsers( name=('Foo', ) ) )
+ self.failUnless( len( zcuf.searchUsers( name=('Foo', ) )) == 1 )
+
+ # Search for more ids or names.
+ self.failUnless( zcuf.searchUsers( id=['FOO', 'BAR', 'ZOPE'] ) )
+ self.failUnless( len( zcuf.searchUsers( id=['FOO', 'BAR', 'ZOPE'] )) == 1 )
+ self.failUnless( zcuf.searchUsers( name=('Foo', 'Bar' , 'Zope' ) ) )
+ self.failUnless( len( zcuf.searchUsers( name=('Foo', 'Bar', 'Zope') )) == 1 )
+
+ # Activate the bar plugin and try again.
+ plugins.activatePlugin( IUserEnumerationPlugin, 'bar' )
+ self.failUnless( len( zcuf.searchUsers( id=['FOO', 'BAR', 'ZOPE'] )) == 2 )
+ self.failUnless( len( zcuf.searchUsers( name=('Foo', 'Bar', 'Zope') )) == 2 )
+
+
def test_searchGroups( self ):
from Products.PluggableAuthService.interfaces.plugins \
More information about the checkins
mailing list