[Zope-CVS] CVS: Products/PluggableAuthService/plugins/tests - test_ZODBGroupManager.py:1.6 test_ScriptablePlugin.py:1.6 test_DynamicGroupsPlugin.py:1.2

Zachery Bir zbir at urbanape.com
Wed Jul 6 14:49:36 EDT 2005


Update of /cvs-repository/Products/PluggableAuthService/plugins/tests
In directory cvs.zope.org:/tmp/cvs-serv29036/plugins/tests

Modified Files:
	test_ZODBGroupManager.py test_ScriptablePlugin.py 
	test_DynamicGroupsPlugin.py 
Log Message:
Merging per-plugin id mangling and Zope 2.7/2.8 Interface compatibility code


=== Products/PluggableAuthService/plugins/tests/test_ZODBGroupManager.py 1.5 => 1.6 ===
--- Products/PluggableAuthService/plugins/tests/test_ZODBGroupManager.py:1.5	Mon Sep 13 11:14:46 2004
+++ Products/PluggableAuthService/plugins/tests/test_ZODBGroupManager.py	Wed Jul  6 14:49:05 2005
@@ -229,6 +229,42 @@
         for info in info_list:
             self.failUnless( info[ 'id' ] in SUBSET )
 
+    def test_enumerateGroups_prefixed( self ):
+
+        from Products.PluggableAuthService.tests.test_PluggableAuthService \
+            import FauxRoot
+
+        root = FauxRoot()
+        zrm = self._makeOne( id='prefixed' ).__of__( root )
+        zrm.prefix = 'prefixed_'
+
+        ID_LIST = ( 'foo', 'bar', 'baz', 'bam' )
+        PRE_LIST = tuple(['prefixed_%s' % x for x in ID_LIST])
+
+        for id in ID_LIST:
+
+            zrm.addGroup( id, 'Group %s' % id, 'This is group, %s' % id )
+
+        info_list = zrm.enumerateGroups()
+
+        self.assertEqual( len( info_list ), len( ID_LIST ) )
+
+        for info in info_list:
+            self.failUnless( info[ 'id' ] in PRE_LIST )
+
+    def test_addPrincipalToGroup( self ):
+
+        zgm = self._makeOne()
+        zgm.prefix = 'prefixed_'
+
+        zgm.addGroup( 'group' )
+
+        user = DummyUser( 'userid' )
+
+        zgm.addPrincipalToGroup( user.getId(), 'group' )
+        groups = zgm.getGroupsForPrincipal( user )
+        self.assertEqual( groups, ( 'prefixed_group', ) )
+
 if __name__ == "__main__":
     unittest.main()
 


=== Products/PluggableAuthService/plugins/tests/test_ScriptablePlugin.py 1.5 => 1.6 ===
--- Products/PluggableAuthService/plugins/tests/test_ScriptablePlugin.py:1.5	Sat Oct 16 16:15:46 2004
+++ Products/PluggableAuthService/plugins/tests/test_ScriptablePlugin.py	Wed Jul  6 14:49:05 2005
@@ -15,7 +15,13 @@
 import unittest
 from OFS.Folder import Folder
 from OFS.SimpleItem import SimpleItem
-from Interface import Interface
+
+try:
+    from zope.interface import Interface
+except ImportError:
+    from Interface import Interface
+
+from Products.PluggableAuthService.utils import providedBy
 
 class IFaux( Interface ):
 
@@ -54,7 +60,8 @@
     def test_empty( self ):
 
         scriptable_plugin = self._makeOne()
-        self.assertEqual( len(scriptable_plugin.__implements__), 2 )
+        self.assertFalse( IFaux in providedBy(scriptable_plugin) )
+        self.assertFalse( IFauxTwo in providedBy(scriptable_plugin) )
 
     def test_withTwo( self ):
 
@@ -71,7 +78,8 @@
 
         scriptable_plugin.manage_updateInterfaces( ['IFaux', 'IFauxTwo'] )
 
-        self.assertEqual( len(scriptable_plugin.__implements__), 4 )
+        self.assertTrue( IFaux in providedBy(scriptable_plugin) )
+        self.assertTrue( IFauxTwo in providedBy(scriptable_plugin) )
 
     def test_withTwoOnlyOneWired( self ):
 
@@ -88,7 +96,7 @@
 
         scriptable_plugin.manage_updateInterfaces( ['IFaux',] )
 
-        self.assertEqual( len(scriptable_plugin.__implements__), 3 )
+        self.assertTrue( IFaux in providedBy(scriptable_plugin) )
 
     def test_withTwoMinusOne( self ):
 
@@ -107,7 +115,8 @@
 
         scriptable_plugin._delObject( 'two_method' )
 
-        self.assertEqual( len(scriptable_plugin.__implements__), 3 )
+        self.assertTrue( IFaux in providedBy(scriptable_plugin) )
+        self.assertFalse( IFauxTwo in providedBy(scriptable_plugin) )
 
 
 if __name__ == '__main__':


=== Products/PluggableAuthService/plugins/tests/test_DynamicGroupsPlugin.py 1.1 => 1.2 ===
--- Products/PluggableAuthService/plugins/tests/test_DynamicGroupsPlugin.py:1.1	Wed Sep 22 07:01:57 2004
+++ Products/PluggableAuthService/plugins/tests/test_DynamicGroupsPlugin.py	Wed Jul  6 14:49:05 2005
@@ -48,7 +48,7 @@
         return self._id
 
 class DynamicGroupsPlugin( unittest.TestCase
-                         , IGroupsPlugin_conformance 
+                         , IGroupsPlugin_conformance
                          , IGroupEnumerationPlugin_conformance
                          ):
 
@@ -328,7 +328,7 @@
 
         dpg = self._makeOne( 'ggp_request' )
         principal = FauxPrincipal( 'faux' )
-        
+
         groups = dpg.getGroupsForPrincipal( principal )
 
         self.assertEqual( len( groups ), 0 )
@@ -337,7 +337,7 @@
 
         dpg = self._makeOne( 'ggp_principal' )
         principal = FauxPrincipal( 'faux' )
-        
+
         dpg.addGroup( 'effable', 'python:principal.getId().startswith("f")' )
         groups = dpg.getGroupsForPrincipal( principal, {} )
         self.assertEqual( len( groups ), 1 )
@@ -347,7 +347,7 @@
 
         dpg = self._makeOne( 'ggp_python' )
         principal = FauxPrincipal( 'faux' )
-        
+
         dpg.addGroup( 'everyone', 'python:1' )
         groups = dpg.getGroupsForPrincipal( principal, {} )
         self.assertEqual( len( groups ), 1 )
@@ -357,7 +357,7 @@
 
         dpg = self._makeOne( 'ggp_request' )
         principal = FauxPrincipal( 'faux' )
-        
+
         dpg.addGroup( 'local', 'request/is_local | nothing' )
 
         groups = dpg.getGroupsForPrincipal( principal, {} )
@@ -377,7 +377,7 @@
 
         dpg = self._makeOne( 'ggp_group' )
         principal = FauxPrincipal( 'faux' )
-        
+
         dpg.addGroup( 'willing', 'group/willing' )
         dpg.willing._setProperty( 'willing', type='boolean', value=0 )
 
@@ -393,7 +393,7 @@
 
         dpg = self._makeOne( 'ggp_plugin' )
         principal = FauxPrincipal( 'faux' )
-        
+
         dpg.addGroup( 'scripted', 'python: plugin.callme(request)' )
         callme = FauxScript( 'callme', 0 )
         dpg._setOb( 'callme', callme )
@@ -405,7 +405,7 @@
 
         dpg = self._makeOne( 'ggp_plugin' )
         principal = FauxPrincipal( 'faux' )
-        
+
         dpg.addGroup( 'scripted', 'python: plugin.callme(request)' )
         callme = FauxScript( 'callme', 1 )
         dpg._setOb( 'callme', callme )
@@ -414,11 +414,71 @@
         self.assertEqual( len( groups ), 1 )
         self.failUnless( 'scripted' in groups )
 
+    def test_enumerateGroups_matching_with_optional_prefix( self ):
+
+        from Products.PluggableAuthService.tests.test_PluggableAuthService \
+            import FauxRoot
+
+        root = FauxRoot()
+        dpg = self._makeOne( 'enumerating' ).__of__( root )
+        dpg.prefix = 'enumerating_'
+
+        dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
+        dpg.addGroup( 'noone', 'python:False', active=True )
+        dpg.addGroup( 'hohum', 'nothing', active=True )
+
+        ID_LIST = ( 'enumerating_everyone', )
+
+        info_list = dpg.enumerateGroups( id=ID_LIST, exact_match=True )
+
+        self.assertEqual( len( info_list ), len( ID_LIST ) )
+
+        ids = [ x[ 'id' ] for x in info_list ]
+
+        for id in ID_LIST:
+            self.failUnless( id in ids )
+
+    def test_enumerateGroups_enumerating_with_optional_prefix( self ):
+
+        from Products.PluggableAuthService.tests.test_PluggableAuthService \
+            import FauxRoot
+
+        root = FauxRoot()
+        dpg = self._makeOne( 'enumerating' ).__of__( root )
+        dpg.prefix = 'enumerating_'
+
+        dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
+        dpg.addGroup( 'noone', 'python:False', active=True )
+        dpg.addGroup( 'hohum', 'nothing', active=True )
+
+        ID_LIST = ( 'enumerating_everyone', 'enumerating_noone',
+                    'enumerating_hohum' )
+
+        info_list = dpg.enumerateGroups()
+
+        self.assertEqual( len( info_list ), len( ID_LIST ) )
+
+        ids = [ x[ 'id' ] for x in info_list ]
+
+        for id in ID_LIST:
+            self.failUnless( id in ids )
+
+    def test_getGroupsForPrincipal_optional_prefix( self ):
+
+        dpg = self._makeOne( 'ggp_prefixed' )
+        dpg.prefix = 'ggp_'
+
+        principal = FauxPrincipal( 'faux' )
+
+        dpg.addGroup( 'effable', 'python:principal.getId().startswith("f")' )
+        groups = dpg.getGroupsForPrincipal( principal, {} )
+        self.assertEqual( len( groups ), 1 )
+        self.failUnless( 'ggp_effable' in groups )
+
 if __name__ == "__main__":
     unittest.main()
-        
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite( DynamicGroupsPlugin ),
         ))
-        
\ No newline at end of file



More information about the Zope-CVS mailing list