Back to index

plone3  3.1.7
test_cache.py
Go to the documentation of this file.
00001 from zope.app.component.hooks import setSite, setHooks
00002 
00003 from plone.app.portlets.tests.base import PortletsTestCase
00004 from plone.app.portlets.cache import render_cachekey
00005 
00006 class MockBrain(object):
00007     def __init__(self, path=u"some/path", modified=u"2002-01-01"):
00008         self.path = path
00009         self.modified = modified
00010     
00011     def getPath(self):
00012         return self.path
00013 
00014 class MockLocation(object):
00015     def __init__(self, name):
00016         self.__name__ = name
00017 
00018 class MockRenderer(object):
00019     manager = MockLocation('some_manager')
00020     data = MockLocation('some_assignment')
00021     data_brains = [MockBrain(), MockBrain()]
00022 
00023     def __init__(self, context, request):
00024         self.context = context
00025         self.request = request
00026         
00027     def _data(self):
00028         return self.data_brains
00029 
00030 class TestCacheKey(PortletsTestCase):
00031 
00032     def afterSetUp(self):
00033         setHooks()
00034         setSite(self.portal)
00035 
00036     def testRenderCachekey(self):
00037         context = self.folder
00038         renderer = MockRenderer(context, context.REQUEST)
00039 
00040         key1 = render_cachekey(None, renderer) 
00041         renderer.manager.__name__ += '__changed__'
00042         key2 = render_cachekey(None, renderer)
00043 
00044         self.failUnless(key1 != key2)
00045 
00046     def testAnonymousFlag(self):
00047         context = self.folder
00048         renderer = MockRenderer(context, context.REQUEST)
00049 
00050         key1 = render_cachekey(None, renderer)
00051         self.logout()
00052         key2 = render_cachekey(None, renderer)
00053 
00054         self.assertNotEqual(key1, key2)
00055 
00056     def testNonASCIIPath(self):
00057         # http://dev.plone.org/plone/ticket/7086
00058         context = self.folder
00059         renderer = MockRenderer(context, context.REQUEST)
00060         renderer.data_brains = [
00061             MockBrain("Pr\xc5\xafvodce"), MockBrain("p\xc5\x99i")]
00062         render_cachekey(None, renderer)
00063 
00064 def test_suite():
00065     from unittest import TestSuite, makeSuite
00066     suite = TestSuite()
00067     suite.addTest(makeSuite(TestCacheKey))
00068     return suite