changeset 2177:3719548ae9a2

test of Hits moved to macro and converted for py.test, a test for the Action macro added
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 20 Jun 2007 20:27:46 +0200
parents 7917222e0e05
children e35adb666eca
files MoinMoin/_tests/macro/test_Action.py MoinMoin/_tests/macro/test_Hits.py MoinMoin/_tests/test_macro_Hits.py
diffstat 3 files changed, 170 insertions(+), 112 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/_tests/macro/test_Action.py	Wed Jun 20 20:27:46 2007 +0200
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+"""
+    MoinMoin - MoinMoin.macro.Action Tests
+
+    @copyright: 2007 MoinMoin:ReimarBauer
+
+    @license: GNU GPL, see COPYING for details.
+"""
+import os
+from MoinMoin import macro
+from MoinMoin.macro import Action
+from MoinMoin.Page import Page
+from MoinMoin.PageEditor import PageEditor
+
+
+class TestAction:
+    """ testing macro Action calling action raw """
+
+    def setup_class(self):
+        self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageForAction'
+        self.page = PageEditor(self.request, self.pagename)
+        self.shouldDeleteTestPage = True
+
+    def teardown_class(self):
+        if self.shouldDeleteTestPage:
+            import shutil
+            page = Page(self.request, self.pagename)
+            fpath = page.getPagePath(use_underlay=0, check_create=0)
+            shutil.rmtree(fpath, True)
+
+            fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
+            if os.path.exists(fpath):
+                os.remove(fpath)
+
+    def _make_macro(self):
+        """Test helper"""
+        from MoinMoin.parser.text import Parser
+        from MoinMoin.formatter.text_html import Formatter
+        p = Parser("##\n", self.request)
+        p.formatter = Formatter(self.request)
+        p.formatter.page = self.page
+        self.request.formatter = p.formatter
+        p.form = self.request.form
+        m = macro.Macro(p)
+        return m
+
+    def _createTestPage(self, body):
+        """ Create temporary page """
+        assert body is not None
+        self.request.reset()
+        self.page.saveText(body, 0)
+
+    def testActionCallingRaw(self):
+        """ module_tested: executes raw by macro Action on existing page"""
+
+        expected = '<a href="./AutoCreatedMoinMoinTemporaryTestPageForAction?action=raw">raw</a>'
+        text = '= title1 =\n||A||B||\n'
+        self._createTestPage(text)
+        m = self._make_macro()
+        result = Action.execute(m, 'raw')
+
+        assert result == expected
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/_tests/macro/test_Hits.py	Wed Jun 20 20:27:46 2007 +0200
@@ -0,0 +1,107 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - MoinMoin.macro Hits tested
+
+    @copyright: 2007 MoinMoin:ReimarBauer
+
+    @license: GNU GPL, see COPYING for details.
+"""
+import os
+from MoinMoin import macro
+from MoinMoin.logfile import eventlog
+from MoinMoin.Page import Page
+from MoinMoin.PageEditor import PageEditor
+from MoinMoin.parser.text_moin_wiki import Parser
+
+class TestHits:
+    """Hits: testing Hits macro """
+
+    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):
+            os.remove(fpath)
+
+    def teardown_class(self):
+        if self.shouldDeleteTestPage:
+            import shutil
+            page = Page(self.request, self.pagename)
+            fpath = page.getPagePath(use_underlay=0, check_create=0)
+            shutil.rmtree(fpath, True)
+
+            fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
+            if os.path.exists(fpath):
+                os.remove(fpath)
+
+    def _make_macro(self):
+        """Test helper"""
+        from MoinMoin.parser.text import Parser
+        from MoinMoin.formatter.text_html import Formatter
+        p = Parser("##\n", self.request)
+        p.formatter = Formatter(self.request)
+        p.formatter.page = self.page
+        self.request.formatter = p.formatter
+        p.form = self.request.form
+        m = macro.Macro(p)
+        return m
+
+    def _test_macro(self, name, args):
+        m = self._make_macro()
+        return m.execute(name, args)
+
+    def _createTestPage(self, body):
+        """ Create temporary page """
+        assert body is not None
+        self.request.reset()
+        self.page.saveText(body, 0)
+
+    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})
+        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
+        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
+
+        result = self._test_macro('Hits', '')
+        expected = "3"
+        assert result == expected
+
+    def testHitsForAll(self):
+        """ macro Hits test: 'all=1' 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
+        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
+        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
+
+        result = self._test_macro('Hits', 'all=1')
+        expected = "6"
+        assert result == expected
+
+    def testHitsForFilter(self):
+        """ macro Hits test: 'all=1, filter=SAVEPAGE' for Hits (SAVEPAGE counted for current page)"""
+        self.shouldDeleteTestPage = False
+
+        # 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('Hits', 'filter=SAVEPAGE')
+        expected = "2"
+        assert result == expected
+
+    def testHitsForAllAndFilter(self):
+        """ macro test: 'all=1, filter=SAVEPAGE' for Hits (all pages are counted for SAVEPAGE)"""
+        self.shouldDeleteTestPage = True
+
+        result = self._test_macro('Hits', 'all=1, filter=SAVEPAGE')
+        expected = "3"
+        assert result == expected
+
+
--- a/MoinMoin/_tests/test_macro_Hits.py	Wed Jun 20 15:40:03 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - MoinMoin.macro Hits tested
-
-    @copyright: 2007 MoinMoin:ReimarBauer
-
-    @license: GNU GPL, see COPYING for details.
-"""
-import os, unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
-from MoinMoin import macro
-from MoinMoin.logfile import eventlog
-from MoinMoin.Page import Page
-from MoinMoin.PageEditor import PageEditor
-from MoinMoin.parser.text_moin_wiki import Parser
-
-class TestHits(unittest.TestCase):
-    """Hits: testing Hits macro """
-
-    pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
-
-    def setUp(self):
-        self.page = PageEditor(self.request, self.pagename)
-
-    def tearDown(self):
-        self.deleteTestPage()
-
-    def _make_macro(self):
-        """Test helper"""
-        from MoinMoin.parser.text import Parser
-        from MoinMoin.formatter.text_html import Formatter
-        p = Parser("##\n", self.request)
-        p.formatter = Formatter(self.request)
-        p.formatter.page = self.page
-        self.request.formatter = p.formatter
-        p.form = self.request.form
-        m = macro.Macro(p)
-        return m
-
-    def _test_macro(self, name, args):
-        m = self._make_macro()
-        return m.execute(name, args)
-
-    def createTestPage(self, body):
-        """ Create temporary page """
-        assert body is not None
-        self.request.reset()
-        self.page.saveText(body, 0)
-
-    def deleteTestPage(self):
-        """ Delete temporary page, bypass logs and notifications """
-        if self.shouldDeleteTestPage:
-            import shutil
-            shutil.rmtree(self.getPagePath(), True)
-
-            fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
-            if os.path.exists(fpath):
-                os.remove(fpath)
-
-    def getPagePath(self):
-        page = Page(self.request, self.pagename)
-        return page.getPagePath(use_underlay=0, check_create=0)
-
-    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})
-        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
-        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
-
-        result = self._test_macro('Hits', '')
-        expected = "3"
-        self.assertEqual(result, expected,
-                     '"%s" not in "%s"' % (expected, result))
-
-    def testHitsForAll(self):
-        """ macro Hits test: 'all=1' 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
-        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
-        eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
-
-        result = self._test_macro('Hits', 'all=1')
-        expected = "6"
-        self.assertEqual(result, expected,
-                     '"%s" not in "%s"' % (expected, result))
-
-    def testHitsForFilter(self):
-        """ macro Hits test: 'all=1, filter=SAVEPAGE' for Hits (SAVEPAGE counted for current page)"""
-        self.shouldDeleteTestPage = False
-
-        # 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('Hits', 'filter=SAVEPAGE')
-        expected = "2"
-        self.assertEqual(result, expected,
-                     '"%s" not in "%s"' % (expected, result))
-
-    def testHitsForAllAndFilter(self):
-        """ macro test: 'all=1, filter=SAVEPAGE' for Hits (all pages are counted for SAVEPAGE)"""
-        self.shouldDeleteTestPage = True
-
-        result = self._test_macro('Hits', 'all=1, filter=SAVEPAGE')
-        expected = "3"
-        self.assertEqual(result, expected,
-                     '"%s" not in "%s"' % (expected, result))
-