Log message for revision 38552: CMFSetup: added support for configuring cookie auth and mailhost tools http://www.zope.org/Collectors/CMF/387
Changed: U CMF/branches/1.5/CHANGES.txt 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/README.txt A CMF/branches/1.5/CMFSetup/cookieauth.py A CMF/branches/1.5/CMFSetup/mailhost.py A CMF/branches/1.5/CMFSetup/tests/test_cookiecrumbler.py A CMF/branches/1.5/CMFSetup/tests/test_mailhost.py A CMF/branches/1.5/CMFSetup/xml/ccExport.xml A CMF/branches/1.5/CMFSetup/xml/mhcExport.xml -=- Modified: CMF/branches/1.5/CHANGES.txt =================================================================== --- CMF/branches/1.5/CHANGES.txt 2005-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CHANGES.txt 2005-09-21 09:48:47 UTC (rev 38552) @@ -13,6 +13,9 @@ Features + - CMFSetup: added support for configuring cookie authentication and + mailhost tools (http://www.zope.org/Collectors/CMF/387). + - CMFCore.CachingPolicyManager: Caching policies can now control all the Cache-Control tokens defined in the HTTP 1.1 spec (s-maxage, public, private, no-transform). When no-cache is enabled, a Pragma: no-cache Modified: CMF/branches/1.5/CMFDefault/profiles/default/export_steps.xml =================================================================== --- CMF/branches/1.5/CMFDefault/profiles/default/export_steps.xml 2005-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFDefault/profiles/default/export_steps.xml 2005-09-21 09:48:47 UTC (rev 38552) @@ -1,5 +1,16 @@ <?xml version="1.0"?> <export-steps> + <export-step id="cookieauth" + handler="Products.CMFSetup.cookieauth.exportCookieCrumbler" + title="Cookie Authentication"> + + + + Export cookie crumbler settings + + + + </export-step> <export-step id="actions" handler="Products.CMFSetup.actions.exportActionProviders" title="Action Providers"> @@ -88,4 +99,17 @@ </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-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFDefault/profiles/default/import_steps.xml 2005-09-21 09:48:47 UTC (rev 38552) @@ -1,5 +1,19 @@ <?xml version="1.0"?> <import-steps> + <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="actions" version="20040630-01" handler="Products.CMFSetup.actions.importActionProviders" title="Action Providers"> @@ -102,4 +116,17 @@ </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-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFDefault/profiles/default/toolset.xml 2005-09-21 09:48:47 UTC (rev 38552) @@ -29,4 +29,8 @@ 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/README.txt =================================================================== --- CMF/branches/1.5/CMFSetup/README.txt 2005-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFSetup/README.txt 2005-09-21 09:48:47 UTC (rev 38552) @@ -82,11 +82,11 @@ o action title / icon bindings - - (_) 'cookie_authentication' + - (x) 'cookie_authentication' o tool properties - - (_) 'MailHost' + - (x) 'MailHost' o tool properties Added: CMF/branches/1.5/CMFSetup/cookieauth.py =================================================================== --- CMF/branches/1.5/CMFSetup/cookieauth.py 2005-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFSetup/cookieauth.py 2005-09-21 09:48:47 UTC (rev 38552) @@ -0,0 +1,143 @@ +############################################################################## +# +# 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: Mailhost import/export + +$Id: mailhost.py 36704 2004-12-14 20:56:58Z yuppie $ +""" + +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 _xmldir +from utils import ExportConfiguratorBase, ImportConfiguratorBase +from utils import CONVERTER, DEFAULT, KEY + + +# +# Configurator entry points +# +_FILENAME = 'cookieauth.xml' + +def importCookieCrumbler( context ): + + """ Import cookiecrumbler 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 ) + + if text is not None: + + ccc = CookieCrumblerImportConfigurator( site, encoding ) + cc_info = ccc.parseXML( text ) + + # now act on the settings we've retrieved + cc = site.cookie_authentication + props = ccc.parseXML(text) + + 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 + """ + site = context.getSite() + mhc = CookieCrumblerExportConfigurator( site ).__of__( site ) + text = mhc.generateXML() + + context.writeDataFile( _FILENAME, text, 'text/xml' ) + + return 'CookieCrumbler properties exported.' + + +class CookieCrumblerExportConfigurator(ExportConfiguratorBase): + """ Synthesize XML description of cc properties. + """ + security = ClassSecurityInfo() + + security.declareProtected( ManagePortal, 'getCookieCrumblerInfo' ) + 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 + + def _getExportTemplate(self): + + return PageTemplateFile('ccExport.xml', _xmldir) + + +InitializeClass(CookieCrumblerExportConfigurator) + +class CookieCrumblerImportConfigurator(ImportConfiguratorBase): + + def _getImportMapping(self): + + return {'cc': + { '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) + Added: CMF/branches/1.5/CMFSetup/mailhost.py =================================================================== --- CMF/branches/1.5/CMFSetup/mailhost.py 2005-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFSetup/mailhost.py 2005-09-21 09:48:47 UTC (rev 38552) @@ -0,0 +1,134 @@ +############################################################################## +# +# 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: Mailhost import/export + +$Id: mailhost.py 36704 2004-12-14 20:56:58Z yuppie $ +""" + +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 _xmldir +from utils import ExportConfiguratorBase, ImportConfiguratorBase +from utils import CONVERTER, DEFAULT, KEY + + +# +# Configurator entry points +# +_FILENAME = 'mailhost.xml' + +def importMailHost( context ): + + """ Import mailhost 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 ) + + if text is not None: + + mhc = MailHostImportConfigurator( site, encoding ) + mh_info = mhc.parseXML( text ) + + # 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 + """ + site = context.getSite() + mhc = MailHostExportConfigurator( site ).__of__( site ) + text = mhc.generateXML() + + context.writeDataFile( _FILENAME, text, 'text/xml' ) + + return 'MailHost properties exported.' + + +class MailHostExportConfigurator(ExportConfiguratorBase): + """ Synthesize XML description of mailhost properties. + """ + security = ClassSecurityInfo() + + security.declareProtected( ManagePortal, 'getMailHostInfo' ) + def getMailHostInfo( self ): + """ List the valid role IDs for our site. + """ + mh = getToolByName(self._site, 'MailHost') + + config = {} + config['id'] = mh.getId() + config['smtp_host'] = mh.smtp_host + config['smtp_port'] = int(mh.smtp_port) + config['smtp_uid'] = mh.smtp_uid + config['smtp_pwd'] = mh.smtp_pwd + config['i18n_domain'] = '' + + return config + + def _getExportTemplate(self): + + return PageTemplateFile('mhcExport.xml', _xmldir) + +InitializeClass(MailHostExportConfigurator) + + +class MailHostImportConfigurator(ImportConfiguratorBase): + + def _getImportMapping(self): + + return { + 'mailhost': + { 'i18n:domain':{}, + 'id': {}, + 'smtp_host': {}, + 'smtp_port': {}, + 'smtp_uid': {}, + 'smtp_pwd': {}, + 'xmlns:i18n': {} }, + } + +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) + + Added: CMF/branches/1.5/CMFSetup/tests/test_cookiecrumbler.py =================================================================== --- CMF/branches/1.5/CMFSetup/tests/test_cookiecrumbler.py 2005-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFSetup/tests/test_cookiecrumbler.py 2005-09-21 09:48:47 UTC (rev 38552) @@ -0,0 +1,228 @@ +############################################################################## +# +# 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. +# +############################################################################## +""" Cookiecrumbler properties export / import unit tests. + +$Id: test_cookiecrumbler.py 37061 2005-06-15 14:17:41Z tseaver $ +""" +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 common import BaseRegistryTests +from common import DummyExportContext +from common import DummyImportContext + + +_DEFAULT_EXPORT = """\ +<?xml version="1.0"?> +<cc 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"?> +<cc 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() + site = self.root.site + site.cookie_authentication = DummyCookieCrumbler() + cc = site.cookie_authentication + + if use_changed: + cc.auth_cookie = 'value1' + cc.cache_header_value = 'value2' + cc.name_cookie = 'value3' + cc.log_username = 0 + cc.persist_cookie = 'value4' + cc.pw_cookie = 'value5' + cc.local_cookie_path = 1 + cc.auto_login_page = 'value6' + cc.unauth_page = 'value7' + cc.logout_page = 'value8' + + return site + +class CookieCrumblerConfiguratorTests(_CookieCrumblerSetup): + + def _getTargetClass(self): + + from Products.CMFSetup.cookieauth import CookieCrumblerConfigurator + return CookieCrumblerConfigurator + + def test_generateXML_default( self ): + + site = self._initSite() + configurator = self._makeOne( site ).__of__( site ) + + self._compareDOM( configurator.generateXML(), _DEFAULT_EXPORT ) + + def test_generateXML_changed( self ): + + site = self._initSite(use_changed=True) + configurator = self._makeOne( site ).__of__( site ) + + self._compareDOM( configurator.generateXML(), _CHANGED_EXPORT ) + + def test_parseXML_default( self ): + + site = self._initSite() + configurator = self._makeOne(site) + props = configurator.parseXML(_DEFAULT_EXPORT) + + 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 test_parseXML_changed( self ): + + site = self._initSite() + configurator = self._makeOne(site) + props = configurator.parseXML(_CHANGED_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') + + +class Test_importCookieCrumbler(_CookieCrumblerSetup): + + def test_normal(self): + site = self._initSite() + context = DummyImportContext(site) + context._files['cookieauth.xml'] = _CHANGED_EXPORT + + 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' ) + + def test_normal_encode_as_ascii(self): + site = self._initSite() + context = DummyImportContext(site, encoding='ascii') + context._files['cookieauth.xml'] = _CHANGED_EXPORT + + 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' ) + + +class Test_exportCookieCrumbler(_CookieCrumblerSetup): + + def test_unchanged(self): + site = self._initSite( use_changed=False ) + context = DummyExportContext(site) + + from Products.CMFSetup.cookieauth import exportCookieCrumbler + exportCookieCrumbler(context) + + 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 + exportCookieCrumbler(context) + + 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') + + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(CookieCrumblerConfiguratorTests), + unittest.makeSuite(Test_exportCookieCrumbler), + unittest.makeSuite(Test_importCookieCrumbler), + )) + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') Added: CMF/branches/1.5/CMFSetup/tests/test_mailhost.py =================================================================== --- CMF/branches/1.5/CMFSetup/tests/test_mailhost.py 2005-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFSetup/tests/test_mailhost.py 2005-09-21 09:48:47 UTC (rev 38552) @@ -0,0 +1,191 @@ +############################################################################## +# +# 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. +# +############################################################################## +""" MailHost properties export / import unit tests. + +$Id: test_mailhost.py 37061 2005-06-15 14:17:41Z tseaver $ +""" +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 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" + smtp_uid="" + smtp_pwd="" + id='MailHost' + + def getId(self): + return self.id + +class _MailHostSetup(BaseRegistryTests): + + def _initSite(self, use_changed=False): + + self.root.site = DummySite() + site = self.root.site + site.MailHost = DummyMailHost() + mh = site.MailHost + + if use_changed: + mh.smtp_port='1' + mh.smtp_pwd="value1" + mh.smtp_host="value2" + mh.smtp_uid="value3" + + + return site + +class MailHostConfiguratorTests(_MailHostSetup): + + def _getTargetClass(self): + + from Products.CMFSetup.mailhost import MailHostConfigurator + return MailHostConfigurator + + def test_generateXML_default( self ): + + site = self._initSite() + configurator = self._makeOne( site ).__of__( site ) + + self._compareDOM( configurator.generateXML(), _DEFAULT_EXPORT ) + + def test_generateXML_changed( self ): + + site = self._initSite(use_changed=True) + configurator = self._makeOne( site ).__of__( site ) + + self._compareDOM( configurator.generateXML(), _CHANGED_EXPORT ) + + 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'],'') + + 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' ) + + +class Test_importMailHost(_MailHostSetup): + + def test_normal(self): + site = self._initSite() + context = DummyImportContext(site) + 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' ) + + 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 + exportMailHost(context) + + 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 + exportMailHost(context) + + 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') + + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(MailHostConfiguratorTests), + unittest.makeSuite(Test_exportMailHost), + unittest.makeSuite(Test_importMailHost), + )) + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') Added: CMF/branches/1.5/CMFSetup/xml/ccExport.xml =================================================================== --- CMF/branches/1.5/CMFSetup/xml/ccExport.xml 2005-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFSetup/xml/ccExport.xml 2005-09-21 09:48:47 UTC (rev 38552) @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<cc 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;" /> Added: CMF/branches/1.5/CMFSetup/xml/mhcExport.xml =================================================================== --- CMF/branches/1.5/CMFSetup/xml/mhcExport.xml 2005-09-20 20:50:17 UTC (rev 38551) +++ CMF/branches/1.5/CMFSetup/xml/mhcExport.xml 2005-09-21 09:48:47 UTC (rev 38552) @@ -0,0 +1,12 @@ +<?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;" /> + _______________________________________________ CMF-checkins mailing list [email protected] http://mail.zope.org/mailman/listinfo/cmf-checkins
