[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/ Tests for tool methods added.

Charlie Clark charlie at begeistert.org
Sun Nov 20 18:11:16 UTC 2011


Log message for revision 123448:
  Tests for tool methods added.
  getHTMLUpdateBase should really return Zulu time and no milliseconds.

Changed:
  U   Products.CMFDefault/trunk/Products/CMFDefault/SyndicationTool.py
  U   Products.CMFDefault/trunk/Products/CMFDefault/tests/test_SyndicationTool.py

-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/SyndicationTool.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/SyndicationTool.py	2011-11-20 16:19:43 UTC (rev 123447)
+++ Products.CMFDefault/trunk/Products/CMFDefault/SyndicationTool.py	2011-11-20 18:11:15 UTC (rev 123448)
@@ -196,7 +196,11 @@
 
         NOTE:  Need to add checks for sitewide policies!!!
         """
-        return self.getSyndicationInfo(obj).period
+        if obj is not None:
+            period = self.getSyndicationInfo(obj).period
+        else:
+            period = self.period
+        return period
 
     security.declarePublic('getUpdateFrequency')
     def getUpdateFrequency(self, obj=None):
@@ -208,8 +212,13 @@
 
         Note:  Need to add checks for sitewide policies!!!
         """
-        return self.getSyndicationInfo(obj).frequency
+        if obj is not None:
+            frequency = self.getSyndicationInfo(obj).frequency
+        else:
+            frequency = self.frequency
 
+        return frequency
+
     security.declarePublic('getUpdateBase')
     def getUpdateBase(self, obj=None):
         """
@@ -223,7 +232,11 @@
         Additionally, sitewide policy checks might have a place
         here...
         """
-        return self.getSyndicationInfo(obj).base.isoformat()
+        if obj is not None:
+            base = self.getSyndicationInfo(obj).base
+        else:
+            base = self.base
+        return base.isoformat()
 
     security.declarePublic('getHTML4UpdateBase')
     def getHTML4UpdateBase(self, obj=None):
@@ -233,13 +246,18 @@
         warn("RSS 2.0 uses RFC 822 formatting"
              " this method will be removed in CMF 2.4",
              DeprecationWarning, stacklevel=2)
-        return self.getSyndicationInfo(obj)['base'].HTML4()
+        # HTML4 is the same as isoformat()
+        return self.getUpdateBase(obj)
 
     def getMaxItems(self, obj=None):
         """
         Return the max_items to be displayed in the syndication
         """
-        return self.getSyndicationInfo(obj).max_items
+        if obj is not None:
+            max_items = self.getSyndicationInfo(obj).max_items
+        else:
+            max_items = self.max_items
+        return max_items
 
 InitializeClass(SyndicationTool)
 registerToolInterface('portal_syndication', ISyndicationTool)

Modified: Products.CMFDefault/trunk/Products/CMFDefault/tests/test_SyndicationTool.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/tests/test_SyndicationTool.py	2011-11-20 16:19:43 UTC (rev 123447)
+++ Products.CMFDefault/trunk/Products/CMFDefault/tests/test_SyndicationTool.py	2011-11-20 18:11:15 UTC (rev 123448)
@@ -109,6 +109,10 @@
         sm.registerAdapter(DummyInfo, [IFolderish], ISyndicationInfo)
         return folder
 
+    def _makeInfo(self, context):
+        info = DummyInfo(context)
+        return info
+
     def tearDown(self):
         cleanUp()
         SecurityTest.tearDown(self)
@@ -170,8 +174,6 @@
                                          max_items=MAX_ITEMS,
                                         )
         info = tool.getSyndicationInfo(context)
-        import pdb
-        #pdb.set_trace()
         self.assertEqual(info.frequency, FREQUENCY)
         self.assertEqual(info.period, PERIOD)
         self.assertEqual(info.base, NOW)
@@ -203,7 +205,116 @@
         self.assertEqual(len(tool.getSyndicatableContent(self.app.pf)), 0)
         self.assertEqual(len(tool.getSyndicatableContent(self.app.bf)), 0)
 
+    def test_getUpdateBase(self):
+        NOW = datetime.now()
 
+        tool = self._makeOne()
+        tool.base = NOW
+
+        self.assertEqual(NOW.isoformat(), tool.getUpdateBase())
+
+
+    def test_getUpdateBaseWithContext(self):
+        NOW = datetime.now()
+
+        tool = self._makeOne()
+        tool.enabled = True
+
+        context = self._makeContext()
+        info = self._makeInfo(context)
+        tool.enableSyndication(context)
+        info.base = NOW
+
+        self.assertEqual(NOW.isoformat(), tool.getUpdateBase(context))
+
+
+    def test_getHTML4UpdateBase(self):
+        NOW = datetime.now()
+
+        tool = self._makeOne()
+        tool.base = NOW
+
+        as_HTML4 = tool.getHTML4UpdateBase()
+        self.assertEqual(as_HTML4, NOW.isoformat())
+
+    def test_getHTML4UpdateBaseWithContext(self):
+        NOW = datetime.now()
+
+        tool = self._makeOne()
+        tool.enabled = True
+
+        context = self._makeContext()
+        info = self._makeInfo(context)
+        tool.enableSyndication(context)
+        info.base = NOW
+
+        as_HTML4 = tool.getHTML4UpdateBase(context)
+        self.assertEqual(NOW.isoformat(), as_HTML4)
+
+    def test_getMaxItems(self):
+        max_items = 5
+
+        tool = self._makeOne()
+        tool.max_items = max_items
+
+        self.assertEqual(max_items, tool.getMaxItems())
+
+    def test_getMaxItemsWithContext(self):
+        max_items = 10
+
+        tool = self._makeOne()
+        tool.enabled = True
+
+        context = self._makeContext()
+        info = self._makeInfo(context)
+        tool.enableSyndication(context)
+        info.max_items = max_items
+
+        self.assertEqual(max_items, tool.getMaxItems(context))
+
+    def test_getUpdatePeriod(self):
+        period = 3
+
+        tool = self._makeOne()
+        tool.period = period
+
+        self.assertEqual(period, tool.getUpdatePeriod())
+
+    def test_getUpdatePeriodWithContext(self):
+        period = 2
+
+        tool = self._makeOne()
+        tool.enabled = True
+
+        context = self._makeContext()
+        info = self._makeInfo(context)
+        tool.enableSyndication(context)
+        info.period = period
+
+        self.assertEqual(period, tool.getUpdatePeriod(context))
+
+    def test_getUpdateFrequency(self):
+        frequency = 'monthly'
+
+        tool = self._makeOne()
+        tool.frequency = frequency
+
+        self.assertEqual(frequency, tool.getUpdateFrequency())
+
+    def test_getUpdateFrequencyWithContext(self):
+        frequency = 'weekly'
+
+        tool = self._makeOne()
+        tool.enabled = True
+
+        context = self._makeContext()
+        info = self._makeInfo(context)
+        tool.enableSyndication(context)
+        info.frequency = frequency
+
+        self.assertEqual(frequency, tool.getUpdateFrequency(context))
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(SyndicationToolTests),



More information about the checkins mailing list