Back to index

plone3  3.1.7
test_cache.py
Go to the documentation of this file.
00001 from Products.Archetypes.utils import shasattr
00002 from Products.CMFCore.utils import getToolByName
00003 from Testing import ZopeTestCase
00004 from sets import Set
00005 from wicked import utils
00006 from wicked.interfaces import IWickedFilter, ICacheManager, IUID
00007 from wickedtestcase import WickedTestCase
00008 import os, sys, time
00009 import traceback
00010 import unittest
00011 import pdb; st = pdb.set_trace
00012 
00013 MARKER = dict(path='/apath',
00014               icon='anicon.ico',
00015               uid='uid')
00016 
00017 class TestLinkCache(WickedTestCase):
00018     wicked_type = 'IronicWiki'
00019     wicked_field = 'body'
00020 
00021     def afterSetUp(self):
00022         """
00023         sets the body of page1 to be a wicked link of the id of page2
00024         """
00025         super(TestLinkCache, self).afterSetUp()
00026         field = self.page1.getField(self.wicked_field)
00027         field.set(self.page1, "((%s))" % self.page2.Title())
00028         self.field = field
00029         self.filter = utils.getWicked(field, self.page1)
00030         self.wicked_ccm = self.filter.cache
00031         self.wicked_ccm.name=field.getName()
00032         
00033     def test_linkGetsCached(self):
00034         field = self.field
00035         wicked_ccm = self.wicked_ccm
00036         pg2_id = self.page2.getId()
00037         val = wicked_ccm.get(pg2_id)
00038         self.failUnless(val)
00039         data=dict(path='/plone/Members/test_user_1_/dmv-computer-has-died',
00040                   icon='plone/document_icon.gif')
00041         data['uid']=IUID(self.page2)
00042         self.failUnlessEqual(set(val[0].items()), set(data.items()))
00043 
00044     def test_cacheIsUsed(self):
00045         field = self.field
00046         wicked_ccm = self.wicked_ccm
00047         pg2_id = self.page2.getId()
00048         wicked_ccm.set((pg2_id, IUID(self.page2)), [MARKER])
00049         value = self.getRenderedWickedField(self.page1)
00050         self.failUnless(MARKER['path'] in value)
00051         self.failIfWickedLink(self.page1, self.page2)
00052         
00053 
00054 def test_suite():
00055     suite = unittest.TestSuite()
00056     from Testing.ZopeTestCase import ZopeDocTestSuite
00057     suite.addTest(unittest.makeSuite(TestLinkCache))
00058     return suite
00059