[CMF-checkins] SVN: CMF/trunk/CMF - moved actions tool setup
handlers to CMFCore
Yvo Schubbe
y.2005- at wcm-solutions.de
Fri Nov 25 06:24:29 EST 2005
Log message for revision 40365:
- moved actions tool setup handlers to CMFCore
Changed:
U CMF/trunk/CMFCore/exportimport/actions.py
U CMF/trunk/CMFCore/exportimport/configure.zcml
U CMF/trunk/CMFCore/exportimport/tests/test_actions.py
U CMF/trunk/CMFCore/exportimport/tests/test_workflow.py
U CMF/trunk/CMFCore/exportimport/workflow.py
U CMF/trunk/CMFDefault/profiles/default/export_steps.xml
U CMF/trunk/CMFDefault/profiles/default/import_steps.xml
U CMF/trunk/CMFSetup/actions.py
D CMF/trunk/CMFSetup/tests/test_actions.py
-=-
Modified: CMF/trunk/CMFCore/exportimport/actions.py
===================================================================
--- CMF/trunk/CMFCore/exportimport/actions.py 2005-11-24 18:23:00 UTC (rev 40364)
+++ CMF/trunk/CMFCore/exportimport/actions.py 2005-11-25 11:24:29 UTC (rev 40365)
@@ -15,11 +15,15 @@
$Id$
"""
+from zope.app import zapi
+
+from Products.GenericSetup.interfaces import IBody
from Products.GenericSetup.interfaces import PURGE, UPDATE
from Products.GenericSetup.utils import I18NURI
from Products.GenericSetup.utils import NodeAdapterBase
from Products.GenericSetup.utils import ObjectManagerHelpers
from Products.GenericSetup.utils import PropertyManagerHelpers
+from Products.GenericSetup.utils import XMLAdapterBase
from Products.CMFCore.interfaces import IAction
from Products.CMFCore.interfaces import IActionCategory
@@ -29,6 +33,7 @@
import ActionProvider as z2IActionProvider
from Products.CMFCore.utils import getToolByName
+_FILENAME = 'actions.xml'
_SPECIAL_PROVIDERS = ('portal_actions', 'portal_types', 'portal_workflow')
@@ -84,13 +89,15 @@
self._initProperties(node, mode)
-class ActionsToolNodeAdapter(NodeAdapterBase, ObjectManagerHelpers):
+class ActionsToolXMLAdapter(XMLAdapterBase, ObjectManagerHelpers):
- """Node im- and exporter for ActionsTool.
+ """XML im- and exporter for ActionsTool.
"""
__used_for__ = IActionsTool
+ _LOGGER_ID = 'actions'
+
def exportNode(self, doc):
"""Export the object as a DOM node.
"""
@@ -99,6 +106,8 @@
node.setAttribute('xmlns:i18n', I18NURI)
node.appendChild(self._extractProviders())
node.appendChild(self._extractObjects())
+
+ self._logger.info('Actions tool exported.')
return node
def importNode(self, node, mode=PURGE):
@@ -111,6 +120,8 @@
self._initObjects(node, mode)
self._initProviders(node, mode)
+ self._logger.info('Actions tool imported.')
+
def _extractProviders(self):
fragment = self._doc.createDocumentFragment()
for provider_id in self.context.listActionProviders():
@@ -222,3 +233,40 @@
parent.appendChild(newnode)
self._initObjects(fragment, UPDATE)
+
+
+def importActionProviders(context):
+ """Import actions tool.
+ """
+ site = context.getSite()
+ logger = context.getLogger('actions')
+ tool = getToolByName(site, 'portal_actions')
+
+ body = context.readDataFile(_FILENAME)
+ if body is None:
+ logger.info('Nothing to import.')
+ return
+
+ importer = zapi.queryMultiAdapter((tool, context), IBody)
+ if importer is None:
+ logger.warning('Import adapter misssing.')
+ return
+
+ importer.body = body
+
+def exportActionProviders(context):
+ """Export actions tool.
+ """
+ site = context.getSite()
+ logger = context.getLogger('actions')
+ tool = getToolByName(site, 'portal_actions', None)
+ if tool is None:
+ logger.info('Nothing to export.')
+ return
+
+ exporter = zapi.queryMultiAdapter((tool, context), IBody)
+ if exporter is None:
+ logger.warning('Export adapter misssing.')
+ return
+
+ context.writeDataFile(_FILENAME, exporter.body, exporter.mime_type)
Modified: CMF/trunk/CMFCore/exportimport/configure.zcml
===================================================================
--- CMF/trunk/CMFCore/exportimport/configure.zcml 2005-11-24 18:23:00 UTC (rev 40364)
+++ CMF/trunk/CMFCore/exportimport/configure.zcml 2005-11-25 11:24:29 UTC (rev 40365)
@@ -27,18 +27,13 @@
/>
<adapter
- factory=".actions.ActionsToolNodeAdapter"
- provides="Products.GenericSetup.interfaces.INodeExporter"
- for="Products.CMFCore.interfaces.IActionsTool"
+ factory=".actions.ActionsToolXMLAdapter"
+ provides="Products.GenericSetup.interfaces.IBody"
+ for="Products.CMFCore.interfaces.IActionsTool
+ Products.GenericSetup.interfaces.ISetupContext"
/>
<adapter
- factory=".actions.ActionsToolNodeAdapter"
- provides="Products.GenericSetup.interfaces.INodeImporter"
- for="Products.CMFCore.interfaces.IActionsTool"
- />
-
- <adapter
factory=".cachingpolicymgr.CachingPolicyNodeAdapter"
provides="Products.GenericSetup.interfaces.INodeExporter"
for="Products.CMFCore.interfaces.ICachingPolicy"
Modified: CMF/trunk/CMFCore/exportimport/tests/test_actions.py
===================================================================
--- CMF/trunk/CMFCore/exportimport/tests/test_actions.py 2005-11-24 18:23:00 UTC (rev 40364)
+++ CMF/trunk/CMFCore/exportimport/tests/test_actions.py 2005-11-25 11:24:29 UTC (rev 40365)
@@ -20,9 +20,25 @@
import Zope2
Zope2.startup()
+import Products
+from Acquisition import Implicit
+from Acquisition import aq_parent
+from OFS.Folder import Folder
+from OFS.OrderedFolder import OrderedFolder
+from Products.Five import zcml
+from zope.interface import implements
+
+from Products.CMFCore.ActionProviderBase import ActionProviderBase
+from Products.CMFCore.interfaces import IActionsTool
+from Products.CMFCore.interfaces.portal_actions \
+ import ActionProvider as IActionProvider
from Products.CMFCore.tests.base.dummy import DummySite
from Products.CMFCore.tests.base.testcase import PlacelessSetup
+from Products.GenericSetup.testing import BodyAdapterTestCase
from Products.GenericSetup.testing import NodeAdapterTestCase
+from Products.GenericSetup.tests.common import BaseRegistryTests
+from Products.GenericSetup.tests.common import DummyExportContext
+from Products.GenericSetup.tests.common import DummyImportContext
_ACTION_XML = """\
@@ -52,7 +68,8 @@
</object>
"""
-_ACTIONSTOOL_XML = """\
+_ACTIONSTOOL_BODY = """\
+<?xml version="1.0"?>
<object name="portal_actions" meta_type="CMF Actions Tool"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<action-provider name="portal_actions"/>
@@ -71,7 +88,164 @@
</object>
"""
+_EMPTY_EXPORT = """\
+<?xml version="1.0"?>
+<object meta_type="CMF Actions Tool" name="portal_actions" \
+xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+ <action-provider name="portal_actions"/>
+</object>
+"""
+_NORMAL_EXPORT = """\
+<?xml version="1.0"?>
+<object meta_type="CMF Actions Tool" name="portal_actions" \
+xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+ <action-provider name="portal_actions"/>
+ <action-provider name="portal_foo">
+ <action action_id="foo"
+ title="Foo"
+ url_expr="string:${object_url}/foo"
+ condition_expr="python:1"
+ category="dummy"
+ visible="True"/>
+ </action-provider>
+ <action-provider name="portal_bar">
+ <action action_id="bar"
+ title="Bar"
+ url_expr="string:${object_url}/bar"
+ condition_expr="python:0"
+ category="dummy"
+ visible="False">
+ <permission>Manage portal</permission>
+ </action>
+ </action-provider>
+</object>
+"""
+
+_NEWSYTLE_EXPORT = """\
+<?xml version="1.0"?>
+<object meta_type="CMF Actions Tool" name="portal_actions" \
+xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+ <action-provider name="portal_actions"/>
+ <object name="dummy" meta_type="CMF Action Category">
+ <property name="title"></property>
+ <object name="foo" meta_type="CMF Action">
+ <property name="title">Foo</property>
+ <property name="description"></property>
+ <property name="url_expr">string:${object_url}/foo</property>
+ <property name="icon_expr"></property>
+ <property name="available_expr">python:1</property>
+ <property name="permissions"></property>
+ <property name="visible">True</property>
+ </object>
+ <object name="bar" meta_type="CMF Action">
+ <property name="title">Bar</property>
+ <property name="description"></property>
+ <property name="url_expr">string:${object_url}/bar</property>
+ <property name="icon_expr"></property>
+ <property name="available_expr">python:0</property>
+ <property name="permissions">
+ <element value="Manage portal"/>
+ </property>
+ <property name="visible">False</property>
+ </object>
+ </object>
+</object>
+"""
+
+_I18N_IMPORT = """\
+<?xml version="1.0"?>
+<object meta_type="CMF Actions Tool" name="portal_actions" \
+xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+ <action-provider name="portal_actions"/>
+ <object name="dummy" meta_type="CMF Action Category">
+ <property name="title"></property>
+ <object name="foo" meta_type="CMF Action" i18n:domain="foo_domain">
+ <property name="title" i18n:translate="">Foo</property>
+ <property name="description" i18n:translate=""></property>
+ <property name="url_expr">string:${object_url}/foo</property>
+ <property name="icon_expr"></property>
+ <property name="available_expr">python:1</property>
+ <property name="permissions"></property>
+ <property name="visible">True</property>
+ </object>
+ </object>
+</object>
+"""
+
+_INSERT_IMPORT = """\
+<?xml version="1.0"?>
+<actions-tool xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+ <object name="dummy">
+ <object name="spam" meta_type="CMF Action" insert-before="*">
+ <property name="title">Spam</property>
+ <property name="description"></property>
+ <property name="url_expr">string:${object_url}/spam</property>
+ <property name="icon_expr">string:spam_icon.png</property>
+ <property name="available_expr"></property>
+ <property name="permissions">
+ <element value="View" /></property>
+ <property name="visible">True</property>
+ </object>
+ <object name="foo" insert-after="*">
+ <property name="icon_expr">string:foo_icon.png</property>
+ </object>
+ </object>
+</actions-tool>
+"""
+
+_REMOVE_IMPORT = """\
+<?xml version="1.0"?>
+<actions-tool xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+ <action-provider id="portal_actions" remove="">
+ </action-provider>
+ <action-provider id="not_existing" remove="">
+ </action-provider>
+ <action-provider id="portal_bar" remove="">
+ </action-provider>
+</actions-tool>
+"""
+
+
+class DummyTool(OrderedFolder, ActionProviderBase):
+
+ __implements__ = IActionProvider
+
+
+class DummyUser(Implicit):
+
+ def getId(self):
+ return 'dummy'
+
+
+class DummyMembershipTool(DummyTool):
+
+ def isAnonymousUser(self):
+ return False
+
+ def getAuthenticatedMember(self):
+ return DummyUser().__of__(aq_parent(self))
+
+
+class DummyActionsTool(DummyTool):
+
+ implements(IActionsTool)
+ id = 'portal_actions'
+ meta_type = 'CMF Actions Tool'
+
+ def __init__(self):
+ self._providers = []
+
+ def addActionProvider(self, provider_name):
+ self._providers.append(provider_name)
+
+ def listActionProviders(self):
+ return self._providers[:]
+
+ def deleteActionProvider(self, provider_name):
+ self._providers = [ x for x in self._providers if x != provider_name ]
+
+
class ActionNodeAdapterTests(PlacelessSetup, NodeAdapterTestCase):
def _getTargetClass(self):
@@ -145,13 +319,13 @@
self._XML = _ACTIONCATEGORY_XML
-class ActionsToolNodeAdapterTests(PlacelessSetup, NodeAdapterTestCase):
+class ActionsToolXMLAdapterTests(BodyAdapterTestCase):
def _getTargetClass(self):
from Products.CMFCore.exportimport.actions \
- import ActionsToolNodeAdapter
+ import ActionsToolXMLAdapter
- return ActionsToolNodeAdapter
+ return ActionsToolXMLAdapter
def _populate(self, obj):
from Products.CMFCore.ActionInformation import Action
@@ -169,26 +343,282 @@
self.assertEqual(obj.action_providers[0], 'portal_actions')
def setUp(self):
+ import Products.CMFCore.exportimport
from Products.CMFCore.ActionsTool import ActionsTool
- import Products.CMFCore.exportimport
- import Products.Five
- from Products.Five import zcml
- PlacelessSetup.setUp(self)
- zcml.load_config('meta.zcml', Products.Five)
+ BodyAdapterTestCase.setUp(self)
zcml.load_config('configure.zcml', Products.CMFCore.exportimport)
site = DummySite('site')
site._setObject('portal_actions', ActionsTool('portal_actions'))
self._obj = site.portal_actions
- self._XML = _ACTIONSTOOL_XML
+ self._BODY = _ACTIONSTOOL_BODY
+class _ActionSetup(PlacelessSetup, BaseRegistryTests):
+
+ def _initSite(self, foo=2, bar=2):
+ self.root.site = Folder(id='site')
+ site = self.root.site
+ site.portal_membership = DummyMembershipTool()
+
+ site.portal_actions = DummyActionsTool()
+ site.portal_actions.addActionProvider('portal_actions')
+
+ if foo > 0:
+ site.portal_foo = DummyTool()
+
+ if foo > 1:
+ site.portal_foo.addAction(id='foo',
+ name='Foo',
+ action='foo',
+ condition='python:1',
+ permission=(),
+ category='dummy',
+ visible=1)
+ site.portal_actions.addActionProvider('portal_foo')
+
+ if bar > 0:
+ site.portal_bar = DummyTool()
+
+ if bar > 1:
+ site.portal_bar.addAction(id='bar',
+ name='Bar',
+ action='bar',
+ condition='python:0',
+ permission=('Manage portal',),
+ category='dummy',
+ visible=0)
+ site.portal_actions.addActionProvider('portal_bar')
+
+ return site
+
+ def setUp(self):
+ PlacelessSetup.setUp(self)
+ BaseRegistryTests.setUp(self)
+ zcml.load_config('meta.zcml', Products.Five)
+ zcml.load_config('configure.zcml', Products.CMFCore.exportimport)
+
+ def tearDown(self):
+ BaseRegistryTests.tearDown(self)
+ PlacelessSetup.tearDown(self)
+
+
+class exportActionProvidersTests(_ActionSetup):
+
+ def test_unchanged(self):
+ from Products.CMFCore.exportimport.actions \
+ import exportActionProviders
+
+ site = self._initSite(0, 0)
+ context = DummyExportContext(site)
+ exportActionProviders(context)
+
+ self.assertEqual(len(context._wrote), 1)
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'actions.xml')
+ self._compareDOM(text, _EMPTY_EXPORT)
+ self.assertEqual(content_type, 'text/xml')
+
+ def test_normal(self):
+ from Products.CMFCore.exportimport.actions \
+ import exportActionProviders
+
+ site = self._initSite()
+
+ context = DummyExportContext(site)
+ exportActionProviders(context)
+
+ self.assertEqual(len(context._wrote), 1)
+
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'actions.xml')
+ self._compareDOM(text, _NORMAL_EXPORT)
+ self.assertEqual(content_type, 'text/xml')
+
+
+class importActionProvidersTests(_ActionSetup):
+
+ def test_empty_default_purge(self):
+ from Products.CMFCore.exportimport.actions \
+ import importActionProviders
+
+ site = self._initSite(2, 0)
+ atool = site.portal_actions
+
+ self.assertEqual(len(atool.listActionProviders()), 2)
+ self.failUnless('portal_foo' in atool.listActionProviders())
+ self.failUnless('portal_actions' in atool.listActionProviders())
+
+ context = DummyImportContext(site)
+ context._files['actions.xml'] = _EMPTY_EXPORT
+ importActionProviders(context)
+
+ self.assertEqual(len(atool.listActionProviders()), 1)
+ self.failIf('portal_foo' in atool.listActionProviders())
+ self.failUnless('portal_actions' in atool.listActionProviders())
+ self.assertEqual(len(atool.objectIds()), 0)
+
+ def test_empty_explicit_purge(self):
+ from Products.CMFCore.exportimport.actions \
+ import importActionProviders
+
+ site = self._initSite(2, 0)
+ atool = site.portal_actions
+
+ self.assertEqual(len(atool.listActionProviders()), 2)
+ self.failUnless('portal_foo' in atool.listActionProviders())
+ self.failUnless('portal_actions' in atool.listActionProviders())
+
+ context = DummyImportContext(site, True)
+ context._files['actions.xml'] = _EMPTY_EXPORT
+ importActionProviders(context)
+
+ self.assertEqual(len(atool.listActionProviders()), 1)
+ self.failIf('portal_foo' in atool.listActionProviders())
+ self.failUnless('portal_actions' in atool.listActionProviders())
+ self.assertEqual(len(atool.objectIds()), 0)
+
+ def test_empty_skip_purge(self):
+ from Products.CMFCore.exportimport.actions \
+ import importActionProviders
+
+ site = self._initSite(2, 0)
+ atool = site.portal_actions
+
+ self.assertEqual(len(atool.listActionProviders()), 2)
+ self.failUnless('portal_foo' in atool.listActionProviders())
+ self.failUnless('portal_actions' in atool.listActionProviders())
+
+ context = DummyImportContext(site, False)
+ context._files['actions.xml'] = _EMPTY_EXPORT
+ importActionProviders(context)
+
+ self.assertEqual(len(atool.listActionProviders()), 2)
+ self.failUnless('portal_foo' in atool.listActionProviders())
+ self.failUnless('portal_actions' in atool.listActionProviders())
+
+ def test_normal(self):
+ from Products.CMFCore.exportimport.actions \
+ import exportActionProviders
+ from Products.CMFCore.exportimport.actions \
+ import importActionProviders
+
+ site = self._initSite(1, 1)
+ atool = site.portal_actions
+ foo = site.portal_foo
+ bar = site.portal_bar
+
+ self.assertEqual(len(atool.listActionProviders()), 1)
+ self.failIf('portal_foo' in atool.listActionProviders())
+ self.failIf(foo.listActions())
+ self.failIf('portal_bar' in atool.listActionProviders())
+ self.failIf(bar.listActions())
+ self.failUnless('portal_actions' in atool.listActionProviders())
+
+ context = DummyImportContext(site)
+ context._files['actions.xml'] = _NORMAL_EXPORT
+ importActionProviders(context)
+
+ self.assertEqual(len(atool.listActionProviders()), 1)
+ self.failIf('portal_foo' in atool.listActionProviders())
+ self.failUnless('portal_actions' in atool.listActionProviders())
+
+ self.assertEqual(len(atool.objectIds()), 1)
+ self.failUnless('dummy' in atool.objectIds())
+ self.assertEqual(len(atool.dummy.objectIds()) , 2)
+ self.failUnless('foo' in atool.dummy.objectIds())
+ self.failUnless('bar' in atool.dummy.objectIds())
+ self.failIf(foo.listActions())
+ self.failIf(bar.listActions())
+
+ # complete the roundtrip
+ context = DummyExportContext(site)
+ exportActionProviders(context)
+
+ self.assertEqual(len(context._wrote), 1)
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'actions.xml')
+ self._compareDOM(text, _NEWSYTLE_EXPORT)
+ self.assertEqual(content_type, 'text/xml')
+
+ def test_i18n(self):
+ from Products.CMFCore.exportimport.actions \
+ import exportActionProviders
+ from Products.CMFCore.exportimport.actions \
+ import importActionProviders
+
+ site = self._initSite(0, 0)
+ atool = site.portal_actions
+
+ context = DummyImportContext(site)
+ context._files['actions.xml'] = _I18N_IMPORT
+ importActionProviders(context)
+
+ self.assertEqual(len(atool.listActionProviders()), 1)
+ self.assertEqual(atool.objectIds(), ['dummy'])
+ self.assertEqual(atool.dummy.objectIds(), ['foo'])
+ self.assertEqual(atool.dummy.foo.i18n_domain, 'foo_domain')
+
+ # complete the roundtrip
+ context = DummyExportContext(site)
+ exportActionProviders(context)
+
+ self.assertEqual(len(context._wrote), 1)
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'actions.xml')
+ self._compareDOM(text, _I18N_IMPORT)
+ self.assertEqual(content_type, 'text/xml')
+
+ def test_insert_skip_purge(self):
+ from Products.CMFCore.exportimport.actions \
+ import importActionProviders
+
+ site = self._initSite(0, 0)
+ atool = site.portal_actions
+
+ context = DummyImportContext(site)
+ context._files['actions.xml'] = _NEWSYTLE_EXPORT
+ importActionProviders(context)
+
+ self.assertEqual(len(atool.listActionProviders()), 1)
+ self.assertEqual(atool.objectIds(), ['dummy'])
+ self.assertEqual(atool.dummy.objectIds(), ['foo', 'bar'])
+ self.assertEqual(atool.dummy.foo.icon_expr, '')
+
+ context = DummyImportContext(site, False)
+ context._files['actions.xml'] = _INSERT_IMPORT
+ importActionProviders(context)
+
+ self.assertEqual(len(atool.listActionProviders()), 1)
+ self.assertEqual(atool.objectIds(), ['dummy'])
+ self.assertEqual(atool.dummy.objectIds(), ['spam', 'bar', 'foo'])
+ self.assertEqual(atool.dummy.foo.icon_expr, 'string:foo_icon.png')
+
+ def test_remove_skip_purge(self):
+ from Products.CMFCore.exportimport.actions \
+ import importActionProviders
+
+ site = self._initSite(2, 2)
+ atool = site.portal_actions
+
+ self.assertEqual(atool.listActionProviders(),
+ ['portal_actions', 'portal_foo', 'portal_bar'])
+
+ context = DummyImportContext(site, False)
+ context._files['actions.xml'] = _REMOVE_IMPORT
+ importActionProviders(context)
+
+ self.assertEqual(atool.listActionProviders(), ['portal_foo'])
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ActionNodeAdapterTests),
unittest.makeSuite(ActionCategoryNodeAdapterTests),
- unittest.makeSuite(ActionsToolNodeAdapterTests),
+ unittest.makeSuite(ActionsToolXMLAdapterTests),
+ unittest.makeSuite(exportActionProvidersTests),
+ unittest.makeSuite(importActionProvidersTests),
))
if __name__ == '__main__':
Modified: CMF/trunk/CMFCore/exportimport/tests/test_workflow.py
===================================================================
--- CMF/trunk/CMFCore/exportimport/tests/test_workflow.py 2005-11-24 18:23:00 UTC (rev 40364)
+++ CMF/trunk/CMFCore/exportimport/tests/test_workflow.py 2005-11-25 11:24:29 UTC (rev 40365)
@@ -219,6 +219,7 @@
BaseRegistryTests.tearDown(self)
PlacelessSetup.tearDown(self)
+
class exportWorkflowToolTests(_WorkflowSetup):
def test_empty(self):
@@ -283,7 +284,6 @@
context = DummyImportContext(site)
context._files['workflows.xml'] = self._EMPTY_TOOL_EXPORT
-
importWorkflowTool(context)
self.assertEqual(len(wf_tool.objectIds()), 0)
Modified: CMF/trunk/CMFCore/exportimport/workflow.py
===================================================================
--- CMF/trunk/CMFCore/exportimport/workflow.py 2005-11-24 18:23:00 UTC (rev 40364)
+++ CMF/trunk/CMFCore/exportimport/workflow.py 2005-11-25 11:24:29 UTC (rev 40365)
@@ -29,14 +29,13 @@
from Products.CMFCore.interfaces import IWorkflowTool
from Products.CMFCore.utils import getToolByName
-
_FILENAME = 'workflows.xml'
class WorkflowToolXMLAdapter(XMLAdapterBase, ObjectManagerHelpers,
PropertyManagerHelpers):
- """Node im- and exporter for WorkflowTool.
+ """XML im- and exporter for WorkflowTool.
"""
__used_for__ = IWorkflowTool
Modified: CMF/trunk/CMFDefault/profiles/default/export_steps.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/default/export_steps.xml 2005-11-24 18:23:00 UTC (rev 40364)
+++ CMF/trunk/CMFDefault/profiles/default/export_steps.xml 2005-11-25 11:24:29 UTC (rev 40365)
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<export-steps>
<export-step id="actions"
- handler="Products.CMFSetup.actions.exportActionProviders"
+ handler="Products.CMFCore.exportimport.actions.exportActionProviders"
title="Action Providers">
Export actions tool's action providers and their actions.
</export-step>
Modified: CMF/trunk/CMFDefault/profiles/default/import_steps.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/default/import_steps.xml 2005-11-24 18:23:00 UTC (rev 40364)
+++ CMF/trunk/CMFDefault/profiles/default/import_steps.xml 2005-11-25 11:24:29 UTC (rev 40365)
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<import-steps>
<import-step id="actions" version="20040630-01"
- handler="Products.CMFSetup.actions.importActionProviders"
+ handler="Products.CMFCore.exportimport.actions.importActionProviders"
title="Action Providers">
<dependency step="toolset"/>
Import actions tool's action providers and their actions.
Modified: CMF/trunk/CMFSetup/actions.py
===================================================================
--- CMF/trunk/CMFSetup/actions.py 2005-11-24 18:23:00 UTC (rev 40364)
+++ CMF/trunk/CMFSetup/actions.py 2005-11-25 11:24:29 UTC (rev 40365)
@@ -15,49 +15,5 @@
$Id$
"""
-from xml.dom.minidom import parseString
-
-from Products.CMFCore.utils import getToolByName
-from Products.GenericSetup.interfaces import INodeExporter
-from Products.GenericSetup.interfaces import INodeImporter
-from Products.GenericSetup.interfaces import PURGE, UPDATE
-from Products.GenericSetup.utils import PrettyDocument
-
-_FILENAME = 'actions.xml'
-
-
-def importActionProviders(context):
- """ Import actions tool.
- """
- site = context.getSite()
- mode = context.shouldPurge() and PURGE or UPDATE
- atool = getToolByName(site, 'portal_actions')
-
- body = context.readDataFile(_FILENAME)
- if body is None:
- return 'Actions tool: Nothing to import.'
-
- importer = INodeImporter(atool, None)
- if importer is None:
- return 'Actions tool: Import adapter misssing.'
-
- importer.importNode(parseString(body).documentElement, mode=mode)
- return 'Actions tool imported.'
-
-def exportActionProviders(context):
- """ Export actions tool.
- """
- site = context.getSite()
-
- atool = getToolByName(site, 'portal_actions', None)
- if atool is None:
- return 'Actions tool: Nothing to export.'
-
- exporter = INodeExporter(atool)
- if exporter is None:
- return 'Actions tool: Export adapter misssing.'
-
- doc = PrettyDocument()
- doc.appendChild(exporter.exportNode(doc))
- context.writeDataFile(_FILENAME, doc.toprettyxml(' '), 'text/xml')
- return 'Actions tool exported.'
+from Products.CMFCore.exportimport.actions import exportActionProviders
+from Products.CMFCore.exportimport.actions import importActionProviders
Deleted: CMF/trunk/CMFSetup/tests/test_actions.py
===================================================================
--- CMF/trunk/CMFSetup/tests/test_actions.py 2005-11-24 18:23:00 UTC (rev 40364)
+++ CMF/trunk/CMFSetup/tests/test_actions.py 2005-11-25 11:24:29 UTC (rev 40365)
@@ -1,488 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors. All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-""" CMFSetup action provider export / import unit tests
-
-$Id$
-"""
-
-import unittest
-import Testing
-import Zope2
-Zope2.startup()
-
-import Products
-from Acquisition import Implicit
-from Acquisition import aq_parent
-from OFS.Folder import Folder
-from OFS.OrderedFolder import OrderedFolder
-from Products.Five import zcml
-from zope.interface import implements
-
-from Products.CMFCore.ActionProviderBase import ActionProviderBase
-from Products.CMFCore.interfaces.portal_actions \
- import ActionProvider as IActionProvider
-from Products.CMFCore.interfaces import IActionsTool
-from Products.CMFCore.tests.base.testcase import PlacelessSetup
-from Products.GenericSetup.tests.common import BaseRegistryTests
-from Products.GenericSetup.tests.common import DummyExportContext
-from Products.GenericSetup.tests.common import DummyImportContext
-
-
-class DummyTool( OrderedFolder, ActionProviderBase ):
-
- __implements__ = ( IActionProvider, )
-
-
-class DummyUser( Implicit ):
-
- def getId( self ):
- return 'dummy'
-
-class DummyMembershipTool( DummyTool ):
-
- def isAnonymousUser( self ):
- return False
-
- def getAuthenticatedMember( self ):
- return DummyUser().__of__( aq_parent( self ) )
-
-class DummyActionsTool( DummyTool ):
-
- implements(IActionsTool)
- id = 'portal_actions'
- meta_type = 'CMF Actions Tool'
-
- def __init__( self ):
-
- self._providers = []
-
- def addActionProvider( self, provider_name ):
-
- self._providers.append( provider_name )
-
- def listActionProviders( self ):
-
- return self._providers[:]
-
- def deleteActionProvider( self, provider_name ):
-
- self._providers = [ x for x in self._providers if x != provider_name ]
-
-class _ActionSetup(PlacelessSetup, BaseRegistryTests):
-
- def _initSite( self, foo=2, bar=2 ):
- self.root.site = Folder(id='site')
- site = self.root.site
-
- site.portal_membership = DummyMembershipTool()
-
- site.portal_actions = DummyActionsTool()
- site.portal_actions.addActionProvider( 'portal_actions' )
-
- if foo > 0:
- site.portal_foo = DummyTool()
-
- if foo > 1:
- site.portal_foo.addAction( id='foo'
- , name='Foo'
- , action='foo'
- , condition='python:1'
- , permission=()
- , category='dummy'
- , visible=1
- )
- site.portal_actions.addActionProvider( 'portal_foo' )
-
- if bar > 0:
- site.portal_bar = DummyTool()
-
- if bar > 1:
- site.portal_bar.addAction( id='bar'
- , name='Bar'
- , action='bar'
- , condition='python:0'
- , permission=( 'Manage portal', )
- , category='dummy'
- , visible=0
- )
- site.portal_actions.addActionProvider( 'portal_bar' )
-
- return site
-
- def setUp(self):
- PlacelessSetup.setUp(self)
- BaseRegistryTests.setUp(self)
- zcml.load_config('meta.zcml', Products.Five)
- zcml.load_config('configure.zcml', Products.CMFCore.exportimport)
-
- def tearDown(self):
- BaseRegistryTests.tearDown(self)
- PlacelessSetup.tearDown(self)
-
-_EMPTY_EXPORT = """\
-<?xml version="1.0"?>
-<object meta_type="CMF Actions Tool" name="portal_actions" \
-xmlns:i18n="http://xml.zope.org/namespaces/i18n">
- <action-provider name="portal_actions"/>
-</object>
-"""
-
-_NORMAL_EXPORT = """\
-<?xml version="1.0"?>
-<object meta_type="CMF Actions Tool" name="portal_actions" \
-xmlns:i18n="http://xml.zope.org/namespaces/i18n">
- <action-provider name="portal_actions"/>
- <action-provider name="portal_foo">
- <action action_id="foo"
- title="Foo"
- url_expr="string:${object_url}/foo"
- condition_expr="python:1"
- category="dummy"
- visible="True"/>
- </action-provider>
- <action-provider name="portal_bar">
- <action action_id="bar"
- title="Bar"
- url_expr="string:${object_url}/bar"
- condition_expr="python:0"
- category="dummy"
- visible="False">
- <permission>Manage portal</permission>
- </action>
- </action-provider>
-</object>
-"""
-
-_NEWSYTLE_EXPORT = """\
-<?xml version="1.0"?>
-<object meta_type="CMF Actions Tool" name="portal_actions" \
-xmlns:i18n="http://xml.zope.org/namespaces/i18n">
- <action-provider name="portal_actions"/>
- <object name="dummy" meta_type="CMF Action Category">
- <property name="title"></property>
- <object name="foo" meta_type="CMF Action">
- <property name="title">Foo</property>
- <property name="description"></property>
- <property name="url_expr">string:${object_url}/foo</property>
- <property name="icon_expr"></property>
- <property name="available_expr">python:1</property>
- <property name="permissions"></property>
- <property name="visible">True</property>
- </object>
- <object name="bar" meta_type="CMF Action">
- <property name="title">Bar</property>
- <property name="description"></property>
- <property name="url_expr">string:${object_url}/bar</property>
- <property name="icon_expr"></property>
- <property name="available_expr">python:0</property>
- <property name="permissions">
- <element value="Manage portal"/>
- </property>
- <property name="visible">False</property>
- </object>
- </object>
-</object>
-"""
-
-_I18N_IMPORT = """\
-<?xml version="1.0"?>
-<object meta_type="CMF Actions Tool" name="portal_actions" \
-xmlns:i18n="http://xml.zope.org/namespaces/i18n">
- <action-provider name="portal_actions"/>
- <object name="dummy" meta_type="CMF Action Category">
- <property name="title"></property>
- <object name="foo" meta_type="CMF Action" i18n:domain="foo_domain">
- <property name="title" i18n:translate="">Foo</property>
- <property name="description" i18n:translate=""></property>
- <property name="url_expr">string:${object_url}/foo</property>
- <property name="icon_expr"></property>
- <property name="available_expr">python:1</property>
- <property name="permissions"></property>
- <property name="visible">True</property>
- </object>
- </object>
-</object>
-"""
-
-_INSERT_IMPORT = """\
-<?xml version="1.0"?>
-<actions-tool xmlns:i18n="http://xml.zope.org/namespaces/i18n">
- <object name="dummy">
- <object name="spam" meta_type="CMF Action" insert-before="*">
- <property name="title">Spam</property>
- <property name="description"></property>
- <property name="url_expr">string:${object_url}/spam</property>
- <property name="icon_expr">string:spam_icon.png</property>
- <property name="available_expr"></property>
- <property name="permissions">
- <element value="View" /></property>
- <property name="visible">True</property>
- </object>
- <object name="foo" insert-after="*">
- <property name="icon_expr">string:foo_icon.png</property>
- </object>
- </object>
-</actions-tool>
-"""
-
-_REMOVE_IMPORT = """\
-<?xml version="1.0"?>
-<actions-tool xmlns:i18n="http://xml.zope.org/namespaces/i18n">
- <action-provider id="portal_actions" remove="">
- </action-provider>
- <action-provider id="not_existing" remove="">
- </action-provider>
- <action-provider id="portal_bar" remove="">
- </action-provider>
-</actions-tool>
-"""
-
-
-class Test_exportActionProviders( _ActionSetup ):
-
- def test_unchanged( self ):
-
- site = self._initSite( 0, 0 )
- context = DummyExportContext( site )
-
- from Products.CMFSetup.actions import exportActionProviders
- exportActionProviders( context )
-
- self.assertEqual( len( context._wrote ), 1 )
- filename, text, content_type = context._wrote[ 0 ]
- self.assertEqual( filename, 'actions.xml' )
- self._compareDOM( text, _EMPTY_EXPORT )
- self.assertEqual( content_type, 'text/xml' )
-
- def test_normal( self ):
-
- site = self._initSite()
-
- context = DummyExportContext( site )
-
- from Products.CMFSetup.actions import exportActionProviders
- exportActionProviders( context )
-
- self.assertEqual( len( context._wrote ), 1 )
- filename, text, content_type = context._wrote[ 0 ]
- self.assertEqual( filename, 'actions.xml' )
- self._compareDOM( text, _NORMAL_EXPORT )
- self.assertEqual( content_type, 'text/xml' )
-
-
-class Test_importActionProviders( _ActionSetup ):
-
- def test_empty_default_purge( self ):
-
- site = self._initSite( 2, 0 )
- atool = site.portal_actions
-
- self.assertEqual( len( atool.listActionProviders() ), 2 )
- self.failUnless( 'portal_foo' in atool.listActionProviders() )
- self.failUnless( 'portal_actions' in atool.listActionProviders() )
-
- context = DummyImportContext( site )
- context._files[ 'actions.xml' ] = _EMPTY_EXPORT
-
- from Products.CMFSetup.actions import importActionProviders
- importActionProviders( context )
-
- self.assertEqual( len( atool.listActionProviders() ), 1 )
- self.failIf( 'portal_foo' in atool.listActionProviders() )
- self.failUnless( 'portal_actions' in atool.listActionProviders() )
- self.assertEqual( len( atool.objectIds() ), 0 )
-
- def test_empty_explicit_purge( self ):
-
- site = self._initSite( 2, 0 )
- atool = site.portal_actions
-
- self.assertEqual( len( atool.listActionProviders() ), 2 )
- self.failUnless( 'portal_foo' in atool.listActionProviders() )
- self.failUnless( 'portal_actions' in atool.listActionProviders() )
-
- context = DummyImportContext( site, True )
- context._files[ 'actions.xml' ] = _EMPTY_EXPORT
-
- from Products.CMFSetup.actions import importActionProviders
- importActionProviders( context )
-
- self.assertEqual( len( atool.listActionProviders() ), 1 )
- self.failIf( 'portal_foo' in atool.listActionProviders() )
- self.failUnless( 'portal_actions' in atool.listActionProviders() )
- self.assertEqual( len( atool.objectIds() ), 0 )
-
- def test_empty_skip_purge( self ):
-
- site = self._initSite( 2, 0 )
- atool = site.portal_actions
-
- self.assertEqual( len( atool.listActionProviders() ), 2 )
- self.failUnless( 'portal_foo' in atool.listActionProviders() )
- self.failUnless( 'portal_actions' in atool.listActionProviders() )
-
- context = DummyImportContext( site, False )
- context._files[ 'actions.xml' ] = _EMPTY_EXPORT
-
- from Products.CMFSetup.actions import importActionProviders
- importActionProviders( context )
-
- self.assertEqual( len( atool.listActionProviders() ), 2 )
- self.failUnless( 'portal_foo' in atool.listActionProviders() )
- self.failUnless( 'portal_actions' in atool.listActionProviders() )
-
- def test_normal( self ):
-
- site = self._initSite( 1, 1 )
- atool = site.portal_actions
- foo = site.portal_foo
- bar = site.portal_bar
-
- self.assertEqual( len( atool.listActionProviders() ), 1 )
- self.failIf( 'portal_foo' in atool.listActionProviders() )
- self.failIf( foo.listActions() )
- self.failIf( 'portal_bar' in atool.listActionProviders() )
- self.failIf( bar.listActions() )
- self.failUnless( 'portal_actions' in atool.listActionProviders() )
-
- context = DummyImportContext( site )
- context._files[ 'actions.xml' ] = _NORMAL_EXPORT
-
- from Products.CMFSetup.actions import importActionProviders
- importActionProviders( context )
-
- self.assertEqual( len( atool.listActionProviders() ), 1 )
- self.failIf( 'portal_foo' in atool.listActionProviders() )
- self.failUnless( 'portal_actions' in atool.listActionProviders() )
-
- self.assertEqual( len( atool.objectIds() ), 1 )
- self.failUnless( 'dummy' in atool.objectIds() )
- self.assertEqual( len( atool.dummy.objectIds() ) , 2 )
- self.failUnless( 'foo' in atool.dummy.objectIds() )
- self.failUnless( 'bar' in atool.dummy.objectIds() )
- self.failIf( foo.listActions() )
- self.failIf( bar.listActions() )
-
- # complete the roundtrip
- context = DummyExportContext( site )
- from Products.CMFSetup.actions import exportActionProviders
- exportActionProviders( context )
-
- self.assertEqual( len( context._wrote ), 1 )
- filename, text, content_type = context._wrote[ 0 ]
- self.assertEqual( filename, 'actions.xml' )
- self._compareDOM( text, _NEWSYTLE_EXPORT )
- self.assertEqual( content_type, 'text/xml' )
-
- def test_normal_encode_as_ascii( self ):
-
- site = self._initSite( 1, 1 )
- atool = site.portal_actions
- foo = site.portal_foo
- bar = site.portal_bar
-
- context = DummyImportContext( site, encoding='ascii' )
- context._files[ 'actions.xml' ] = _NORMAL_EXPORT
-
- from Products.CMFSetup.actions import importActionProviders
- importActionProviders( context )
-
- self.assertEqual( len( atool.listActionProviders() ), 1 )
- self.failIf( 'portal_foo' in atool.listActionProviders() )
- self.failUnless( 'portal_actions' in atool.listActionProviders() )
-
- self.assertEqual( len( atool.objectIds() ), 1 )
- self.failUnless( 'dummy' in atool.objectIds() )
- self.assertEqual( len( atool.dummy.objectIds() ), 2 )
- self.failUnless( 'foo' in atool.dummy.objectIds() )
- self.failUnless( 'bar' in atool.dummy.objectIds() )
- self.failIf( foo.listActions() )
- self.failIf( bar.listActions() )
-
- def test_i18n(self):
-
- from Products.CMFSetup.actions import importActionProviders
-
- site = self._initSite(0, 0)
- atool = site.portal_actions
-
- context = DummyImportContext(site)
- context._files['actions.xml'] = _I18N_IMPORT
- importActionProviders(context)
-
- self.assertEqual(len(atool.listActionProviders()), 1)
- self.assertEqual(atool.objectIds(), ['dummy'])
- self.assertEqual(atool.dummy.objectIds(), ['foo'])
- self.assertEqual(atool.dummy.foo.i18n_domain, 'foo_domain')
-
- # complete the roundtrip
- context = DummyExportContext(site)
- from Products.CMFSetup.actions import exportActionProviders
- exportActionProviders(context)
-
- self.assertEqual(len(context._wrote), 1)
- filename, text, content_type = context._wrote[0]
- self.assertEqual(filename, 'actions.xml')
- self._compareDOM(text, _I18N_IMPORT)
- self.assertEqual(content_type, 'text/xml')
-
- def test_insert_skip_purge(self):
-
- from Products.CMFSetup.actions import importActionProviders
-
- site = self._initSite(0, 0)
- atool = site.portal_actions
-
- context = DummyImportContext(site)
- context._files['actions.xml'] = _NEWSYTLE_EXPORT
- importActionProviders(context)
-
- self.assertEqual( len( atool.listActionProviders() ), 1 )
- self.assertEqual( atool.objectIds(), ['dummy'] )
- self.assertEqual( atool.dummy.objectIds(), ['foo', 'bar'] )
- self.assertEqual( atool.dummy.foo.icon_expr, '' )
-
- context = DummyImportContext(site, False)
- context._files['actions.xml'] = _INSERT_IMPORT
- importActionProviders(context)
-
- self.assertEqual( len( atool.listActionProviders() ), 1 )
- self.assertEqual( atool.objectIds(), ['dummy'] )
- self.assertEqual( atool.dummy.objectIds(), ['spam', 'bar', 'foo'] )
- self.assertEqual( atool.dummy.foo.icon_expr, 'string:foo_icon.png' )
-
- def test_remove_skip_purge(self):
-
- from Products.CMFSetup.actions import importActionProviders
-
- site = self._initSite(2, 2)
- atool = site.portal_actions
-
- self.assertEqual( atool.listActionProviders(),
- ['portal_actions', 'portal_foo', 'portal_bar'] )
-
- context = DummyImportContext(site, False)
- context._files['actions.xml'] = _REMOVE_IMPORT
- importActionProviders(context)
-
- self.assertEqual( atool.listActionProviders(), ['portal_foo'] )
-
-
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite( Test_exportActionProviders ),
- unittest.makeSuite( Test_importActionProviders ),
- ))
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
More information about the CMF-checkins
mailing list