[CMF-checkins] SVN: CMF/trunk/CMF Forward-port CTR export / import
from 1.5 branch.
Tres Seaver
tseaver at palladion.com
Fri Oct 14 00:06:21 EDT 2005
Log message for revision 39125:
Forward-port CTR export / import from 1.5 branch.
Changed:
U CMF/trunk/CMFDefault/Portal.py
D CMF/trunk/CMFDefault/profiles/default/caching_policy_mgr.xml
A CMF/trunk/CMFDefault/profiles/default/cachingpolicymgr.xml
A CMF/trunk/CMFDefault/profiles/default/contenttyperegistry.xml
U CMF/trunk/CMFDefault/profiles/default/export_steps.xml
U CMF/trunk/CMFDefault/profiles/default/import_steps.xml
U CMF/trunk/CMFDefault/profiles/default/toolset.xml
U CMF/trunk/CMFDefault/setuphandlers.py
U CMF/trunk/CMFSetup/README.txt
A CMF/trunk/CMFSetup/contenttyperegistry.py
A CMF/trunk/CMFSetup/tests/test_contenttyperegistry.py
A CMF/trunk/CMFSetup/xml/ctrExport.xml
-=-
Modified: CMF/trunk/CMFDefault/Portal.py
===================================================================
--- CMF/trunk/CMFDefault/Portal.py 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFDefault/Portal.py 2005-10-14 04:06:21 UTC (rev 39125)
@@ -203,30 +203,6 @@
fti = FactoryTypeInformation(**t)
tool._setObject(t['id'], fti)
- def setupMimetypes(self, p):
- p.manage_addProduct[ 'CMFCore' ].manage_addRegistry()
- reg = p.content_type_registry
-
- reg.addPredicate( 'link', 'extension' )
- reg.getPredicate( 'link' ).edit( extensions="url, link" )
- reg.assignTypeName( 'link', 'Link' )
-
- reg.addPredicate( 'news', 'extension' )
- reg.getPredicate( 'news' ).edit( extensions="news" )
- reg.assignTypeName( 'news', 'News Item' )
-
- reg.addPredicate( 'document', 'major_minor' )
- reg.getPredicate( 'document' ).edit( major="text", minor="" )
- reg.assignTypeName( 'document', 'Document' )
-
- reg.addPredicate( 'image', 'major_minor' )
- reg.getPredicate( 'image' ).edit( major="image", minor="" )
- reg.assignTypeName( 'image', 'Image' )
-
- reg.addPredicate( 'file', 'major_minor' )
- reg.getPredicate( 'file' ).edit( major="application", minor="" )
- reg.assignTypeName( 'file', 'File' )
-
def setupWorkflow(self, p):
wftool = getToolByName(p, 'portal_workflow', None)
if wftool is None:
@@ -261,7 +237,6 @@
self.setupTypes(p, PortalFolder.factory_type_information)
self.setupTypes(p, Topic.factory_type_information)
- self.setupMimetypes(p)
self.setupWorkflow(p)
def create(self, parent, id, create_userfolder):
Deleted: CMF/trunk/CMFDefault/profiles/default/caching_policy_mgr.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/default/caching_policy_mgr.xml 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFDefault/profiles/default/caching_policy_mgr.xml 2005-10-14 04:06:21 UTC (rev 39125)
@@ -1,4 +0,0 @@
-<?xml version="1.0"?>
-<caching-policies>
-<!-- TODO: add some sensible defaults -->
-</caching-policies>
Copied: CMF/trunk/CMFDefault/profiles/default/cachingpolicymgr.xml (from rev 39124, CMF/trunk/CMFDefault/profiles/default/caching_policy_mgr.xml)
Added: CMF/trunk/CMFDefault/profiles/default/contenttyperegistry.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/default/contenttyperegistry.xml 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFDefault/profiles/default/contenttyperegistry.xml 2005-10-14 04:06:21 UTC (rev 39125)
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<content-type-registry>
+ <predicate
+ predicate_id="link"
+ predicate_type="extension"
+ content_type_name="Link">
+ <argument value="url,link" />
+ </predicate>
+ <predicate
+ predicate_id="news"
+ predicate_type="extension"
+ content_type_name="News Item">
+ <argument value="news" />
+ </predicate>
+ <predicate
+ predicate_id="document"
+ predicate_type="major_minor"
+ content_type_name="Document">
+ <argument value="text" />
+ <argument value="" />
+ </predicate>
+ <predicate
+ predicate_id="image"
+ predicate_type="major_minor"
+ content_type_name="Image">
+ <argument value="image" />
+ <argument value="" />
+ </predicate>
+ <predicate
+ predicate_id="file"
+ predicate_type="major_minor"
+ content_type_name="File">
+ <argument value="application" />
+ <argument value="" />
+ </predicate>
+</content-type-registry>
Modified: CMF/trunk/CMFDefault/profiles/default/export_steps.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/default/export_steps.xml 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFDefault/profiles/default/export_steps.xml 2005-10-14 04:06:21 UTC (rev 39125)
@@ -3,133 +3,66 @@
<export-step id="actions"
handler="Products.CMFSetup.actions.exportActionProviders"
title="Action Providers">
-
-
-
Export actions tool's action providers and their actions.
-
-
-
</export-step>
<export-step id="catalog"
handler="Products.CMFSetup.catalog.exportCatalogTool"
title="Catalog Tool">
-
-
-
Export catalog tool's sub-objects, indexes and columns.
-
-
-
</export-step>
<export-step id="cookieauth"
handler="Products.CMFSetup.cookieauth.exportCookieCrumbler"
title="Cookie Authentication">
-
-
-
Export cookie crumbler settings
-
-
-
</export-step>
<export-step id="mailhost"
handler="Products.CMFSetup.mailhost.exportMailHost"
title="MailHost">
-
-
-
Export the mailhost's settings and properties
-
-
-
</export-step>
<export-step id="properties"
handler="Products.CMFSetup.properties.exportSiteProperties"
title="Site Properties">
-
-
-
Export site properties.
-
-
-
</export-step>
<export-step id="rolemap"
handler="Products.GenericSetup.rolemap.exportRolemap"
title="Role / Permission Map">
-
-
-
Export custom roles and non-default role-permission mappings.
-
-
-
</export-step>
<export-step id="skins"
handler="Products.CMFSetup.skins.exportSkinsTool"
title="Skins Tool">
-
-
-
Export skins tool's filesystem directory views and skin path definitions.
-
-
-
</export-step>
<export-step id="step_registries"
handler="Products.GenericSetup.tool.exportStepRegistries"
title="Step Registries">
-
-
-
Export current contents of import step registry and export step registry.
-
-
-
</export-step>
<export-step id="toolset"
handler="Products.GenericSetup.tool.exportToolset"
title="Required Tools">
-
-
-
Export required / forbidden tools.
-
-
-
</export-step>
<export-step id="typeinfo"
handler="Products.CMFSetup.typeinfo.exportTypesTool"
title="Types Tool">
-
-
-
Export types tool's type information objects.
-
-
-
</export-step>
<export-step id="workflows"
handler="Products.CMFSetup.workflow.exportWorkflowTool"
title="Workflow Tool">
-
-
-
Export workflow tool's workflow definitions and supporting scripts.
-
-
-
</export-step>
<export-step id="caching_policy_mgr"
handler="Products.CMFSetup.cachingpolicymgr.exportCachingPolicyManager"
title="Caching Policies">
-
-
-
Export cacing policy manager's policies.
-
-
-
</export-step>
+ <export-step id="content_type_registry"
+ handler="Products.CMFSetup.contenttyperegistry.exportContentTypeRegistry"
+ title="Content Type Registry">
+ Export content type registry's predicates / bindings.
+ </export-step>
</export-steps>
Modified: CMF/trunk/CMFDefault/profiles/default/import_steps.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/default/import_steps.xml 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFDefault/profiles/default/import_steps.xml 2005-10-14 04:06:21 UTC (rev 39125)
@@ -4,154 +4,78 @@
handler="Products.CMFSetup.actions.importActionProviders"
title="Action Providers">
<dependency step="toolset"/>
-
-
-
Import actions tool's action providers and their actions.
-
-
-
-
</import-step>
<import-step id="catalog" version="20050929-01"
handler="Products.CMFSetup.catalog.importCatalogTool"
title="Catalog Tool">
<dependency step="toolset"/>
-
-
-
Import catalog tool's sub-objects, indexes and columns.
-
-
-
-
</import-step>
<import-step id="cookie_authentication"
version="20050903-01"
handler="Products.CMFSetup.cookieauth.importCookieCrumbler"
title="Cookie Authentication">
<dependency step="toolset"/>
-
-
-
Import cookie crumbler settings
-
-
-
-
</import-step>
<import-step id="mailhost" version="20050803-01"
handler="Products.CMFSetup.mailhost.importMailHost"
title="MailHost">
<dependency step="toolset"/>
-
-
-
Import mailhost settings
-
-
-
-
</import-step>
<import-step id="properties" version="20041215-01"
handler="Products.CMFSetup.properties.importSiteProperties"
title="Site Properties">
-
-
-
Import site properties.
-
-
-
-
</import-step>
<import-step id="rolemap" version="20040523-01"
handler="Products.GenericSetup.rolemap.importRolemap"
title="Role / Permission Map">
-
-
-
-
Import custom roles and non-default role-permission mappings.
-
-
-
</import-step>
<import-step id="skins" version="20040630-01"
handler="Products.CMFSetup.skins.importSkinsTool"
title="Skins Tool">
<dependency step="toolset"/>
-
-
-
Import skins tool's filesystem directory views and skin path definitions.
-
-
-
-
</import-step>
<import-step id="toolset" version="20040630-01"
handler="Products.GenericSetup.tool.importToolset"
title="Required tools">
-
-
-
-
Create required tools, replacing any of the wrong class, and remove
forbidden ones.
-
-
</import-step>
<import-step id="typeinfo" version="20040630-01"
handler="Products.CMFSetup.typeinfo.importTypesTool"
title="Types Tool">
<dependency step="toolset"/>
-
-
-
Import types tool's type information objects.
-
-
-
-
</import-step>
<import-step id="various" version="20041118-01"
handler="Products.CMFDefault.setuphandlers.importVarious"
title="Various Settings">
<dependency step="toolset"/>
-
-
-
Import various settings from PortalGenerator.
-
-
-
-
</import-step>
<import-step id="workflow" version="20040630-01"
handler="Products.CMFSetup.workflow.importWorkflowTool"
title="Workflow Tool">
<dependency step="toolset"/>
<dependency step="typeinfo"/>
-
-
-
Import workflow tool's workflow definitions and supporting scripts.
-
-
-
-
</import-step>
<import-step id="caching_policy_mgr" version="20051011-01"
handler="Products.CMFSetup.cachingpolicymgr.importCachingPolicyManager"
title="Caching Policies">
<dependency step="toolset"/>
-
-
-
- Import cacing policy manager's policies.
-
-
-
+ Import caching policy manager's policies.
</import-step>
+ <import-step id="content_type_registry" version="20051013-01"
+ handler="Products.CMFSetup.contenttyperegistry.importContentTypeRegistry"
+ title="Content Type Registry">
+ <dependency step="toolset"/>
+ Import content type registry's predicates and bindings.
+ </import-step>
</import-steps>
Modified: CMF/trunk/CMFDefault/profiles/default/toolset.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/default/toolset.xml 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFDefault/profiles/default/toolset.xml 2005-10-14 04:06:21 UTC (rev 39125)
@@ -7,6 +7,8 @@
class="Products.CMFCore.CookieCrumbler.CookieCrumbler"/>
<required tool_id="caching_policy_manager"
class="Products.CMFCore.CachingPolicyManager.CachingPolicyManager"/>
+ <required tool_id="content_type_registry"
+ class="Products.CMFCore.ContentTypeRegistry.ContentTypeRegistry"/>
<required tool_id="portal_actions"
class="Products.CMFCore.ActionsTool.ActionsTool"/>
<required tool_id="portal_catalog"
Modified: CMF/trunk/CMFDefault/setuphandlers.py
===================================================================
--- CMF/trunk/CMFDefault/setuphandlers.py 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFDefault/setuphandlers.py 2005-10-14 04:06:21 UTC (rev 39125)
@@ -39,6 +39,5 @@
gen = PortalGenerator()
gen.setupUserFolder(site)
gen.setupMembersFolder(site)
- gen.setupMimetypes(site)
return 'Various settings from PortalGenerator imported.'
Modified: CMF/trunk/CMFSetup/README.txt
===================================================================
--- CMF/trunk/CMFSetup/README.txt 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFSetup/README.txt 2005-10-14 04:06:21 UTC (rev 39125)
@@ -67,6 +67,10 @@
o policy settings
+ - (x) 'content_type_registry'
+
+ o predicate -> portal_type bindings.
+
- (_) 'portal_membership'
o "skeleton" home folder (XXX: is this in the core?)
@@ -75,10 +79,6 @@
o member properties
- - (_) 'content_type_registry'
-
- o predicate -> portal_type bindings.
-
- (_) 'portal_metadata'
o global properties
Added: CMF/trunk/CMFSetup/contenttyperegistry.py
===================================================================
--- CMF/trunk/CMFSetup/contenttyperegistry.py 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFSetup/contenttyperegistry.py 2005-10-14 04:06:21 UTC (rev 39125)
@@ -0,0 +1,137 @@
+##############################################################################
+#
+# Copyright (c) 2005 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.
+#
+##############################################################################
+"""ContentTypeRegistry setup handlers.
+
+$Id$
+"""
+
+from AccessControl import ClassSecurityInfo
+from AccessControl.Permission import Permission
+from Globals import InitializeClass
+from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+
+from Products.CMFCore.utils import getToolByName
+
+from permissions import ManagePortal
+from utils import CONVERTER
+from utils import DEFAULT
+from utils import ExportConfiguratorBase
+from utils import ImportConfiguratorBase
+from utils import KEY
+from utils import _xmldir
+
+#
+# Configurator entry points
+#
+_FILENAME = 'contenttyperegistry.xml'
+
+def importContentTypeRegistry(context):
+ """ Import content type registry settings from an XML file.
+ """
+ site = context.getSite()
+ ctr = getToolByName(site, 'content_type_registry', None)
+ if ctr is None:
+ return 'Content type registry: No tool!'
+
+ body = context.readDataFile(_FILENAME)
+ if body is None:
+ return 'Content type registry: Nothing to import.'
+
+ if context.shouldPurge():
+ ctr.__init__()
+
+ # now act on the settings we've retrieved
+ configurator = ContentTypeRegistryImportConfigurator(site)
+ cpm_info = configurator.parseXML(body)
+
+ for info in cpm_info['predicates']:
+ ctr.addPredicate(info['predicate_id'], info['predicate_type'])
+ arguments = [x['value'].encode('ascii') for x in info['arguments']]
+ ctr.getPredicate(info['predicate_id']).edit(*arguments)
+ ctr.assignTypeName(info['predicate_id'], info['content_type_name'])
+
+ return 'Content type registry settings imported.'
+
+def exportContentTypeRegistry(context):
+ """ Export content type registry settings as an XML file.
+ """
+ site = context.getSite()
+ mhc = ContentTypeRegistryExportConfigurator( site ).__of__( site )
+ text = mhc.generateXML()
+
+ context.writeDataFile( _FILENAME, text, 'text/xml' )
+
+ return 'Content type registry settings exported.'
+
+
+class ContentTypeRegistryExportConfigurator(ExportConfiguratorBase):
+ """ Synthesize XML description of ctr properties.
+ """
+ security = ClassSecurityInfo()
+
+ security.declareProtected( ManagePortal, 'listPredicateInfo' )
+ def listPredicateInfo(self):
+ """ Return a list of mappings describing the tool's predicates.
+ """
+ cpm = getToolByName(self._site, 'content_type_registry')
+ for predicate_id, (predicate,
+ content_type_name) in cpm.listPredicates():
+ yield {'predicate_id': predicate_id,
+ 'predicate_type': predicate.PREDICATE_TYPE,
+ 'content_type_name' : content_type_name,
+ 'arguments' : self._crackArgs(predicate),
+ }
+
+ _KNOWN_PREDICATE_TYPES = {
+ 'major_minor': lambda x: (','.join(x.major), ','.join(x.minor)),
+ 'extension': lambda x: (','.join(x.extensions),),
+ 'mimetype_regex': lambda x: (x.pattern and x.pattern.pattern,),
+ 'name_regex': lambda x: (x.pattern and x.pattern.pattern,),
+ }
+
+ security.declarePrivate('_crackArgs')
+ def _crackArgs(self, predicate):
+ """ Crack apart the "edit args" from predicate.
+ """
+ cracker = self._KNOWN_PREDICATE_TYPES.get(predicate.PREDICATE_TYPE)
+ if cracker is not None:
+ return cracker(predicate)
+ return () # XXX: raise?
+
+ security.declarePrivate('_getExportTemplate')
+ def _getExportTemplate(self):
+
+ return PageTemplateFile('ctrExport.xml', _xmldir)
+
+InitializeClass(ContentTypeRegistryExportConfigurator)
+
+class ContentTypeRegistryImportConfigurator(ImportConfiguratorBase):
+
+ def _getImportMapping(self):
+ return {
+ 'content-type-registry':
+ { 'predicate': {KEY: 'predicates', DEFAULT: ()}
+ },
+ 'predicate':
+ { 'predicate_id': {},
+ 'remove': {},
+ 'predicate_type': {},
+ 'content_type_name': {},
+ 'argument': {KEY: 'arguments', DEFAULT: ()},
+ },
+ 'argument':
+ { 'value': {},
+ },
+ }
+
+InitializeClass(ContentTypeRegistryImportConfigurator)
Property changes on: CMF/trunk/CMFSetup/contenttyperegistry.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: CMF/trunk/CMFSetup/tests/test_contenttyperegistry.py
===================================================================
--- CMF/trunk/CMFSetup/tests/test_contenttyperegistry.py 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFSetup/tests/test_contenttyperegistry.py 2005-10-14 04:06:21 UTC (rev 39125)
@@ -0,0 +1,278 @@
+##############################################################################
+#
+# Copyright (c) 2005 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.
+#
+##############################################################################
+"""ContentTypeRegistry setup handler unit tests.
+
+$Id$
+"""
+import unittest
+#import Testing
+
+
+from common import BaseRegistryTests
+from common import DummyExportContext
+from common import DummyImportContext
+
+_TEST_PREDICATES = (
+ ('plain_text', 'major_minor', ('text', 'plain,javascript'), 'File'),
+ ('stylesheets', 'extension', ('css,xsl,xslt',), 'Text File'),
+ ('images', 'mimetype_regex', ('image/.*',), 'Image'),
+ ('logfiles', 'name_regex', ('error_log-.*',), 'Log File'),
+)
+
+class _ContentTypeRegistrySetup(BaseRegistryTests):
+
+ MAJOR_MINOR_ID = _TEST_PREDICATES[0][0]
+ MAJOR = _TEST_PREDICATES[0][2][0]
+ MINOR = _TEST_PREDICATES[0][2][1]
+ MAJOR_MINOR_TYPENAME = _TEST_PREDICATES[0][3]
+ EXTENSION_ID = _TEST_PREDICATES[1][0]
+ EXTENSIONS = _TEST_PREDICATES[1][2][0]
+ EXTENSION_TYPENAME = _TEST_PREDICATES[1][3]
+ MIMETYPE_REGEX_ID = _TEST_PREDICATES[2][0]
+ MIMETYPE_REGEX = _TEST_PREDICATES[2][2][0]
+ MIMETYPE_REGEX_TYPENAME = _TEST_PREDICATES[2][3]
+ NAME_REGEX_ID = _TEST_PREDICATES[3][0]
+ NAME_REGEX = _TEST_PREDICATES[3][2][0]
+ NAME_REGEX_TYPENAME = _TEST_PREDICATES[3][3]
+
+ _EMPTY_EXPORT = """\
+<?xml version="1.0"?>
+<content-type-registry>
+</content-type-registry>
+"""
+
+ _WITH_POLICY_EXPORT = """\
+<?xml version="1.0"?>
+<content-type-registry>
+ <predicate
+ predicate_id="%s"
+ predicate_type="major_minor"
+ content_type_name="%s">
+ <argument value="%s" />
+ <argument value="%s" />
+ </predicate>
+ <predicate
+ predicate_id="%s"
+ predicate_type="extension"
+ content_type_name="%s">
+ <argument value="%s" />
+ </predicate>
+ <predicate
+ predicate_id="%s"
+ predicate_type="mimetype_regex"
+ content_type_name="%s">
+ <argument value="%s" />
+ </predicate>
+ <predicate
+ predicate_id="%s"
+ predicate_type="name_regex"
+ content_type_name="%s">
+ <argument value="%s" />
+ </predicate>
+</content-type-registry>
+""" % (MAJOR_MINOR_ID,
+ MAJOR_MINOR_TYPENAME,
+ MAJOR,
+ MINOR,
+ EXTENSION_ID,
+ EXTENSION_TYPENAME,
+ EXTENSIONS,
+ MIMETYPE_REGEX_ID,
+ MIMETYPE_REGEX_TYPENAME,
+ MIMETYPE_REGEX,
+ NAME_REGEX_ID,
+ NAME_REGEX_TYPENAME,
+ NAME_REGEX,
+ )
+
+ def _initSite(self, mit_predikat=False):
+ from OFS.Folder import Folder
+ from Products.CMFCore.ContentTypeRegistry import ContentTypeRegistry
+
+ self.root.site = Folder(id='site')
+ site = self.root.site
+ ctr = ContentTypeRegistry()
+ site._setObject( ctr.getId(), ctr )
+
+ if mit_predikat:
+ for (predicate_id, predicate_type, edit_args, content_type_name
+ ) in _TEST_PREDICATES:
+ ctr.addPredicate(predicate_id, predicate_type)
+ predicate = ctr.getPredicate(predicate_id)
+ predicate.edit(*edit_args)
+ ctr.assignTypeName(predicate_id, content_type_name)
+
+ return site
+
+class ContentTypeRegistryExportConfiguratorTests(_ContentTypeRegistrySetup):
+
+ def _getTargetClass(self):
+ from Products.CMFSetup.contenttyperegistry \
+ import ContentTypeRegistryExportConfigurator
+
+ return ContentTypeRegistryExportConfigurator
+
+ def test_generateXML_empty(self):
+ site = self._initSite(mit_predikat=False)
+ configurator = self._makeOne(site).__of__(site)
+
+ self._compareDOM(configurator.generateXML(), self._EMPTY_EXPORT)
+
+ def test_generateXML_with_policy(self):
+ site = self._initSite(mit_predikat=True)
+ configurator = self._makeOne(site).__of__(site)
+
+ self._compareDOM(configurator.generateXML(), self._WITH_POLICY_EXPORT)
+
+
+class ContentTypeRegistryImportConfiguratorTests(_ContentTypeRegistrySetup):
+
+ def _getTargetClass(self):
+ from Products.CMFSetup.contenttyperegistry \
+ import ContentTypeRegistryImportConfigurator
+
+ return ContentTypeRegistryImportConfigurator
+
+ def test_parseXML_empty(self):
+ site = self._initSite(mit_predikat=False)
+ configurator = self._makeOne(site)
+ ctr_info = configurator.parseXML(self._EMPTY_EXPORT)
+
+ self.assertEqual(len(ctr_info['predicates']), 0)
+
+ def test_parseXML_with_policy(self):
+ site = self._initSite(mit_predikat=False)
+ configurator = self._makeOne(site)
+ ctr_info = configurator.parseXML(self._WITH_POLICY_EXPORT)
+
+ self.assertEqual(len(ctr_info['predicates']), len(_TEST_PREDICATES))
+
+ info = ctr_info['predicates'][0]
+ self.assertEqual(info['predicate_id'], self.MAJOR_MINOR_ID)
+ self.assertEqual(info['predicate_type'], 'major_minor')
+ self.assertEqual(info['content_type_name'], self.MAJOR_MINOR_TYPENAME)
+ arguments = info['arguments']
+ self.assertEqual(len(arguments), 2)
+ self.assertEqual(arguments[0]['value'], self.MAJOR)
+ self.assertEqual(arguments[1]['value'], self.MINOR)
+
+ info = ctr_info['predicates'][1]
+ self.assertEqual(info['predicate_id'], self.EXTENSION_ID)
+ self.assertEqual(info['predicate_type'], 'extension')
+ self.assertEqual(info['content_type_name'], self.EXTENSION_TYPENAME)
+ arguments = info['arguments']
+ self.assertEqual(len(arguments), 1)
+ self.assertEqual(arguments[0]['value'], self.EXTENSIONS)
+
+ info = ctr_info['predicates'][2]
+ self.assertEqual(info['predicate_id'], self.MIMETYPE_REGEX_ID)
+ self.assertEqual(info['predicate_type'], 'mimetype_regex')
+ self.assertEqual(info['content_type_name'],
+ self.MIMETYPE_REGEX_TYPENAME)
+ arguments = info['arguments']
+ self.assertEqual(len(arguments), 1)
+ self.assertEqual(arguments[0]['value'], self.MIMETYPE_REGEX)
+
+ info = ctr_info['predicates'][3]
+ self.assertEqual(info['predicate_id'], self.NAME_REGEX_ID)
+ self.assertEqual(info['predicate_type'], 'name_regex')
+ self.assertEqual(info['content_type_name'],
+ self.NAME_REGEX_TYPENAME)
+ arguments = info['arguments']
+ self.assertEqual(len(arguments), 1)
+ self.assertEqual(arguments[0]['value'], self.NAME_REGEX)
+
+class Test_exportContentTypeRegistry(_ContentTypeRegistrySetup):
+
+ def test_empty(self):
+ from Products.CMFSetup.contenttyperegistry \
+ import exportContentTypeRegistry
+
+ site = self._initSite(mit_predikat=False)
+ context = DummyExportContext(site)
+ exportContentTypeRegistry(context)
+
+ self.assertEqual(len(context._wrote), 1)
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'contenttyperegistry.xml')
+ self._compareDOM(text, self._EMPTY_EXPORT)
+ self.assertEqual(content_type, 'text/xml')
+
+ def test_with_policy(self):
+ from Products.CMFSetup.contenttyperegistry \
+ import exportContentTypeRegistry
+
+ site = self._initSite(mit_predikat=True)
+ context = DummyExportContext(site)
+ exportContentTypeRegistry(context)
+
+ self.assertEqual(len(context._wrote), 1)
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'contenttyperegistry.xml')
+ self._compareDOM(text, self._WITH_POLICY_EXPORT)
+ self.assertEqual(content_type, 'text/xml')
+
+
+class Test_importContentTypeRegistry(_ContentTypeRegistrySetup):
+
+ def test_normal(self):
+ from Products.CMFSetup.contenttyperegistry \
+ import importContentTypeRegistry
+
+ site = self._initSite(mit_predikat=False)
+ ctr = site.content_type_registry
+ self.assertEqual(len(ctr.listPredicates()), 0)
+
+ context = DummyImportContext(site)
+ context._files['contenttyperegistry.xml'] = self._WITH_POLICY_EXPORT
+ importContentTypeRegistry(context)
+
+ self.assertEqual(len(ctr.listPredicates()), len(_TEST_PREDICATES))
+
+ predicate_id, (predicate, content_type_name) = ctr.listPredicates()[0]
+ self.assertEqual(predicate_id, self.MAJOR_MINOR_ID)
+ self.assertEqual(predicate.PREDICATE_TYPE, 'major_minor')
+ self.assertEqual(content_type_name, self.MAJOR_MINOR_TYPENAME)
+ self.assertEqual(predicate.major, self.MAJOR.split(','))
+ self.assertEqual(predicate.minor, self.MINOR.split(','))
+
+ predicate_id, (predicate, content_type_name) = ctr.listPredicates()[1]
+ self.assertEqual(predicate_id, self.EXTENSION_ID)
+ self.assertEqual(predicate.PREDICATE_TYPE, 'extension')
+ self.assertEqual(content_type_name, self.EXTENSION_TYPENAME)
+ self.assertEqual(predicate.extensions, self.EXTENSIONS.split(','))
+
+ predicate_id, (predicate, content_type_name) = ctr.listPredicates()[2]
+ self.assertEqual(predicate_id, self.MIMETYPE_REGEX_ID)
+ self.assertEqual(predicate.PREDICATE_TYPE, 'mimetype_regex')
+ self.assertEqual(content_type_name, self.MIMETYPE_REGEX_TYPENAME)
+ self.assertEqual(predicate.pattern.pattern, self.MIMETYPE_REGEX)
+
+ predicate_id, (predicate, content_type_name) = ctr.listPredicates()[3]
+ self.assertEqual(predicate_id, self.NAME_REGEX_ID)
+ self.assertEqual(predicate.PREDICATE_TYPE, 'name_regex')
+ self.assertEqual(content_type_name, self.NAME_REGEX_TYPENAME)
+ self.assertEqual(predicate.pattern.pattern, self.NAME_REGEX)
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(ContentTypeRegistryExportConfiguratorTests),
+ unittest.makeSuite(ContentTypeRegistryImportConfiguratorTests),
+ unittest.makeSuite(Test_exportContentTypeRegistry),
+ unittest.makeSuite(Test_importContentTypeRegistry),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
Property changes on: CMF/trunk/CMFSetup/tests/test_contenttyperegistry.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: CMF/trunk/CMFSetup/xml/ctrExport.xml
===================================================================
--- CMF/trunk/CMFSetup/xml/ctrExport.xml 2005-10-14 03:51:13 UTC (rev 39124)
+++ CMF/trunk/CMFSetup/xml/ctrExport.xml 2005-10-14 04:06:21 UTC (rev 39125)
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<content-type-registry xmlns:tal="http://xml.zope.org/namespaces/tal">
+ <predicate
+ predicate_id="PREDICATE_ID"
+ predicate_type="PREDICATE_TYPE"
+ content_type_name="CONTENT_TYPE_NAME"
+ tal:repeat="info context/listPredicateInfo"
+ tal:attributes="predicate_id info/predicate_id;
+ predicate_type info/predicate_type;
+ content_type_name info/content_type_name; " >
+ <argument
+ value="ARGUMENT_VALUE"
+ tal:repeat="arg info/arguments"
+ tal:attributes="value arg"
+ />
+ </predicate>
+</content-type-registry>
+
Property changes on: CMF/trunk/CMFSetup/xml/ctrExport.xml
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the CMF-checkins
mailing list