products/CPSRSS

changeset 231:6c108954bee9

Added a pure ZopeTestCase variant and preparation to test local containers
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Sun, 05 Dec 2010 00:42:14 +0100
parents 7b60a90d8d6b
children 8b941a0115c5
files tests/CPSRSSTestCase.py tests/testRSS.py
diffstat 2 files changed, 61 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/tests/CPSRSSTestCase.py
     1.2 +++ b/tests/CPSRSSTestCase.py
     1.3 @@ -14,12 +14,13 @@
     1.4  # along with this program; if not, write to the Free Software
     1.5  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
     1.6  # 02111-1307, USA.
     1.7 -#
     1.8 -# $Id$
     1.9 +
    1.10 +from Testing.ZopeTestCase import ZopeTestCase
    1.11  
    1.12  from Products.CPSDefault.tests.CPSTestCase import CPSTestCase
    1.13  from Products.CPSDefault.tests.CPSTestCase import ExtensionProfileLayerClass
    1.14  
    1.15 +from Products.CPSRSS.RSSTool import RSSTool
    1.16  
    1.17  class LayerClass(ExtensionProfileLayerClass):
    1.18      extension_ids = ('CPSRSS:default',)
    1.19 @@ -28,4 +29,15 @@
    1.20  
    1.21  
    1.22  class CPSRSSTestCase(CPSTestCase):
    1.23 +    """This class also tests that the profile does what it's supposed to."""
    1.24      layer = CPSRSSLayer
    1.25 +
    1.26 +    def afterSetUp(self):
    1.27 +        self.tool = self.portal.portal_rss
    1.28 +
    1.29 +class ZopeRSSTestCase(ZopeTestCase):
    1.30 +
    1.31 +    def afterSetUp(self):
    1.32 +        self.folder._setObject('portal_rss', RSSTool())
    1.33 +        self.tool = self.folder.portal_rss
    1.34 +
     2.1 --- a/tests/testRSS.py
     2.2 +++ b/tests/testRSS.py
     2.3 @@ -1,22 +1,33 @@
     2.4  # (c) 2003 Nuxeo SARL <http://nuxeo.com>
     2.5 -# $Id$
     2.6  
     2.7  import unittest, os.path
     2.8 -import CPSRSSTestCase
     2.9  
    2.10 -class TestRSSTool(CPSRSSTestCase.CPSRSSTestCase):
    2.11 +from CPSRSSTestCase import CPSRSSTestCase
    2.12 +from CPSRSSTestCase import ZopeRSSTestCase
    2.13 +
    2.14 +from Products.CPSRSS.RSSChannelContainer import RSSChannelContainer
    2.15 +
    2.16 +def get_feed_url(feed_file):
    2.17 +    return os.path.abspath(os.path.join(os.path.dirname(__file__), feed_file))
    2.18 +
    2.19 +
    2.20 +class TestRSS(object):
    2.21 +
    2.22 +    def _localContainer(self, folder):
    2.23 +        folder._setObject('.cps_rss', RSSChannelContainer('.cps_rss'))
    2.24 +        return folder['.cps_rss']
    2.25 +
    2.26      def testEmptyTool(self):
    2.27 -        rss_tool = self.portal.portal_rss
    2.28 +        rss_tool = self.tool
    2.29          self.assertEquals(rss_tool.meta_type, 'RSS Tool')
    2.30          self.assertEquals(rss_tool.objectIds(), [])
    2.31          rss_tool.refresh()
    2.32  
    2.33      def _testChannel(self, lazy_refresh=0):
    2.34 -        rss_tool = self.portal.portal_rss
    2.35 +        rss_tool = self.tool
    2.36          rss_tool.lazy_refresh = lazy_refresh
    2.37 -        url = os.path.abspath(os.path.join(
    2.38 -            os.path.dirname(CPSRSSTestCase.__file__), 'zope.rss'))
    2.39 -        rss_tool.manage_addRSSChannel('channel', url)
    2.40 +
    2.41 +        rss_tool.manage_addRSSChannel('channel', get_feed_url('zope.rss'))
    2.42          self.assertEquals(rss_tool.objectIds(), ['channel'])
    2.43          rss_tool.refresh()
    2.44          d = rss_tool.channel.getData()
    2.45 @@ -24,14 +35,41 @@
    2.46          self.assertEquals(d['title'], 'Zope.org')
    2.47          self.assertEquals(d['description'], '')
    2.48  
    2.49 +    def _testLocalChannel(self, lazy_refresh=0):
    2.50 +        rss_tool = self.tool
    2.51 +        rss_tool.lazy_refresh = lazy_refresh
    2.52 +
    2.53 +        container = self.localContainer()
    2.54 +        container.manage_addRSSChannel('channel', get_feed_url('zope.rss'))
    2.55 +        self.assertEquals(container.objectIds(), ['channel'])
    2.56 +        rss_tool.refresh()
    2.57 +        d = container.channel.getData()
    2.58 +        self.assertEquals(d['url'], 'http://zope.org')
    2.59 +        self.assertEquals(d['title'], 'Zope.org')
    2.60 +        self.assertEquals(d['description'], '')
    2.61 +
    2.62      def testChannelLazy(self):
    2.63          self._testChannel(lazy_refresh=1)
    2.64  
    2.65      def testChannelNotLazy(self):
    2.66          self._testChannel(lazy_refresh=0)
    2.67  
    2.68 +class CPSTestRSS(TestRSS, CPSRSSTestCase):
    2.69 +    """Run the tests in a full CPS portal context."""
    2.70 +
    2.71 +    def localContainer(self):
    2.72 +        return _localContainer(self.portal.workspaces)
    2.73 +
    2.74 +
    2.75 +class ZopeTestRSS(TestRSS, ZopeRSSTestCase):
    2.76 +    """Run the tests in a ZopeTestCase environment"""
    2.77 +
    2.78 +    def localContainer(self):
    2.79 +        self.folder._setObject('subfold', Folder('subfold'))
    2.80 +        return _localContainer(self.folder.subfold)
    2.81 +
    2.82  def test_suite():
    2.83 -    suites = [unittest.makeSuite(TestRSSTool)]
    2.84 +    suites = [unittest.makeSuite(cls) for cls in (ZopeTestRSS, CPSTestRSS)]
    2.85      return unittest.TestSuite(suites)
    2.86  
    2.87  if __name__=="__main__":