Back to index

plone3  3.1.7
test_PropertiesTool.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for PropertiesTool module.
00014 
00015 $Id: test_PropertiesTool.py 82567 2007-12-30 11:31:06Z jens $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from zope.component import getSiteManager
00022 from zope.component import getUtility
00023 from zope.testing.cleanup import cleanUp
00024 
00025 from OFS.PropertyManager import PropertyManager
00026 
00027 from Products.MailHost.interfaces import IMailHost
00028 from Products.MailHost.MailHost import MailHost
00029 
00030 from Products.CMFCore.interfaces import IPropertiesTool
00031 from Products.CMFCore.interfaces import ISiteRoot
00032 from Products.CMFCore.tests.base.dummy import DummySite
00033 from Products.CMFCore.tests.base.testcase import SecurityTest
00034 
00035 class PropertiedDummySite(PropertyManager, DummySite):
00036     _properties = (
00037         {'id':'title', 'type':'string', 'mode': 'w'},
00038         {'id':'description', 'type':'text', 'mode': 'w'},
00039         {'id':'email_from_address', 'type':'string', 'mode': 'w'},
00040         {'id':'email_from_name', 'type':'string', 'mode': 'w'},
00041         {'id':'validate_email', 'type':'boolean', 'mode': 'w'},
00042         {'id':'default_charset', 'type':'string', 'mode': 'w'},
00043         {'id':'email_charset', 'type':'string', 'mode': 'w'},
00044         {'id':'enable_permalink', 'type':'boolean', 'mode': 'w'},
00045         )
00046     title = description = email_from_address = email_from_name = ''
00047     default_charset = email_charset = ''
00048     validate_email = enable_permalink = False
00049 
00050 
00051 class PropertiesToolTests(SecurityTest):
00052 
00053     def _makeOne(self, *args, **kw):
00054         from Products.CMFDefault.PropertiesTool import PropertiesTool
00055 
00056         return PropertiesTool(*args, **kw)
00057 
00058     def setUp(self):
00059         SecurityTest.setUp(self)
00060         self.site = PropertiedDummySite('site')
00061         sm = getSiteManager()
00062         sm.registerUtility(self.site, ISiteRoot)
00063         self.site._setObject('portal_properties', self._makeOne())
00064         sm.registerUtility(self.site.portal_properties, IPropertiesTool)
00065         self.site._setObject('MailHost', MailHost('MailHost'))
00066         sm.registerUtility(self.site.MailHost, IMailHost)
00067 
00068     def tearDown(self):
00069         cleanUp()
00070         SecurityTest.tearDown(self)
00071 
00072     def test_z2interfaces(self):
00073         from Interface.Verify import verifyClass
00074         from Products.CMFCore.interfaces.portal_properties \
00075                 import portal_properties as IPropertiesTool
00076         from Products.CMFDefault.PropertiesTool import PropertiesTool
00077 
00078         verifyClass(IPropertiesTool, PropertiesTool)
00079 
00080     def test_z3interfaces(self):
00081         from zope.interface.verify import verifyClass
00082         from Products.CMFCore.interfaces import IPropertiesTool
00083         from Products.CMFDefault.PropertiesTool import PropertiesTool
00084 
00085         verifyClass(IPropertiesTool, PropertiesTool)
00086 
00087     def test_editProperties(self):
00088         # https://bugs.launchpad.net/zope-cmf/+bug/174246
00089         # PropertiesTool.editProperties fails with traceback due to
00090         # faulty invocation of the site's manage_changeProperties method
00091         props = { 'email_from_name' : 'Test Admin'
00092                 , 'email_from_address' : 'test@example.com'
00093                 , 'description' : 'Test MailHost Description'
00094                 , 'title' : 'Test MailHost'
00095                 , 'smtp_server' : 'mail.example.com'
00096                 , 'validate_email' : True
00097                 , 'email_charset' : 'iso-8859-15'
00098                 , 'default_charset' : 'iso-8859-1'
00099                 , 'enable_permalink' : True
00100                 }
00101         tool = getUtility(IPropertiesTool)
00102         tool.editProperties(props)
00103 
00104         site_prop = self.site.getProperty
00105         self.assertEquals(getUtility(IMailHost).smtp_host, 'mail.example.com')
00106         self.assertEquals(site_prop('email_from_name'), 'Test Admin')
00107         self.assertEquals(site_prop('email_from_address'), 'test@example.com')
00108         self.assertEquals(site_prop('description'), 'Test MailHost Description')
00109         self.assertEquals(site_prop('title'), 'Test MailHost')
00110         self.assertEquals(site_prop('validate_email'), True)
00111         self.assertEquals(site_prop('email_charset'), 'iso-8859-15')
00112         self.assertEquals(site_prop('default_charset'), 'iso-8859-1')
00113         self.assertEquals(site_prop('enable_permalink'), True)
00114 
00115 
00116 def test_suite():
00117     return unittest.TestSuite((
00118         unittest.makeSuite(PropertiesToolTests),
00119         ))
00120 
00121 if __name__ == '__main__':
00122     unittest.main(defaultTest='test_suite')