~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/macro/_tests/test_PageHits.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - MoinMoin.macro PageHits tested
 
4
 
 
5
    @copyright: 2008 MoinMoin:ReimarBauer
 
6
 
 
7
    @license: GNU GPL, see COPYING for details.
 
8
"""
 
9
import os
 
10
 
 
11
from MoinMoin import caching, macro
 
12
from MoinMoin.logfile import eventlog
 
13
from MoinMoin.PageEditor import PageEditor
 
14
from MoinMoin.Page import Page
 
15
 
 
16
from MoinMoin._tests import become_trusted, create_page, nuke_page
 
17
 
 
18
class TestHits:
 
19
    """Hits: testing Hits macro """
 
20
    pagename = u'AutoCreatedMoinMoinTemporaryTestPageForPageHits'
 
21
 
 
22
    def setup_class(self):
 
23
        request = self.request
 
24
        become_trusted(request)
 
25
        self.page = create_page(request, self.pagename, u"Foo!")
 
26
 
 
27
        # for that test eventlog needs to be empty
 
28
        fpath = request.rootpage.getPagePath('event-log', isfile=1)
 
29
        if os.path.exists(fpath):
 
30
            os.remove(fpath)
 
31
 
 
32
        # hits is based on hitcounts which reads the cache
 
33
        caching.CacheEntry(request, 'charts', 'pagehits', scope='wiki').remove()
 
34
        caching.CacheEntry(request, 'charts', 'hitcounts', scope='wiki').remove()
 
35
 
 
36
    def teardown_class(self):
 
37
        nuke_page(self.request, self.pagename)
 
38
 
 
39
    def _make_macro(self):
 
40
        """Test helper"""
 
41
        from MoinMoin.parser.text import Parser
 
42
        from MoinMoin.formatter.text_html import Formatter
 
43
        p = Parser("##\n", self.request)
 
44
        p.formatter = Formatter(self.request)
 
45
        p.formatter.page = self.page
 
46
        self.request.formatter = p.formatter
 
47
        p.form = self.request.form
 
48
        m = macro.Macro(p)
 
49
        return m
 
50
 
 
51
    def _test_macro(self, name, args):
 
52
        m = self._make_macro()
 
53
        return m.execute(name, args)
 
54
 
 
55
    def testPageHits(self):
 
56
        """ macro PageHits test: updating of cache from event-log for multiple call of PageHits"""
 
57
        count = 20
 
58
        for counter in range(count):
 
59
            eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': 'PageHits'})
 
60
            result = self._test_macro(u'PageHits', u'') # XXX SENSE???
 
61
 
 
62
        cache = caching.CacheEntry(self.request, 'charts', 'pagehits', scope='wiki', use_pickle=True)
 
63
        date, hits = 0, {}
 
64
        if cache.exists():
 
65
            try:
 
66
                date, hits = cache.content()
 
67
            except caching.CacheError:
 
68
                cache.remove()
 
69
        assert hits['PageHits'] == count
 
70
 
 
71
coverage_modules = ['MoinMoin.macro.PageHits']