changeset 3501:159b08b1d9ff

macro._tests.test_Hits: removed dependencies of tests
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 13 Apr 2008 18:04:46 +0200
parents b5b3f1a72b4e
children 02b73ceab324
files MoinMoin/macro/_tests/test_Hits.py
diffstat 1 files changed, 28 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/macro/_tests/test_Hits.py	Sun Apr 13 16:15:34 2008 +0200
+++ b/MoinMoin/macro/_tests/test_Hits.py	Sun Apr 13 18:04:46 2008 +0200
@@ -3,7 +3,6 @@
     MoinMoin - MoinMoin.macro Hits tested
 
     @copyright: 2007-2008 MoinMoin:ReimarBauer
-
     @license: GNU GPL, see COPYING for details.
 """
 import os
@@ -19,7 +18,6 @@
     def setup_class(self):
         self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageForHits'
         self.page = PageEditor(self.request, self.pagename)
-        self.shouldDeleteTestPage = False
         # for that test eventlog needs to be empty
         fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
         if os.path.exists(fpath):
@@ -30,12 +28,10 @@
         caching.CacheEntry(self.request, arena, 'hitcounts', scope='item').remove()
 
     def teardown_class(self):
-        if self.shouldDeleteTestPage:
-            import shutil
-            page = PageEditor(self.request, self.pagename)
-            page.deletePage()
-            fpath = page.getPagePath(use_underlay=0, check_create=0)
-            shutil.rmtree(fpath, True)
+        import shutil
+        page = PageEditor(self.request, self.pagename)
+        fpath = page.getPagePath(use_underlay=0, check_create=0)
+        shutil.rmtree(fpath, True)
 
     def _make_macro(self):
         """Test helper"""
@@ -59,11 +55,18 @@
         self.request.reset()
         self.page.saveText(body, 0)
 
+    def _cleanStats(self):
+        # cleans all involved cache and log files
+        fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
+        if os.path.exists(fpath):
+            os.remove(fpath)
+        # hits is based on hitcounts which reads the cache
+        caching.CacheEntry(self.request, 'charts', 'hitcounts', scope='wiki').remove()
+        arena = Page(self.request, self.pagename)
+        caching.CacheEntry(self.request, arena, 'hitcounts', scope='item').remove()
+
     def testHitsNoArg(self):
         """ macro Hits test: 'no args for Hits (Hits is executed on current page) """
-        self.shouldDeleteTestPage = False
-        self._createTestPage('This is an example to test a macro')
-
         # Three log entries for the current page and one for WikiSandBox simulating viewing
         eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': 'WikiSandBox'})
         eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
@@ -71,41 +74,42 @@
         eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
 
         result = self._test_macro(u'Hits', u'')
+        self._cleanStats()
         expected = "3"
         assert result == expected
 
     def testHitsForAll(self):
         """ macro Hits test: 'all=True' for Hits (all pages are counted for VIEWPAGE) """
-        self.shouldDeleteTestPage = False
-        self._createTestPage('This is an example to test a macro with parameters')
-
-        # Two log entries for simulating viewing 
+        # Two log entries for simulating viewing
         eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
         eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
+        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': 'WikiSandBox'})
+        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': 'WikiSandBox'})
 
         result = self._test_macro(u'Hits', u'all=True')
-        # four log entries from the previuos test + two from this test
-        expected = "6"
+        self._cleanStats()
+        expected = "4"
         assert result == expected
 
     def testHitsForFilter(self):
         """ macro Hits test: 'event_type=SAVEPAGE' for Hits (SAVEPAGE counted for current page)"""
-        self.shouldDeleteTestPage = False
-
+        eventlog.EventLog(self.request).add(self.request, 'SAVEPAGE', {'pagename': self.pagename})
         # simulate a log entry SAVEPAGE for WikiSandBox to destinguish current page
         eventlog.EventLog(self.request).add(self.request, 'SAVEPAGE', {'pagename': 'WikiSandBox'})
+
         result = self._test_macro(u'Hits', u'event_type=SAVEPAGE')
-        # two previous tests do have saved the page twice times
-        expected = "2"
+        self._cleanStats()
+        expected = "1"
         assert result == expected
 
     def testHitsForAllAndFilter(self):
         """ macro test: 'all=True, event_type=SAVEPAGE' for Hits (all pages are counted for SAVEPAGE)"""
-        self.shouldDeleteTestPage = True
+        eventlog.EventLog(self.request).add(self.request, 'SAVEPAGE', {'pagename': 'WikiSandBox'})
+        eventlog.EventLog(self.request).add(self.request, 'SAVEPAGE', {'pagename': self.pagename})
 
         result = self._test_macro(u'Hits', u'all=True, event_type=SAVEPAGE')
-        # two previous tests have saved the page twice times + one log entry for WikiSandBox
-        expected = "3"
+        self._cleanStats()
+        expected = "2"
         assert result == expected