changeset 2150:3417a1d559d0

Merge the changes from main.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Mon, 18 Jun 2007 00:48:31 +0200
parents 7def1e49e757 (current diff) d84535cb9f65 (diff)
children 8e772d72ec6e
files
diffstat 20 files changed, 132 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/_test_template.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/_test_template.py	Mon Jun 18 00:48:31 2007 +0200
@@ -31,7 +31,7 @@
         # injected for you into the test class by moin test framework.
         result = module_tested.some_function(self.request, 'test_value')
         expected = 'expected value'
-        assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
+        assert result == expected
 
 
 class TestComplexStuff:
@@ -63,8 +63,7 @@
         """ module_tested: function should... """
         for description, test, expected in self._tests:
             result = self._helper_function(test)
-            assert result == expected, ('%(description)s: expected "%(expected)s" '
-                              'but got "%(result)s"') % locals()
+            assert result == expected
 
     def _helper_fuction(self, test):
         """ Some tests needs extra  work to run
--- a/MoinMoin/_tests/test_Page.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_Page.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin import Page
 
 class TestExists(unittest.TestCase):
--- a/MoinMoin/_tests/test_PageEditor.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_PageEditor.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 
 import py
 
--- a/MoinMoin/_tests/test_converter_text_html_text_moin_wiki.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_converter_text_html_text_moin_wiki.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
 @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 
 import py
 py.test.skip("Many broken tests, much broken code, broken, broken, broken.")
@@ -1134,6 +1134,3 @@
 """
         self.do(test, output)
 
-if __name__ == '__main__':
-    unittest.main()
-
--- a/MoinMoin/_tests/test_error.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_error.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin import error
 
 
--- a/MoinMoin/_tests/test_macro.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_macro.py	Mon Jun 18 00:48:31 2007 +0200
@@ -7,7 +7,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 
 from MoinMoin import macro
 from MoinMoin.parser.text import Parser
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/_tests/test_macro_Hits.py	Mon Jun 18 00:48:31 2007 +0200
@@ -0,0 +1,112 @@
+# -*- 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))
+
--- a/MoinMoin/_tests/test_mail_sendmail.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_mail_sendmail.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from email.Charset import Charset, QP
 from email.Header import Header
 from MoinMoin.mail import sendmail
--- a/MoinMoin/_tests/test_parser_text_moin_wiki.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_parser_text_moin_wiki.py	Mon Jun 18 00:48:31 2007 +0200
@@ -9,7 +9,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 import re
 from StringIO import StringIO
 
--- a/MoinMoin/_tests/test_pysupport.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_pysupport.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest, os, errno
+import unittest, os, errno # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 
 import py
 
--- a/MoinMoin/_tests/test_request.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_request.py	Mon Jun 18 00:48:31 2007 +0200
@@ -8,7 +8,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin import config
 
 class TestNormalizePagename(unittest.TestCase):
--- a/MoinMoin/_tests/test_search.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_search.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin import search
 
 
--- a/MoinMoin/_tests/test_security.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_security.py	Mon Jun 18 00:48:31 2007 +0200
@@ -9,7 +9,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin import security
 
 acliter = security.ACLStringIterator
--- a/MoinMoin/_tests/test_user.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_user.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest, os
+import unittest, os # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 
 import py
 
--- a/MoinMoin/_tests/test_util_lock.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_util_lock.py	Mon Jun 18 00:48:31 2007 +0200
@@ -8,7 +8,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest, tempfile, os, time, shutil
+import unittest, tempfile, os, time, shutil # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 
 import py
 
--- a/MoinMoin/_tests/test_util_web.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_util_web.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin import wikiutil
 from MoinMoin.util import web
 from MoinMoin.widget import html
--- a/MoinMoin/_tests/test_widget_html.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_widget_html.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin.widget import html
 
 class TestHTMLWidgets(unittest.TestCase):
--- a/MoinMoin/_tests/test_wikidicts.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_wikidicts.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 import re
 
 from MoinMoin import wikidicts
--- a/MoinMoin/_tests/test_wikiutil.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin import wikiutil
 
 
--- a/MoinMoin/_tests/test_wikixml_marshal.py	Sun Jun 17 16:56:43 2007 +0200
+++ b/MoinMoin/_tests/test_wikixml_marshal.py	Mon Jun 18 00:48:31 2007 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 import array
 from MoinMoin.wikixml import marshal