[Zope-CVS] CVS: Packages3/workflow/tests - workflowsetup.py:1.1 test_service.py:1.2

Ulrich Eck ueck@net-labs.de
Thu, 6 Feb 2003 17:03:09 -0500


Update of /cvs-repository/Packages3/workflow/tests
In directory cvs.zope.org:/tmp/cvs-serv23752/tests

Modified Files:
	test_service.py 
Added Files:
	workflowsetup.py 
Log Message:
Next round in Stateful workflow implementation:
- Transitions:
  + Conditions based on TALES Expressions work
  - Permissions are implemented but tests do not work yet (tests disabled)
- Instance:
  + Relevant-Data based on Schema basically works (schema written as persistent module)
  - Permissions for dataaccess not yet implemented
- BrowserViews:
 - basic setup for ManagementInterface made, no functionality yet
- extensive tests for the instance written.


=== Added File Packages3/workflow/tests/workflowsetup.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
Setup for Placeful Worfklow Tests
Revision information:
$Id: workflowsetup.py,v 1.1 2003/02/06 22:03:07 jack-e Exp $
"""
from zope.app.traversing import traverse
from zope.app.container.zopecontainer import ZopeContainerAdapter
from zope.app.services.service import ServiceManager
from zope.app.services.service import ServiceConfiguration

from zope.component import getService, getServiceManager
from zope.component.servicenames import Roles, Permissions, Adapters
from zope.component.servicenames import Authentication, Workflows

from zope.app.interfaces.security import IAuthenticationService
from zope.app.interfaces.security import IRoleService
from zope.app.interfaces.security import IPermissionService
from zope.app.security.registries.principalregistry \
     import principalRegistry
from zope.app.security.registries.permissionregistry \
     import permissionRegistry

from zope.app.interfaces.dependable import IDependable
from zope.app.services.tests.placefulsetup \
     import PlacefulSetup
from zope.app.interfaces.annotation import IAnnotatable
from zope.app.interfaces.annotation import IAttributeAnnotatable
from zope.app.attributeannotations import AttributeAnnotations
from zope.app.interfaces.annotation import IAnnotations
from zope.app.interfaces.dependable import IDependable
from zope.app.dependable import Dependable
from zope.component.adapter import provideAdapter

from zope.app.interfaces.services.configuration \
     import Active, Unregistered, Registered

from zope.app.workflow.service import WorkflowService




class WorkflowServiceForTests(WorkflowService):

    __implements__ = WorkflowService.__implements__, IAttributeAnnotatable




class WorkflowSetup(PlacefulSetup):

    def setUp(self):
        PlacefulSetup.setUp(self)

        self.root_sm = getServiceManager(None)

        provideAdapter(IAttributeAnnotatable,
                       IAnnotations, AttributeAnnotations)
        provideAdapter(IAnnotatable, IDependable, Dependable)

        # Set up a local workflow service
        self.buildFolders()
        self.rootFolder.setServiceManager(ServiceManager())

        self.sm = traverse(self.rootFolder, '++etc++Services')

        self.default = traverse(self.rootFolder,
                                '++etc++Services/Packages/default')
        self.default.setObject('workflow_srv', WorkflowServiceForTests())
        self.service = traverse(self.default, 'workflow_srv')

        self.cm = ZopeContainerAdapter(traverse(self.default, "configure"))
        self.cm.setObject('', ServiceConfiguration(Workflows,
                                '/++etc++Services/Packages/default/workflow_srv'))
        traverse(self.default, 'configure/1').status = Active

        # Set up a more local workflow service
        folder1 = traverse(self.rootFolder, 'folder1')
        folder1.setServiceManager(ServiceManager())

        self.default1 = traverse(folder1, '++etc++Services/Packages/default')
        self.default1.setObject('workflow_srv1', WorkflowServiceForTests())
        self.service1 = traverse(self.default1, 'workflow_srv1')

        self.cm1 = ZopeContainerAdapter(traverse(self.default1, "configure"))
        self.cm1.setObject('', ServiceConfiguration(Workflows,
                                '/folder1/++etc++Services/Packages/default/workflow_srv1'))
        traverse(self.default1, 'configure/1').status = Active


    def setupAuthService(self):
        self.root_sm.defineService(Authentication, IAuthenticationService)
        self.root_sm.provideService(Authentication, principalRegistry)
        return getService(self.rootFolder, Authentication)


    def setupRoleService(self):
        self.root_sm.defineService(Roles, IRoleService)
        self.root_sm.provideService(Roles, roleRegistry)
        return getService(self.rootFolder, Roles)

    def setupPermissionService(self):
        self.root_sm.defineService(Permissions, IPermissionService)
        self.root_sm.provideService(Permissions, permissionRegistry)
        return getService(self.rootFolder, Permissions)

        


=== Packages3/workflow/tests/test_service.py 1.1 => 1.2 ===
--- Packages3/workflow/tests/test_service.py:1.1	Sun Feb  2 14:21:55 2003
+++ Packages3/workflow/tests/test_service.py	Thu Feb  6 17:03:07 2003
@@ -24,31 +24,17 @@
 
 from zope.app.traversing import traverse
 from zope.app.container.zopecontainer import ZopeContainerAdapter
-from zope.app.services.service import ServiceManager
-from zope.app.services.service import ServiceConfiguration
-from zope.app.interfaces.dependable import IDependable
-from zope.app.services.tests.placefulsetup \
-     import PlacefulSetup
-from zope.app.interfaces.annotation import IAnnotatable
 from zope.app.interfaces.annotation import IAttributeAnnotatable
-from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.interfaces.annotation import IAnnotations
-from zope.app.interfaces.dependable import IDependable
-from zope.app.dependable import Dependable
-from zope.component.adapter import provideAdapter
+
 from zope.app.interfaces.services.configuration \
      import Active, Unregistered, Registered
 
+from zope.app.workflow.tests.workflowsetup import WorkflowSetup
 from zope.app.interfaces.workflow \
      import IWorkflowService, IProcessDefinition
 from zope.app.workflow.service import WorkflowService
 from zope.app.workflow.service import ProcessDefinitionConfiguration
 
-class WorkflowServiceForTests(WorkflowService):
-
-    __implements__ = WorkflowService.__implements__, IAttributeAnnotatable
-
-
 # define and create dummy ProcessDefinition (PD) for tests
 class DummyProcessDefinition:
     __implements__ = IProcessDefinition, IAttributeAnnotatable
@@ -68,29 +54,11 @@
     l.sort()
     return l
 
-class WorkflowServiceTests(PlacefulSetup, unittest.TestCase):
+class WorkflowServiceTests(WorkflowSetup, unittest.TestCase):
 
     def setUp(self):
-        PlacefulSetup.setUp(self)
-
-        provideAdapter(IAttributeAnnotatable,
-                       IAnnotations, AttributeAnnotations)
-        provideAdapter(IAnnotatable, IDependable, Dependable)
-
-        # Set up a local workflow service
-        self.buildFolders()
-        self.rootFolder.setServiceManager(ServiceManager())
-
-        self.default = traverse(self.rootFolder,
-                                '++etc++Services/Packages/default')
-        self.default.setObject('workflow_srv', WorkflowServiceForTests())
-        self.service = traverse(self.default, 'workflow_srv')
-
-        self.cm = ZopeContainerAdapter(traverse(self.default, "configure"))
-        self.cm.setObject('', ServiceConfiguration('Workflows',
-                                '/++etc++Services/Packages/default/workflow_srv'))
-        traverse(self.default, 'configure/1').status = Active
-
+        WorkflowSetup.setUp(self)
+        # setup ProcessDefinitions
         self.default.setObject('pd1', DummyProcessDefinition(1))
         self.default.setObject('pd2', DummyProcessDefinition(2))
 
@@ -106,28 +74,15 @@
         # Now self.service has definition1 and definition2 available
         # and knows about definition3
 
-        # Set up a more local workflow service
-        folder1 = traverse(self.rootFolder, 'folder1')
-        folder1.setServiceManager(ServiceManager())
-
-        default1 = traverse(folder1, '++etc++Services/Packages/default')
-        default1.setObject('workflow_srv1', WorkflowServiceForTests())
-        self.service1 = traverse(default1, 'workflow_srv1')
-
-        cm1 = ZopeContainerAdapter(traverse(default1, "configure"))
-        cm1.setObject('', ServiceConfiguration('Workflows',
-                '/folder1/++etc++Services/Packages/default/workflow_srv1'))
-        traverse(default1, 'configure/1').status = Active
-
-        default1.setObject('pd3', DummyProcessDefinition(3))
-        default1.setObject('pd4', DummyProcessDefinition(4))
+        self.default1.setObject('pd3', DummyProcessDefinition(3))
+        self.default1.setObject('pd4', DummyProcessDefinition(4))
 
-        cm1.setObject('', ProcessDefinitionConfiguration('definition1',
+        self.cm1.setObject('', ProcessDefinitionConfiguration('definition1',
                             '/folder1/++etc++Services/Packages/default/pd3'))
-        traverse(default1, 'configure/2').status = Active
-        cm1.setObject('', ProcessDefinitionConfiguration('definition4',
+        traverse(self.default1, 'configure/2').status = Active
+        self.cm1.setObject('', ProcessDefinitionConfiguration('definition4',
                             '/folder1/++etc++Services/Packages/default/pd4'))
-        traverse(default1, 'configure/3').status = Active
+        traverse(self.default1, 'configure/3').status = Active
         # Now self.service1 overrides definition1, adds new definition4 available,
         # and inherits definition2 from self.service