products/CPSRSS

view tests/testRSS.py @ 216:30f6d0876296

Testing for per-user caching capabilities
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Thu, 15 Jul 2010 11:29:51 +0200
parents 8d651512b305
children
line source
1 # (c) 2003 Nuxeo SARL <http://nuxeo.com>
2 # $Id$
4 import unittest, os.path
5 import urllib2
6 import CPSRSSTestCase
8 class TestRSSTool(CPSRSSTestCase.CPSRSSTestCase):
10 def afterSetUp(self):
11 rss_tool = self.rss_tool = self.portal.portal_rss
12 self.base_url = os.path.abspath(
13 os.path.dirname(CPSRSSTestCase.__file__))
14 url = os.path.join(self.base_url, 'zope.rss')
15 rss_tool.manage_addRSSChannel('channel', url)
16 self.channel = rss_tool.channel
18 def testTool(self):
19 rss_tool = self.portal.portal_rss
20 self.assertEquals(rss_tool.meta_type, 'RSS Tool')
21 self.assertEquals(rss_tool.objectIds(), ['channel'])
22 # now testing if there is no channel
23 rss_tool.manage_delObjects(['channel'])
24 rss_tool.refresh()
26 def _testChannel(self, lazy_refresh=0):
27 rss_tool = self.portal.portal_rss
28 rss_tool.lazy_refresh = lazy_refresh
29 rss_tool.refresh()
30 d = rss_tool.channel.getData()
31 self.assertEquals(d['url'], 'http://zope.org')
32 self.assertEquals(d['title'], 'Zope.org')
33 self.assertEquals(d['description'], '')
35 def _testPerUserChannel(self, lazy_refresh=0):
36 self.rss_tool.lazy_refresh = lazy_refresh
38 channel = self.channel
39 d1 = channel.getData(user_id='user1')
40 self.assertEquals(d1['url'], 'http://zope.org')
41 self.assertEquals(d1['title'], 'Zope.org')
42 self.assertEquals(d1['description'], '')
44 # we switch the url to simulate channel contents depending on the user
45 url1 = channel.channel_url
46 channel.channel_url = os.path.join(self.base_url, 'zope_user2.rss')
47 d2 = channel.getData(user_id='user2')
48 self.assertTrue('user2' in d2['lines'][0]['title'])
50 if not lazy_refresh:
51 return
53 # we don't switch back, but user1 content is served from cache
54 d1_cache = channel.getData(user_id='user1')
55 self.assertEquals(d1, d1_cache)
57 def testChannelWrongAuthFwd(self):
58 # does not break if extended_auth is missing
59 self.channel.manage_changeProperties(forward_auth=True)
60 self.assertTrue(self.channel.getProperty('forward_auth'))
61 self.rss_tool.refresh()
63 # it worked anyway
64 d = self.channel.getData()
65 self.assertEquals(d['url'], 'http://zope.org')
66 self.assertEquals(d['title'], 'Zope.org')
67 self.assertEquals(d['description'], '')
69 def testChannelLazy(self):
70 self._testChannel(lazy_refresh=1)
72 def testPerUserChannelLazy(self):
73 self._testPerUserChannel(lazy_refresh=1)
75 def testPerUserChannelNotLazy(self):
76 self._testPerUserChannel(lazy_refresh=0)
78 def testChannelNotLazy(self):
79 self._testChannel(lazy_refresh=0)
81 def testExcHandling(self):
82 rss_tool = self.rss_tool
83 rss_tool.lazy_refresh = False
84 url = 'http://nohost.cps-cms.org'
85 try:
86 stream = urllib2.urlopen('http://nohost.cps-cms.org')
87 stream.read()
88 except urllib2.URLError:
89 pass
90 else:
91 self.fail("URL that should not be found actually exists !")
93 chan = self.channel
94 chan.channel_url = url
95 chan = rss_tool.channel
96 chan._retrieveRSSFeed()
98 def test_suite():
99 suites = [unittest.makeSuite(TestRSSTool)]
100 return unittest.TestSuite(suites)
102 if __name__=="__main__":
103 unittest.main(defaultTest='test_suite')