[CMF-checkins] SVN: CMF/branches/1.5/CMF - backported CookieCrumbler and MailHost changes from trunk

Yvo Schubbe y.2005- at wcm-solutions.de
Wed Oct 5 06:48:17 EDT 2005


Log message for revision 38763:
  - backported CookieCrumbler and MailHost changes from trunk
  - updated CMFDefault default profile
  

Changed:
  U   CMF/branches/1.5/CMFDefault/profiles/default/export_steps.xml
  U   CMF/branches/1.5/CMFDefault/profiles/default/import_steps.xml
  U   CMF/branches/1.5/CMFDefault/profiles/default/toolset.xml
  U   CMF/branches/1.5/CMFSetup/cookieauth.py
  U   CMF/branches/1.5/CMFSetup/mailhost.py
  U   CMF/branches/1.5/CMFSetup/tests/test_cookieauth.py
  U   CMF/branches/1.5/CMFSetup/tests/test_mailhost.py
  U   CMF/branches/1.5/CMFSetup/xml/ccExport.xml
  U   CMF/branches/1.5/CMFSetup/xml/mhcExport.xml

-=-
Modified: CMF/branches/1.5/CMFDefault/profiles/default/export_steps.xml
===================================================================
--- CMF/branches/1.5/CMFDefault/profiles/default/export_steps.xml	2005-10-05 10:44:00 UTC (rev 38762)
+++ CMF/branches/1.5/CMFDefault/profiles/default/export_steps.xml	2005-10-05 10:48:16 UTC (rev 38763)
@@ -1,5 +1,16 @@
 <?xml version="1.0"?>
 <export-steps>
+ <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="cookieauth"
               handler="Products.CMFSetup.cookieauth.exportCookieCrumbler"
               title="Cookie Authentication">
@@ -11,13 +22,13 @@
  
  
  </export-step>
- <export-step id="actions"
-              handler="Products.CMFSetup.actions.exportActionProviders"
-              title="Action Providers">
+ <export-step id="mailhost"
+              handler="Products.CMFSetup.mailhost.exportMailHost"
+              title="MailHost">
   
   
   
-  Export actions tool's action providers and their actions.
+  Export the mailhost's settings and properties
  
  
  
@@ -99,17 +110,4 @@
  
  
  </export-step>
-
- <export-step id="mailhost"
-              handler="Products.CMFSetup.mailhost.exportMailHost"
-              title="MailHost">
-  
-  
-  
-  Export the mailhost's settings and properties
- 
- 
- 
- </export-step>
-
 </export-steps>

Modified: CMF/branches/1.5/CMFDefault/profiles/default/import_steps.xml
===================================================================
--- CMF/branches/1.5/CMFDefault/profiles/default/import_steps.xml	2005-10-05 10:44:00 UTC (rev 38762)
+++ CMF/branches/1.5/CMFDefault/profiles/default/import_steps.xml	2005-10-05 10:48:16 UTC (rev 38763)
@@ -1,6 +1,20 @@
 <?xml version="1.0"?>
 <import-steps>
- <import-step id="cookie_authentication" version="20050903-01"
+ <import-step id="actions" version="20040630-01"
+              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="cookie_authentication"
+              version="20050903-01"
               handler="Products.CMFSetup.cookieauth.importCookieCrumbler"
               title="Cookie Authentication">
   <dependency step="toolset"/>
@@ -13,15 +27,14 @@
   
  
  </import-step>
-
- <import-step id="actions" version="20040630-01"
-              handler="Products.CMFSetup.actions.importActionProviders"
-              title="Action Providers">
+ <import-step id="mailhost" version="20050803-01"
+              handler="Products.CMFSetup.mailhost.importMailHost"
+              title="MailHost">
   <dependency step="toolset"/>
   
   
   
-  Import actions tool's action providers and their actions.
+  Import mailhost settings
  
  
   
@@ -116,17 +129,4 @@
   
  
  </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-steps>

Modified: CMF/branches/1.5/CMFDefault/profiles/default/toolset.xml
===================================================================
--- CMF/branches/1.5/CMFDefault/profiles/default/toolset.xml	2005-10-05 10:44:00 UTC (rev 38762)
+++ CMF/branches/1.5/CMFDefault/profiles/default/toolset.xml	2005-10-05 10:48:16 UTC (rev 38763)
@@ -1,6 +1,10 @@
 <?xml version="1.0"?>
 <tool-setup>
 
+ <required tool_id="MailHost"
+           class="Products.MailHost.MailHost.MailHost"/>
+ <required tool_id="cookie_authentication"
+           class="Products.CMFCore.CookieCrumbler.CookieCrumbler"/>
  <required tool_id="portal_actions"
            class="Products.CMFCore.ActionsTool.ActionsTool"/>
  <required tool_id="portal_catalog"
@@ -29,8 +33,4 @@
            class="Products.CMFCore.URLTool.URLTool"/>
  <required tool_id="portal_workflow"
            class="Products.CMFCore.WorkflowTool.WorkflowTool"/>
- <required tool_id="MailHost"
-           class="Products.MailHost.MailHost.MailHost"/>
- <required tool_id="cookie_authentication"
-           class="Products.CMFCore.CookieCrumbler.CookieCrumbler"/>
 </tool-setup>

Modified: CMF/branches/1.5/CMFSetup/cookieauth.py
===================================================================
--- CMF/branches/1.5/CMFSetup/cookieauth.py	2005-10-05 10:44:00 UTC (rev 38762)
+++ CMF/branches/1.5/CMFSetup/cookieauth.py	2005-10-05 10:48:16 UTC (rev 38763)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2004 Zope Corporation and Contributors. All Rights Reserved.
+# 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.
@@ -10,7 +10,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" CMFSetup:  Mailhost import/export
+"""Cookie crumbler setup handlers.
 
 $Id$
 """
@@ -33,45 +33,32 @@
 #
 _FILENAME = 'cookieauth.xml'
 
-def importCookieCrumbler( context ):
 
-    """ Import cookiecrumbler settings from an XML file.
+def importCookieCrumbler(context):
+    """ Import cookie crumbler settings from an XML file.
     """
     site = context.getSite()
-    encoding = context.getEncoding()
 
     if context.shouldPurge():
         # steps to follow to remove old settings
         pass
 
-    text = context.readDataFile( _FILENAME )
+    body = context.readDataFile(_FILENAME)
+    if body is None:
+        return 'Cookie crumbler: Nothing to import.'
 
-    if text is not None:
+    # now act on the settings we've retrieved
+    cc = site.cookie_authentication
+    ccc = CookieCrumblerImportConfigurator(site)
+    cc_info = ccc.parseXML(body)
 
-        ccc = CookieCrumblerImportConfigurator( site, encoding )
-        cc_info = ccc.parseXML( text )
+    for prop_info in cc_info['properties']:
+        ccc.initProperty(cc, prop_info)
 
-        # now act on the settings we've retrieved
-        cc = site.cookie_authentication
-        props = ccc.parseXML(text)
+    return 'Cookie crumbler settings imported.'
 
-        cc.auth_cookie = props['auth_cookie']
-        cc.name_cookie = props['name_cookie']
-        cc.pw_cookie = props['pw_cookie']
-        cc.persist_cookie = props['persist_cookie']
-        cc.auto_login_page = props['auto_login_page']
-        cc.logout_page = props['logout_page']
-        cc.unauth_page = props['unauth_page']
-        cc.local_cookie_path = props['local_cookie_path']
-        cc.cache_header_value = props['cache_header_value']
-        cc.log_username = props['log_username']
-
-        return 'Cookie crumbler settings imported.'
-
-
-def exportCookieCrumbler( context ):
-
-    """ Export cookiecrumbler properties as an XML file
+def exportCookieCrumbler(context):
+    """ Export cookie crumbler settings as an XML file.
     """
     site = context.getSite()
     mhc = CookieCrumblerExportConfigurator( site ).__of__( site )
@@ -79,7 +66,7 @@
 
     context.writeDataFile( _FILENAME, text, 'text/xml' )
 
-    return 'CookieCrumbler properties exported.'
+    return 'Cookie crumbler settings exported.'
 
 
 class CookieCrumblerExportConfigurator(ExportConfiguratorBase):
@@ -88,56 +75,24 @@
     security = ClassSecurityInfo()
 
     security.declareProtected( ManagePortal, 'getCookieCrumblerInfo' )
-    def getCookieCrumblerInfo( self ):
+    def getCookieCrumblerInfo(self):
         """ List the valid role IDs for our site.
         """
         cc = self._site.cookie_authentication
-        config = {}
-        config['auth_cookie'] = cc.auth_cookie
-        config['name_cookie'] = cc.name_cookie
-        config['pw_cookie'] = cc.pw_cookie
-        config['persist_cookie'] = cc.persist_cookie
-        config['auto_login_page'] = cc.auto_login_page
-        config['logout_page'] = cc.logout_page
-        config['unauth_page'] = cc.unauth_page
-        config['local_cookie_path'] = cc.local_cookie_path
-        config['cache_header_value'] = cc.cache_header_value
-        config['log_username'] = cc.log_username
-        return config
+        properties = tuple( [ self._extractProperty(cc, prop_map)
+                              for prop_map in cc._propertyMap() ] )
+        return {'id': cc.getId(), 'properties': properties}
 
     def _getExportTemplate(self):
 
         return PageTemplateFile('ccExport.xml', _xmldir)
 
-
 InitializeClass(CookieCrumblerExportConfigurator)
 
+
 class CookieCrumblerImportConfigurator(ImportConfiguratorBase):
 
     def _getImportMapping(self):
+        return {}
 
-        return {'cookiecrumbler':
-                  { 'auth_cookie': {},
-                    'name_cookie': {},
-                    'pw_cookie': {},
-                    'persist_cookie': {},
-                    'auto_login_page': {},
-                    'logout_page': {},
-                    'unauth_page': {},
-                    'local_cookie_path': {CONVERTER: self._convertToBoolean},
-                    'cache_header_value': {},
-                    'log_username': {CONVERTER: self._convertToBoolean},
-                  }
-               }
-
 InitializeClass(CookieCrumblerImportConfigurator)
-
-# BBB: will be removed in CMF 1.7
-class CookieCrumblerConfigurator(CookieCrumblerImportConfigurator,
-                                 CookieCrumblerExportConfigurator):
-    def __init__(self, site, encoding=None):
-        CookieCrumblerImportConfigurator.__init__(self, site, encoding)
-        CookieCrumblerExportConfigurator.__init__(self, site, encoding)
-
-InitializeClass(CookieCrumblerConfigurator)
-

Modified: CMF/branches/1.5/CMFSetup/mailhost.py
===================================================================
--- CMF/branches/1.5/CMFSetup/mailhost.py	2005-10-05 10:44:00 UTC (rev 38762)
+++ CMF/branches/1.5/CMFSetup/mailhost.py	2005-10-05 10:48:16 UTC (rev 38763)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2004 Zope Corporation and Contributors. All Rights Reserved.
+# 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.
@@ -10,7 +10,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" CMFSetup:  Mailhost import/export
+"""Mailhost setup handlers.
 
 $Id$
 """
@@ -33,38 +33,34 @@
 #
 _FILENAME = 'mailhost.xml'
 
-def importMailHost( context ):
 
+def importMailHost(context):
     """ Import mailhost settings from an XML file.
     """
     site = context.getSite()
-    encoding = context.getEncoding()
 
+    mailhost = getToolByName(site, 'MailHost')
     if context.shouldPurge():
         # steps to follow to remove old settings
         pass
 
-    text = context.readDataFile( _FILENAME )
+    body = context.readDataFile(_FILENAME)
+    if body is None:
+        return 'Mailhost: Nothing to import.'
 
-    if text is not None:
+    mhc = MailHostImportConfigurator(site)
+    mh_info = mhc.parseXML(body)
 
-        mhc = MailHostImportConfigurator( site, encoding )
-        mh_info = mhc.parseXML( text )
+    # now act on the settings we've retrieved
+    mailhost.smtp_host = mh_info['smtp_host']
+    mailhost.smtp_port = int(mh_info['smtp_port'])
+    mailhost.smtp_uid = mh_info['smtp_uid']
+    mailhost.smtp_pwd = mh_info['smtp_pwd']
 
-        # now act on the settings we've retrieved
-        mh = getToolByName(site, 'MailHost')
-
-        mh.smtp_host = mh_info['smtp_host']
-        mh.smtp_port = mh_info['smtp_port']
-        mh.smtp_uid = mh_info['smtp_uid']
-        mh.smtp_pwd = mh_info['smtp_pwd']
-
     return 'Mailhost settings imported.'
 
-
-def exportMailHost( context ):
-
-    """ Export mailhost properties as an XML file
+def exportMailHost(context):
+    """ Export mailhost settings as an XML file.
     """
     site = context.getSite()
     mhc = MailHostExportConfigurator( site ).__of__( site )
@@ -72,12 +68,14 @@
 
     context.writeDataFile( _FILENAME, text, 'text/xml' )
 
-    return 'MailHost properties exported.'
+    return 'MailHost settings exported.'
 
 
 class MailHostExportConfigurator(ExportConfiguratorBase):
+
     """ Synthesize XML description of mailhost properties.
     """
+
     security = ClassSecurityInfo()
 
     security.declareProtected( ManagePortal, 'getMailHostInfo' )
@@ -92,7 +90,6 @@
         config['smtp_port'] = int(mh.smtp_port)
         config['smtp_uid'] = getattr(mh, 'smtp_uid', '')
         config['smtp_pwd'] = getattr(mh, 'smtp_pwd', '')
-        config['i18n_domain'] = ''
 
         return config
 
@@ -108,27 +105,12 @@
     def _getImportMapping(self):
 
         return {
-          'mailhost':
-            { 'i18n:domain':{},
-              'id':         {},
-              'smtp_host':  {},
-              'smtp_port':  {},
-              'smtp_uid':   {},
-              'smtp_pwd':   {},
-              'xmlns:i18n': {} },
-          }
+          'object':
+            { 'name':      {KEY: 'id'},
+              'meta_type': {},
+              'smtp_host': {},
+              'smtp_port': {},
+              'smtp_uid':  {},
+              'smtp_pwd':  {} } }
 
 InitializeClass(MailHostImportConfigurator)
-
-# BBB: will be removed in CMF 1.7
-class MailHostConfigurator(MailHostImportConfigurator
-                          ,MailHostExportConfigurator
-                          ):
-
-    def __init__(self, site, encoding=None):
-        MailHostImportConfigurator.__init__(self, site, encoding=None)
-        MailHostExportConfigurator.__init__(self, site, encoding=None)
-
-InitializeClass(MailHostConfigurator)
-
-

Modified: CMF/branches/1.5/CMFSetup/tests/test_cookieauth.py
===================================================================
--- CMF/branches/1.5/CMFSetup/tests/test_cookieauth.py	2005-10-05 10:44:00 UTC (rev 38762)
+++ CMF/branches/1.5/CMFSetup/tests/test_cookieauth.py	2005-10-05 10:48:16 UTC (rev 38763)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2004 Zope Corporation and Contributors. All Rights Reserved.
+# 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.
@@ -10,70 +10,29 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" Cookiecrumbler properties export / import unit tests.
+"""Cookie crumbler setup handler unit tests.
 
 $Id$
 """
+
 import unittest
 import Testing
-try:
-    import Zope2
-except ImportError:  # BBB for Zope 2.7
-    import Zope as Zope2
-Zope2.startup()
 
 from OFS.Folder import Folder
 
+from Products.CMFCore.CookieCrumbler import CookieCrumbler
+
 from common import BaseRegistryTests
 from common import DummyExportContext
 from common import DummyImportContext
 
 
-_DEFAULT_EXPORT = """\
-<?xml version="1.0"?>
-<cookiecrumbler auth_cookie="__ac" cache_header_value="private"
-    name_cookie="__ac_name" log_username="1"
-    persist_cookie="__ac_persistent"
-    pw_cookie="__ac_password" local_cookie_path="0"
-    auto_login_page="login_form" unauth_page=""
-    logout_page="logged_out"/>
-"""
-
-_CHANGED_EXPORT = """\
-<?xml version="1.0"?>
-<cookiecrumbler auth_cookie="value1" cache_header_value="value2"
-    name_cookie="value3" log_username="0"
-    persist_cookie="value4"
-    pw_cookie="value5" local_cookie_path="1"
-    auto_login_page="value6" unauth_page="value7"
-    logout_page="value8"/>
-"""
-
-class DummySite(Folder):
-    pass
-
-
-class DummyCookieCrumbler:
-
-    auth_cookie = '__ac'
-    cache_header_value = 'private'
-    name_cookie = '__ac_name'
-    log_username = 1
-    persist_cookie = '__ac_persistent'
-    pw_cookie = '__ac_password'
-    local_cookie_path = 0
-    auto_login_page = 'login_form'
-    unauth_page = ''
-    logout_page = 'logged_out'
-
 class _CookieCrumblerSetup(BaseRegistryTests):
 
     def _initSite(self, use_changed=False):
-
-        self.root.site = DummySite()
+        self.root.site = Folder(id='site')
         site = self.root.site
-        site.cookie_authentication = DummyCookieCrumbler()
-        cc = site.cookie_authentication
+        cc = site.cookie_authentication = CookieCrumbler('foo_cookiecrumbler')
  
         if use_changed:
             cc.auth_cookie = 'value1'
@@ -89,137 +48,161 @@
 
         return site
 
-class CookieCrumblerConfiguratorTests(_CookieCrumblerSetup):
 
+class CookieCrumblerExportConfiguratorTests(_CookieCrumblerSetup):
+
     def _getTargetClass(self):
+        from Products.CMFSetup.cookieauth \
+                import CookieCrumblerExportConfigurator
 
-        from Products.CMFSetup.cookieauth import CookieCrumblerConfigurator
-        return CookieCrumblerConfigurator
+        return CookieCrumblerExportConfigurator
 
-    def test_generateXML_default( self ):
-
+    def test_generateXML_default(self):
         site = self._initSite()
-        configurator = self._makeOne( site ).__of__( site )
+        configurator = self._makeOne(site).__of__(site)
 
-        self._compareDOM( configurator.generateXML(), _DEFAULT_EXPORT )
+        self._compareDOM(configurator.generateXML(), _DEFAULT_EXPORT)
 
-    def test_generateXML_changed( self ):
-
+    def test_generateXML_changed(self):
         site = self._initSite(use_changed=True)
-        configurator = self._makeOne( site ).__of__( site )
+        configurator = self._makeOne(site).__of__(site)
 
-        self._compareDOM( configurator.generateXML(), _CHANGED_EXPORT )
+        self._compareDOM(configurator.generateXML(), _CHANGED_EXPORT)
 
-    def test_parseXML_default( self ):
 
-        site = self._initSite()
-        configurator = self._makeOne(site)
-        props = configurator.parseXML(_DEFAULT_EXPORT)
+class CookieCrumblerImportConfiguratorTests(_CookieCrumblerSetup):
 
-        self.assertEqual( props['auth_cookie'],'__ac')
-        self.assertEqual( props['cache_header_value'],'private')
-        self.assertEqual( props['name_cookie'],'__ac_name')
-        self.assertEqual( props['log_username'],1)
-        self.assertEqual( props['persist_cookie'],'__ac_persistent')
-        self.assertEqual( props['pw_cookie'],'__ac_password')
-        self.assertEqual( props['local_cookie_path'],0)
-        self.assertEqual( props['auto_login_page'],'login_form')
-        self.assertEqual( props['unauth_page'],'')
-        self.assertEqual( props['logout_page'],'logged_out')
+    def _getTargetClass(self):
+        from Products.CMFSetup.cookieauth \
+                import CookieCrumblerImportConfigurator
 
-    def test_parseXML_changed( self ):
+        return CookieCrumblerImportConfigurator
 
+    def test_parseXML_default(self):
         site = self._initSite()
         configurator = self._makeOne(site)
-        props = configurator.parseXML(_CHANGED_EXPORT)
+        cc_info = configurator.parseXML(_DEFAULT_EXPORT)
 
-        self.assertEqual( props['auth_cookie'],'value1')
-        self.assertEqual( props['cache_header_value'],'value2')
-        self.assertEqual( props['name_cookie'],'value3')
-        self.assertEqual( props['log_username'],0)
-        self.assertEqual( props['persist_cookie'],'value4')
-        self.assertEqual( props['pw_cookie'],'value5')
-        self.assertEqual( props['local_cookie_path'],1)
-        self.assertEqual( props['auto_login_page'],'value6')
-        self.assertEqual( props['unauth_page'],'value7')
-        self.assertEqual( props['logout_page'],'value8')
+        self.assertEqual(len(cc_info['properties']), 10)
 
+        info = cc_info['properties'][0]
+        self.assertEqual(info['id'], 'auth_cookie')
+        self.assertEqual(info['value'], '__ac')
+        self.assertEqual(len(info['elements']), 0)
 
-class Test_importCookieCrumbler(_CookieCrumblerSetup):
+        info = cc_info['properties'][1]
+        self.assertEqual(info['id'], 'name_cookie')
+        self.assertEqual(info['value'], '__ac_name')
+        self.assertEqual(len(info['elements']), 0)
 
-    def test_normal(self):
+    def test_parseXML_changed(self):
         site = self._initSite()
-        context = DummyImportContext(site)
-        context._files['cookieauth.xml'] = _CHANGED_EXPORT
+        configurator = self._makeOne(site)
+        cc_info = configurator.parseXML(_CHANGED_EXPORT)
 
-        from Products.CMFSetup.cookieauth import importCookieCrumbler
-        importCookieCrumbler(context)
+        self.assertEqual(len(cc_info['properties']), 10)
 
-        cc = site.cookie_authentication
-        self.assertEqual( cc.auth_cookie, 'value1' )
-        self.assertEqual( cc.cache_header_value, 'value2' )
-        self.assertEqual( cc.name_cookie, 'value3' )
-        self.assertEqual( cc.log_username, 0 )
-        self.assertEqual( cc.persist_cookie, 'value4' )
-        self.assertEqual( cc.pw_cookie, 'value5' )
-        self.assertEqual( cc.local_cookie_path, 1 )
-        self.assertEqual( cc.auto_login_page, 'value6' )
-        self.assertEqual( cc.unauth_page, 'value7' )
-        self.assertEqual( cc.logout_page, 'value8' )
+        info = cc_info['properties'][0]
+        self.assertEqual(info['id'], 'auth_cookie')
+        self.assertEqual(info['value'], 'value1')
+        self.assertEqual(len(info['elements']), 0)
 
-    def test_normal_encode_as_ascii(self):
-        site = self._initSite()
-        context = DummyImportContext(site, encoding='ascii')
-        context._files['cookieauth.xml'] = _CHANGED_EXPORT
+        info = cc_info['properties'][1]
+        self.assertEqual(info['id'], 'name_cookie')
+        self.assertEqual(info['value'], 'value3')
+        self.assertEqual(len(info['elements']), 0)
 
-        from Products.CMFSetup.cookieauth import importCookieCrumbler
-        importCookieCrumbler(context)
 
-        cc = site.cookie_authentication
-        self.assertEqual( cc.auth_cookie, 'value1' )
-        self.assertEqual( cc.cache_header_value, 'value2' )
-        self.assertEqual( cc.name_cookie, 'value3' )
-        self.assertEqual( cc.log_username, 0 )
-        self.assertEqual( cc.persist_cookie, 'value4' )
-        self.assertEqual( cc.pw_cookie, 'value5' )
-        self.assertEqual( cc.local_cookie_path, 1 )
-        self.assertEqual( cc.auto_login_page, 'value6' )
-        self.assertEqual( cc.unauth_page, 'value7' )
-        self.assertEqual( cc.logout_page, 'value8' )
+_DEFAULT_EXPORT = """\
+<?xml version="1.0"?>
+<object name="foo_cookiecrumbler" meta_type="Cookie Crumbler">
+  <property name="auth_cookie">__ac</property>
+  <property name="name_cookie">__ac_name</property>
+  <property name="pw_cookie">__ac_password</property>
+  <property name="persist_cookie">__ac_persistent</property>
+  <property name="auto_login_page">login_form</property>
+  <property name="logout_page">logged_out</property>
+  <property name="unauth_page"></property>
+  <property name="local_cookie_path">0</property>
+  <property name="cache_header_value">private</property>
+  <property name="log_username">1</property>
+</object>
+"""
 
+_CHANGED_EXPORT = """\
+<?xml version="1.0"?>
+<object name="foo_cookiecrumbler" meta_type="Cookie Crumbler">
+  <property name="auth_cookie">value1</property>
+  <property name="name_cookie">value3</property>
+  <property name="pw_cookie">value5</property>
+  <property name="persist_cookie">value4</property>
+  <property name="auto_login_page">value6</property>
+  <property name="logout_page">value8</property>
+  <property name="unauth_page">value7</property>
+  <property name="local_cookie_path">1</property>
+  <property name="cache_header_value">value2</property>
+  <property name="log_username">0</property>
+</object>
+"""
 
+
 class Test_exportCookieCrumbler(_CookieCrumblerSetup):
 
     def test_unchanged(self):
-        site = self._initSite( use_changed=False )
-        context = DummyExportContext(site)
-
         from Products.CMFSetup.cookieauth import exportCookieCrumbler
+
+        site = self._initSite(use_changed=False)
+        context = DummyExportContext(site)
         exportCookieCrumbler(context)
 
-        self.assertEqual( len(context._wrote), 1 )
+        self.assertEqual(len(context._wrote), 1)
         filename, text, content_type = context._wrote[0]
         self.assertEqual(filename, 'cookieauth.xml')
         self._compareDOM(text, _DEFAULT_EXPORT)
         self.assertEqual(content_type, 'text/xml')
 
     def test_changed(self):
-        site = self._initSite( use_changed=True )
-        context = DummyExportContext( site )
-
         from Products.CMFSetup.cookieauth import exportCookieCrumbler
+
+        site = self._initSite(use_changed=True)
+        context = DummyExportContext(site)
         exportCookieCrumbler(context)
 
-        self.assertEqual( len(context._wrote), 1 )
+        self.assertEqual(len(context._wrote), 1)
         filename, text, content_type = context._wrote[0]
         self.assertEqual(filename, 'cookieauth.xml')
         self._compareDOM(text, _CHANGED_EXPORT)
         self.assertEqual(content_type, 'text/xml')
 
 
+class Test_importCookieCrumbler(_CookieCrumblerSetup):
+
+    def test_normal(self):
+        from Products.CMFSetup.cookieauth import importCookieCrumbler
+
+        site = self._initSite()
+        cc = site.cookie_authentication
+
+        context = DummyImportContext(site)
+        context._files['cookieauth.xml'] = _CHANGED_EXPORT
+        importCookieCrumbler(context)
+
+        self.assertEqual( cc.auth_cookie, 'value1' )
+        self.assertEqual( cc.cache_header_value, 'value2' )
+        self.assertEqual( cc.name_cookie, 'value3' )
+        self.assertEqual( cc.log_username, 0 )
+        self.assertEqual( cc.persist_cookie, 'value4' )
+        self.assertEqual( cc.pw_cookie, 'value5' )
+        self.assertEqual( cc.local_cookie_path, 1 )
+        self.assertEqual( cc.auto_login_page, 'value6' )
+        self.assertEqual( cc.unauth_page, 'value7' )
+        self.assertEqual( cc.logout_page, 'value8' )
+
+
 def test_suite():
     return unittest.TestSuite((
-        unittest.makeSuite(CookieCrumblerConfiguratorTests),
+        unittest.makeSuite(CookieCrumblerExportConfiguratorTests),
+        unittest.makeSuite(CookieCrumblerImportConfiguratorTests),
         unittest.makeSuite(Test_exportCookieCrumbler),
         unittest.makeSuite(Test_importCookieCrumbler),
         ))

Modified: CMF/branches/1.5/CMFSetup/tests/test_mailhost.py
===================================================================
--- CMF/branches/1.5/CMFSetup/tests/test_mailhost.py	2005-10-05 10:44:00 UTC (rev 38762)
+++ CMF/branches/1.5/CMFSetup/tests/test_mailhost.py	2005-10-05 10:48:16 UTC (rev 38763)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2004 Zope Corporation and Contributors. All Rights Reserved.
+# 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.
@@ -10,60 +10,28 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" MailHost properties export / import unit tests.
+"""Mailhost setup handler unit tests.
 
 $Id$
 """
+
 import unittest
 import Testing
-try:
-    import Zope2
-except ImportError:  # BBB for Zope 2.7
-    import Zope as Zope2
-Zope2.startup()
 
 from OFS.Folder import Folder
+from Products.MailHost.MailHost import MailHost
 
 from common import BaseRegistryTests
 from common import DummyExportContext
 from common import DummyImportContext
 
 
-_DEFAULT_EXPORT = """\
-<?xml version="1.0"?>
-<mailhost id="MailHost" smtp_pwd="" smtp_port="25"
-          smtp_host="localhost.localdomain" i18n:domain="" smtp_uid=""
-          xmlns:i18n="http://xml.zope.org/namespaces/i18n"/>
-"""
-
-_CHANGED_EXPORT = """\
-<?xml version="1.0"?>
-<mailhost id="MailHost" smtp_pwd="value1" smtp_port="1"
-          smtp_host="value2" i18n:domain="" smtp_uid="value3"
-          xmlns:i18n="http://xml.zope.org/namespaces/i18n"/>
-"""
-
-class DummySite(Folder):
-    pass
-
-
-class DummyMailHost:
-
-    smtp_port='25'
-    smtp_host="localhost.localdomain"
-    id='MailHost'
-
-    def getId(self):
-       return self.id
-
 class _MailHostSetup(BaseRegistryTests):
 
     def _initSite(self, use_changed=False):
-
-        self.root.site = DummySite()
+        self.root.site = Folder(id='site')
         site = self.root.site
-        site.MailHost = DummyMailHost()
-        mh = site.MailHost
+        mh = site.MailHost = MailHost('MailHost')
  
         if use_changed:
            mh.smtp_port='1'
@@ -71,116 +39,123 @@
            mh.smtp_host="value2"
            mh.smtp_uid="value3"
 
-
         return site
 
-class MailHostConfiguratorTests(_MailHostSetup):
 
+class MailHostExportConfiguratorTests(_MailHostSetup):
+
     def _getTargetClass(self):
+        from Products.CMFSetup.mailhost import MailHostExportConfigurator
 
-        from Products.CMFSetup.mailhost import MailHostConfigurator
-        return MailHostConfigurator
+        return MailHostExportConfigurator
 
-    def test_generateXML_default( self ):
-
+    def test_generateXML_default(self):
         site = self._initSite()
-        configurator = self._makeOne( site ).__of__( site )
+        configurator = self._makeOne(site).__of__(site)
 
-        self._compareDOM( configurator.generateXML(), _DEFAULT_EXPORT )
+        self._compareDOM(configurator.generateXML(), _DEFAULT_EXPORT)
 
-    def test_generateXML_changed( self ):
-
+    def test_generateXML_changed(self):
         site = self._initSite(use_changed=True)
-        configurator = self._makeOne( site ).__of__( site )
+        configurator = self._makeOne(site).__of__(site)
 
-        self._compareDOM( configurator.generateXML(), _CHANGED_EXPORT )
+        self._compareDOM(configurator.generateXML(), _CHANGED_EXPORT)
 
-    def test_parseXML_default( self ):
 
+class MailHostImportConfiguratorTests(_MailHostSetup):
+
+    def _getTargetClass(self):
+        from Products.CMFSetup.mailhost import MailHostImportConfigurator
+
+        return MailHostImportConfigurator
+
+    def test_parseXML_default(self):
         site = self._initSite()
         configurator = self._makeOne(site)
         props = configurator.parseXML(_DEFAULT_EXPORT)
 
-        self.assertEqual( props['smtp_port'],'25')
-        self.assertEqual( props['smtp_host'],'localhost.localdomain')
-        self.assertEqual( props['smtp_uid'],'')
-        self.assertEqual( props['smtp_pwd'],'')
+        self.assertEqual(props['smtp_port'], '25')
+        self.assertEqual(props['smtp_host'], 'localhost')
+        self.assertEqual(props['smtp_uid'], '')
+        self.assertEqual(props['smtp_pwd'], '')
 
-    def test_parseXML_changed( self ):
-
+    def test_parseXML_changed(self):
         site = self._initSite()
         configurator = self._makeOne(site)
         props = configurator.parseXML(_CHANGED_EXPORT)
 
-        self.assertEqual( props['smtp_pwd'], 'value1' )
-        self.assertEqual( props['smtp_host'], 'value2' )
-        self.assertEqual( props['smtp_uid'], 'value3' )
-        self.assertEqual( props['smtp_port'], '1' )
+        self.assertEqual(props['smtp_pwd'], 'value1')
+        self.assertEqual(props['smtp_host'], 'value2')
+        self.assertEqual(props['smtp_uid'], 'value3')
+        self.assertEqual(props['smtp_port'], '1')
 
 
-class Test_importMailHost(_MailHostSetup):
+_DEFAULT_EXPORT = """\
+<?xml version="1.0"?>
+<object name="MailHost" meta_type="Mail Host"
+        smtp_host="localhost" smtp_port="25" smtp_pwd=""
+        smtp_uid=""/>
+"""
 
-    def test_normal(self):
-        site = self._initSite()
-        context = DummyImportContext(site)
-        context._files['mailhost.xml'] = _CHANGED_EXPORT
+_CHANGED_EXPORT = """\
+<?xml version="1.0"?>
+<object name="MailHost" meta_type="Mail Host"
+        smtp_host="value2" smtp_port="1" smtp_pwd="value1"
+        smtp_uid="value3"/>
+"""
 
-        from Products.CMFSetup.mailhost import importMailHost
-        importMailHost(context)
 
-        mh = site.MailHost
-        self.assertEqual( mh.smtp_pwd, 'value1' )
-        self.assertEqual( mh.smtp_host, 'value2' )
-        self.assertEqual( mh.smtp_uid, 'value3' )
-        self.assertEqual( mh.smtp_port, '1' )
-
-    def test_normal_encode_as_ascii(self):
-        site = self._initSite()
-        context = DummyImportContext(site, encoding='ascii')
-        context._files['mailhost.xml'] = _CHANGED_EXPORT
-
-        from Products.CMFSetup.mailhost import importMailHost
-        importMailHost(context)
-
-        mh = site.MailHost
-        self.assertEqual( mh.smtp_pwd, 'value1' )
-        self.assertEqual( mh.smtp_host, 'value2' )
-        self.assertEqual( mh.smtp_uid, 'value3' )
-        self.assertEqual( mh.smtp_port, '1' )
-
-
 class Test_exportMailHost(_MailHostSetup):
 
     def test_unchanged(self):
-        site = self._initSite( use_changed=False )
-        context = DummyExportContext(site)
-
         from Products.CMFSetup.mailhost import exportMailHost
+
+        site = self._initSite(use_changed=False)
+        context = DummyExportContext(site)
         exportMailHost(context)
 
-        self.assertEqual( len(context._wrote), 1 )
+        self.assertEqual(len(context._wrote), 1)
         filename, text, content_type = context._wrote[0]
         self.assertEqual(filename, 'mailhost.xml')
         self._compareDOM(text, _DEFAULT_EXPORT)
         self.assertEqual(content_type, 'text/xml')
 
     def test_changed(self):
-        site = self._initSite( use_changed=True )
-        context = DummyExportContext( site )
-
         from Products.CMFSetup.mailhost import exportMailHost
+
+        site = self._initSite(use_changed=True)
+        context = DummyExportContext(site)
         exportMailHost(context)
 
-        self.assertEqual( len(context._wrote), 1 )
+        self.assertEqual(len(context._wrote), 1)
         filename, text, content_type = context._wrote[0]
         self.assertEqual(filename, 'mailhost.xml')
         self._compareDOM(text, _CHANGED_EXPORT)
         self.assertEqual(content_type, 'text/xml')
 
 
+class Test_importMailHost(_MailHostSetup):
+
+    def test_normal(self):
+        from Products.CMFSetup.mailhost import importMailHost
+
+        site = self._initSite()
+        mh = site.MailHost
+
+        context = DummyImportContext(site)
+        context._files['mailhost.xml'] = _CHANGED_EXPORT
+        importMailHost(context)
+
+        self.assertEqual( mh.smtp_pwd, 'value1' )
+        self.assertEqual( mh.smtp_host, 'value2' )
+        self.assertEqual( mh.smtp_uid, 'value3' )
+        self.assertEqual( mh.smtp_port, 1 )
+
+
 def test_suite():
     return unittest.TestSuite((
-        unittest.makeSuite(MailHostConfiguratorTests),
+        unittest.makeSuite(MailHostExportConfiguratorTests),
+        unittest.makeSuite(MailHostImportConfiguratorTests),
         unittest.makeSuite(Test_exportMailHost),
         unittest.makeSuite(Test_importMailHost),
         ))

Modified: CMF/branches/1.5/CMFSetup/xml/ccExport.xml
===================================================================
--- CMF/branches/1.5/CMFSetup/xml/ccExport.xml	2005-10-05 10:44:00 UTC (rev 38762)
+++ CMF/branches/1.5/CMFSetup/xml/ccExport.xml	2005-10-05 10:48:16 UTC (rev 38763)
@@ -1,13 +1,8 @@
 <?xml version="1.0"?>
-<cookiecrumbler xmlns:tal="http://xml.zope.org/namespaces/tal"
-    tal:define="cc_info context/getCookieCrumblerInfo"
-    tal:attributes="auth_cookie cc_info/auth_cookie;
-                    name_cookie cc_info/name_cookie;
-                    pw_cookie cc_info/pw_cookie;
-                    persist_cookie cc_info/persist_cookie;
-                    auto_login_page cc_info/auto_login_page;
-                    logout_page cc_info/logout_page;
-                    unauth_page cc_info/unauth_page;
-                    local_cookie_path cc_info/local_cookie_path;
-                    cache_header_value cc_info/cache_header_value;
-                    log_username cc_info/log_username;" />
+<object xmlns:tal="http://xml.zope.org/namespaces/tal"
+   name="ID" meta_type="Cookie Crumbler"
+   tal:define="cc_info context/getCookieCrumblerInfo"
+   tal:attributes="name cc_info/id"
+><tal:span tal:define="prop_infos cc_info/properties"
+   tal:replace="structure python: context.generatePropertyNodes(prop_infos)"/>
+</object>

Modified: CMF/branches/1.5/CMFSetup/xml/mhcExport.xml
===================================================================
--- CMF/branches/1.5/CMFSetup/xml/mhcExport.xml	2005-10-05 10:44:00 UTC (rev 38762)
+++ CMF/branches/1.5/CMFSetup/xml/mhcExport.xml	2005-10-05 10:48:16 UTC (rev 38763)
@@ -1,12 +1,10 @@
 <?xml version="1.0"?>
-<mailhost xmlns:tal="http://xml.zope.org/namespaces/tal"
-          id="some_id"
-          tal:define="mh_info here/getMailHostInfo"
-          tal:attributes="xmlns:i18n string:http://xml.zope.org/namespaces/i18n;
-                          i18n:domain mh_info/i18n_domain;
-                          id mh_info/id;
-                          smtp_host mh_info/smtp_host;
-                          smtp_port mh_info/smtp_port;
-                          smtp_uid mh_info/smtp_uid;
-                          smtp_pwd mh_info/smtp_pwd;" />
-
+<object xmlns:tal="http://xml.zope.org/namespaces/tal"
+   name="some_id" meta_type="Mail Host" smtp_host="localhost"
+   smtp_port="25" smtp_pwd="" smtp_uid=""
+   tal:define="mh_info context/getMailHostInfo"
+   tal:attributes="name mh_info/id;
+                   smtp_host mh_info/smtp_host;
+                   smtp_port mh_info/smtp_port;
+                   smtp_uid mh_info/smtp_uid;
+                   smtp_pwd mh_info/smtp_pwd;" />



More information about the CMF-checkins mailing list