Back to index

moin  1.9.0~rc2
test_PageHits.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - MoinMoin.macro PageHits tested
00004 
00005     @copyright: 2008 MoinMoin:ReimarBauer
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 import os
00009 
00010 from MoinMoin import caching, macro
00011 from MoinMoin.logfile import eventlog
00012 from MoinMoin.PageEditor import PageEditor
00013 from MoinMoin.Page import Page
00014 
00015 from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_eventlog, nuke_page
00016 
00017 class TestHits:
00018     """Hits: testing Hits macro """
00019     pagename = u'AutoCreatedMoinMoinTemporaryTestPageForPageHits'
00020 
00021     def setup_class(self):
00022         request = self.request
00023         become_trusted(request)
00024         self.page = create_page(request, self.pagename, u"Foo!")
00025         # for that test eventlog needs to be empty
00026         nuke_eventlog(self.request)
00027         # hits is based on hitcounts which reads the cache
00028         caching.CacheEntry(request, 'charts', 'pagehits', scope='wiki').remove()
00029         caching.CacheEntry(request, 'charts', 'hitcounts', scope='wiki').remove()
00030 
00031     def teardown_class(self):
00032         nuke_page(self.request, self.pagename)
00033 
00034     def _test_macro(self, name, args):
00035         m = make_macro(self.request, self.page)
00036         return m.execute(name, args)
00037 
00038     def testPageHits(self):
00039         """ macro PageHits test: updating of cache from event-log for multiple call of PageHits"""
00040         count = 20
00041         for counter in range(count):
00042             eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': 'PageHits'})
00043             result = self._test_macro(u'PageHits', u'') # XXX SENSE???
00044         cache = caching.CacheEntry(self.request, 'charts', 'pagehits', scope='wiki', use_pickle=True)
00045         date, hits = 0, {}
00046         if cache.exists():
00047             try:
00048                 date, hits = cache.content()
00049             except caching.CacheError:
00050                 cache.remove()
00051         assert hits['PageHits'] == count
00052 
00053 coverage_modules = ['MoinMoin.macro.PageHits']