[Zope-CVS] CVS: Products/PluggableAuthService/plugins/tests - test_ZODBRoleManager.py:1.4

Zachery Bir zbir at urbanape.com
Mon Aug 30 11:30:12 EDT 2004


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

Modified Files:
	test_ZODBRoleManager.py 
Log Message:
  - Moved some of the dummy classes to the helpers module

  - Test the new behavior that will allow for principals no longer in
    the system to be displayed as "<foo: not found>" rather than raise
    exceptions.


=== Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py 1.3 => 1.4 ===
--- Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py:1.3	Thu Aug 12 11:15:55 2004
+++ Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py	Mon Aug 30 11:30:11 2004
@@ -21,25 +21,8 @@
 from Products.PluggableAuthService.tests.conformance \
     import IRoleAssignerPlugin_conformance
 
-from Products.PluggableAuthService.tests.test_PluggableAuthService \
-    import FauxContainer
-
-class FauxPAS( FauxContainer ):
-
-    def __init__( self ):
-        self._id = 'acl_users'
-        
-    def searchPrincipals( self, **kw ):
-        id = kw.get( 'id' )
-        return [ { 'id': id } ]
-
-class DummyUser:
-
-    def __init__( self, id ):
-        self._id = id
-
-    def getId( self ):
-        return self._id
+from Products.PluggableAuthService.plugins.tests.helpers \
+     import FauxPAS, FauxSmartPAS, DummyUser
 
 class ZODBRoleManagerTests( unittest.TestCase
                           , IRolesPlugin_conformance
@@ -264,7 +247,7 @@
                          , () )
 
     def test_assignRoleToPrincipal_nonesuch( self ):
-        
+
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
             import FauxRoot
 
@@ -274,7 +257,7 @@
         self.assertRaises( KeyError, zrm.assignRoleToPrincipal, 'test', 'foo' )
 
     def test_assignRoleToPrincipal_user( self ):
-        
+
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
             import FauxRoot
 
@@ -301,7 +284,7 @@
         self.failUnless( 'test2' in roles )
 
     def test_assignRoleToPrincipal_new( self ):
-        
+
         root = FauxPAS()
         zrm = self._makeOne( id='assign_new' ).__of__( root )
 
@@ -318,7 +301,7 @@
         self.assertEqual( assigned[0], 'foo' )
 
     def test_assignRoleToPrincipal_already( self ):
-        
+
         root = FauxPAS()
         zrm = self._makeOne( id='assign_already' ).__of__( root )
 
@@ -334,8 +317,34 @@
         self.assertEqual( len( assigned ), 1 )
         self.assertEqual( assigned[0], 'foo' )
 
+    def test_assignRoleBeforeRemovingPrincipal( self ):
+
+        root = FauxSmartPAS()
+        root.user_ids['foo'] = 'foo'
+
+        zrm = self._makeOne( id='assign_before_remove' ).__of__( root )
+
+        zrm.addRole( 'test' )
+        self.assertEqual( len( zrm.listAssignedPrincipals( 'test' ) ), 0 )
+
+        new = zrm.assignRoleToPrincipal( 'test', 'foo' )
+
+        self.failUnless( new )
+
+        assigned = [x[1] for x in zrm.listAssignedPrincipals( 'test' )]
+
+        self.assertEqual( len( assigned ), 1 )
+        self.assertEqual( assigned[0], 'foo' )
+
+        del root.user_ids['foo']
+
+        assigned = [x[1] for x in zrm.listAssignedPrincipals( 'test' )]
+
+        self.assertEqual( len( assigned ), 1 )
+        self.assertEqual( assigned[0], '<foo: not found>' )
+
     def test_removeRoleFromPrincipal_nonesuch( self ):
-        
+
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
             import FauxRoot
 
@@ -346,7 +355,7 @@
                          , 'test', 'foo' )
 
     def test_removeRoleFromPrincipal_existing( self ):
-        
+
         root = FauxPAS()
         zrm = self._makeOne( id='remove_existing' ).__of__( root )
 
@@ -373,7 +382,7 @@
         self.failUnless( 'baz' in assigned )
 
     def test_removeRoleFromPrincipal_noop( self ):
-        
+
         root = FauxPAS()
         zrm = self._makeOne( id='remove_noop' ).__of__( root )
 
@@ -390,7 +399,7 @@
         removed = zrm.removeRoleFromPrincipal( 'test', 'bar' )
 
         self.failIf( removed )
-        
+
     def test_updateRole_nonesuch( self ):
 
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
@@ -425,7 +434,7 @@
         self.assertEqual( info[ 'description' ], 'Updated description' )
 
     def test_removeRole_then_addRole( self ):
-        
+
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
             import FauxRoot
 



More information about the Zope-CVS mailing list