Back to index

plone3  3.1.7
test_SyndicationTool.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 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 SyndicationTool module.
00014 
00015 $Id: test_SyndicationTool.py 77004 2007-06-24 08:57:54Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from DateTime.DateTime import DateTime
00022 from zope.testing.cleanup import cleanUp
00023 
00024 from Products.CMFCore.tests.base.testcase import SecurityTest
00025 
00026 
00027 class Dummy:
00028 
00029     def getId(self):
00030         return 'dummy'
00031 
00032 
00033 class SyndicationToolTests(SecurityTest):
00034 
00035     def _getTargetClass(self):
00036         from Products.CMFDefault.SyndicationTool import SyndicationTool
00037         return SyndicationTool
00038 
00039     def _makeOne(self, *args, **kw):
00040         return self._getTargetClass()(*args, **kw)
00041 
00042     def tearDown(self):
00043         cleanUp()
00044         SecurityTest.tearDown(self)
00045 
00046     def test_empty(self):
00047         ONE_MINUTE = (24.0 * 60.0) / 86400
00048 
00049         tool = self._makeOne()
00050 
00051         self.assertEqual(tool.syUpdatePeriod, 'daily')
00052         self.assertEqual(tool.syUpdateFrequency, 1)
00053         self.failUnless(DateTime() - tool.syUpdateBase < ONE_MINUTE)
00054         self.failIf(tool.isAllowed)
00055         self.assertEqual(tool.max_items, 15)
00056 
00057     def test_editProperties_normal(self):
00058         PERIOD = 'hourly'
00059         FREQUENCY = 4
00060         NOW = DateTime()
00061         MAX_ITEMS = 42
00062 
00063         tool = self._makeOne()
00064         tool.editProperties(updatePeriod=PERIOD,
00065                             updateFrequency=FREQUENCY,
00066                             updateBase=NOW,
00067                             isAllowed=True,
00068                             max_items=MAX_ITEMS,
00069                            )
00070 
00071         self.assertEqual(tool.syUpdatePeriod, PERIOD)
00072         self.assertEqual(tool.syUpdateFrequency, FREQUENCY)
00073         self.assertEqual(tool.syUpdateBase, NOW)
00074         self.failUnless(tool.isAllowed)
00075         self.assertEqual(tool.max_items, MAX_ITEMS)
00076 
00077     def test_editProperties_coercing(self):
00078         PERIOD = 'hourly'
00079         FREQUENCY = 4
00080         NOW = DateTime()
00081         MAX_ITEMS = 42
00082 
00083         tool = self._makeOne()
00084         tool.editProperties(updatePeriod=PERIOD,
00085                             updateFrequency='%d' % FREQUENCY,
00086                             updateBase=NOW.ISO(),
00087                             isAllowed='True',
00088                             max_items='%d' % MAX_ITEMS,
00089                            )
00090 
00091         self.assertEqual(tool.syUpdatePeriod, PERIOD)
00092         self.assertEqual(tool.syUpdateFrequency, FREQUENCY)
00093         self.assertEqual(tool.syUpdateBase, DateTime(NOW.ISO()))
00094         self.failUnless(tool.isAllowed)
00095         self.assertEqual(tool.max_items, MAX_ITEMS)
00096 
00097     def test_editSyInformationProperties_disabled(self):
00098         from zExceptions import Unauthorized
00099 
00100         tool = self._makeOne()
00101         dummy = Dummy()
00102         try:
00103             tool.editSyInformationProperties(object, updateFrequency=1)
00104         except Unauthorized:
00105             raise
00106         except: # WAAA! it raises a string!
00107             pass
00108         else:
00109             assert 0, "Didn't raise"
00110 
00111     def test_editSyInformationProperties_normal(self):
00112         PERIOD = 'hourly'
00113         FREQUENCY = 4
00114         NOW = DateTime()
00115         MAX_ITEMS = 42
00116 
00117         tool = self._makeOne()
00118         dummy = Dummy()
00119         info = dummy.syndication_information = Dummy()
00120 
00121         tool.editSyInformationProperties(dummy,
00122                                          updatePeriod=PERIOD,
00123                                          updateFrequency=FREQUENCY,
00124                                          updateBase=NOW,
00125                                          max_items=MAX_ITEMS,
00126                                         )
00127 
00128         self.assertEqual(info.syUpdatePeriod, PERIOD)
00129         self.assertEqual(info.syUpdateFrequency, FREQUENCY)
00130         self.assertEqual(info.syUpdateBase, NOW)
00131         self.assertEqual(info.max_items, MAX_ITEMS)
00132 
00133     def test_editSyInformationProperties_coercing(self):
00134         PERIOD = 'hourly'
00135         FREQUENCY = 4
00136         NOW = DateTime()
00137         MAX_ITEMS = 42
00138 
00139         tool = self._makeOne()
00140         dummy = Dummy()
00141         info = dummy.syndication_information = Dummy()
00142 
00143         tool.editSyInformationProperties(dummy,
00144                                          updatePeriod=PERIOD,
00145                                          updateFrequency='%d' % FREQUENCY,
00146                                          updateBase=NOW.ISO(),
00147                                          max_items='%d' % MAX_ITEMS,
00148                                         )
00149 
00150         self.assertEqual(info.syUpdatePeriod, PERIOD)
00151         self.assertEqual(info.syUpdateFrequency, FREQUENCY)
00152         self.assertEqual(info.syUpdateBase, DateTime(NOW.ISO()))
00153         self.assertEqual(info.max_items, MAX_ITEMS)
00154 
00155     def test_editProperties_isAllowedOnly(self):
00156         # Zope 2.8 crashes if we don't edit all properties.
00157         # This is because Zope now raises AttributeError
00158         # instead of KeyError in editProperties().
00159         tool = self._makeOne()
00160         tool.editProperties(isAllowed=1)
00161 
00162         self.failUnless(tool.isAllowed)
00163 
00164     def test_getSyndicatableContent(self):
00165         # http://www.zope.org/Collectors/CMF/369
00166         # Make sure we use a suitable base class call when determining
00167         # syndicatable content
00168         from Products.CMFCore.PortalFolder import PortalFolder
00169         from Products.CMFCore.CMFBTreeFolder import CMFBTreeFolder
00170         from Products.CMFCore.TypesTool import TypesTool
00171 
00172         PERIOD = 'hourly'
00173         FREQUENCY = 4
00174         NOW = DateTime()
00175         MAX_ITEMS = 42
00176 
00177         self.root._setObject( 'portal_types', TypesTool() )
00178         self.root._setObject('pf', PortalFolder('pf'))
00179         self.root._setObject('bf', CMFBTreeFolder('bf'))
00180         self.root._setObject('portal_syndication', self._makeOne())
00181         tool = self.root.portal_syndication
00182         tool.editProperties(updatePeriod=PERIOD,
00183                             updateFrequency=FREQUENCY,
00184                             updateBase=NOW,
00185                             isAllowed=True,
00186                             max_items=MAX_ITEMS,
00187                            )
00188 
00189         self.assertEqual(len(tool.getSyndicatableContent(self.root.pf)), 0)
00190         self.assertEqual(len(tool.getSyndicatableContent(self.root.bf)), 0)
00191 
00192 
00193 def test_suite():
00194     return unittest.TestSuite((
00195         unittest.makeSuite(SyndicationToolTests),
00196         ))
00197 
00198 if __name__ == '__main__':
00199     unittest.main(defaultTest='test_suite')