[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/RoleService/tests - testRoleService.py:1.1.2.3

Gary Poster garyposter@earthlink.net
Mon, 22 Apr 2002 15:03:51 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/RoleService/tests
In directory cvs.zope.org:/tmp/cvs-serv31509/App/OFS/RoleService/tests

Modified Files:
      Tag: Zope-3x-branch
	testRoleService.py 
Log Message:
1. As per ZopeTop discussion, moved Addable out of ZMI into the Services folder, and turned it into a true service (this involved a lot of small changes, particularly in the folders and a number of tests) and gave it some hooks
2. used SteveA's ContextWrapper.ContextMethod to make the ServiceManager and Services placefully look up to parent placeful equivalents
3. Made Event into a more standard service, and gave it some hooks
4. Built the beginning of a placeful EventService (will need tests, and views, and EventChannels, and more meat; just wanted to check this in for now)
5. made it so you can't add an item to a folder with a blank string id, and updated the folder interface
6. some typos fixed here and there
7. a few more tests here and there

I'm checking this in then checking it out again to check my work; also tagged previous version as gary-service_update.



=== Zope3/lib/python/Zope/App/OFS/RoleService/tests/testRoleService.py 1.1.2.2 => 1.1.2.3 ===
 """
 from unittest import TestCase, TestLoader, TextTestRunner
-from Zope.App.OFS.Container.tests.testIContainer import BaseTestIContainer
-
-from Interface import Interface
-from Zope.App.OFS.Folder.RootFolder import RootFolder
-from Zope.App.OFS.Folder.Folder import Folder
-from Zope.ContextWrapper import Wrapper
-from Zope.App.OFS.RoleService.RoleService import RoleService
 from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-from Zope.ComponentArchitecture import getService
-from Zope.App.Security.RoleRegistry import roleRegistry
+from Interface import Interface
 
 class ITestService(Interface): pass
 
@@ -34,26 +26,73 @@
 
     __implements__ = ITestService
 
-class RoleServiceTests(BaseTestIContainer, CleanUp, TestCase):
+class RoleServiceTests(CleanUp, TestCase):
 
     def _Test__new(self):
         return RoleService()
 
+    def setUp(self):
+        from Zope.App.OFS.ServiceManager.tests.PlacefulSetup \
+	      import PlacefulSetup
+        from Zope.App.Security.IRoleService import IRoleService
+        from Zope.App.Security.RoleRegistry import RoleRegistry
+        self.__sandbox=PlacefulSetup()
+        self.__sandbox.serviceManager.defineService("RoleService", IRoleService)
+        self.roleRegistry=RoleRegistry()
+        self.__sandbox.serviceManager.provideService("RoleService", self.roleRegistry)
+        from Zope.App.OFS.ServiceManager.ServiceManager import ServiceManager
+        self.__sandbox.rootFolder.setServiceManager(ServiceManager())
+        self.sm=self.__sandbox.rootFolder.getServiceManager()
+        from Zope.App.OFS.RoleService.RoleService import RoleService
+        self.rs = RoleService()
+        self.sm.setObject("myRoleService", self.rs)
+        self.sm.bindService("RoleService","myRoleService")
+        
+    def tearDown(self):
+        self.__sandbox.tearDown()
+        
     def testGetRole(self):
-        roleRegistry.defineRole('Manager', 'Manager', '')
+        self.roleRegistry.defineRole('Manager', 'Manager', '')
         
         from Zope.App.OFS.RoleService.Role import Role
-        rs = self._Test__new()
         r = Role()
         r.setId("Hacker")
-        rs.setObject("Hacker", r)
-        self.assertEqual(rs.getRole('Hacker').getId(), 'Hacker')
-        self.assertEqual(rs.getRole('Manager').getId(), 'Manager')
+        self.rs.setObject("Hacker", r)
+        self.assertEqual(self.rs.getRole('Hacker').getId(), 'Hacker')
+        self.assertEqual(self.rs.getRole('Manager').getId(), 'Manager')
 
-        roles = [role.getId() for role in rs.getRoles()]
+        roles = [role.getId() for role in self.rs.getRoles()]
         roles.sort()
 
         self.assertEqual(roles, ['Anonymous', 'Hacker', 'Manager'])
+    
+    def testGetRoleFromLayeredServices(self):
+        self.roleRegistry.defineRole('Manager', 'Manager', '')
+        
+        from Zope.App.OFS.RoleService.Role import Role
+        r = Role()
+        r.setId("Hacker")
+        self.rs.setObject("Hacker", r)
+        from Zope.App.OFS.ServiceManager.ServiceManager import ServiceManager
+        self.__sandbox.folder1.setServiceManager(ServiceManager())
+        self.sm1=self.__sandbox.folder1.getServiceManager()
+        from Zope.App.OFS.RoleService.RoleService import RoleService
+        self.rs1 = RoleService()
+        self.sm1.setObject("myRoleService", self.rs1)
+        self.sm1.bindService("RoleService","myRoleService")
+        self.rs1=self.sm1.getService("RoleService")
+        r1=Role()
+        r1.setId("Reviewer")
+        self.rs1.setObject("Reviewer", r1)
+        self.assertEqual(self.rs1.getRole('Hacker').getId(), 'Hacker')
+        self.assertEqual(self.rs1.getRole('Manager').getId(), 'Manager')
+        self.assertEqual(self.rs1.getRole('Reviewer').getId(), 'Reviewer')
+
+        roles = [role.getId() for role in self.rs1.getRoles()]
+        roles.sort()
+
+        self.assertEqual(roles, ['Anonymous', 'Hacker', 'Manager','Reviewer'])
+        
 
         
 def test_suite():