Commits

Thomas Waldmann committed 7ee94ad

tests: test page creation/deletion now done by helpers in MoinMoin._tests

  • Participants
  • Parent commits 383fda7

Comments (0)

Files changed (12)

File MoinMoin/_tests/__init__.py

     @license: GNU GPL, see COPYING for details.
 """
 
+import shutil
+
+from MoinMoin.PageEditor import PageEditor
+
+# Promoting the test user -------------------------------------------
+# Usually the tests run as anonymous user, but for some stuff, you
+# need more privs...
+
 def become_valid(request, username=u"ValidUser"):
     """ modify request.user to make the user valid.
         Note that a valid user will only be in ACL special group "Known", if
     request.user.may.name = username
     request.user.valid = 1
 
+
 def become_trusted(request, username=u"TrustedUser"):
     """ modify request.user to make the user valid and trusted, so it is in acl group Trusted """
     become_valid(request, username)
     request.user.auth_method = request.cfg.auth_methods_trusted[0]
 
+
 def become_superuser(request):
     """ modify request.user so it is in the superuser list,
         also make the user valid (see notes in become_valid()),
     become_trusted(request, su_name)
     if su_name not in request.cfg.superuser:
         request.cfg.superuser.append(su_name)
+
+
+# Creating and destroying test pages --------------------------------
+
+def create_page(request, pagename, content, do_editor_backup=False):
+    """ create a page with some content """
+    # make sure there is nothing already there:
+    nuke_page(request, pagename)
+    # now create from scratch:
+    page = PageEditor(request, pagename, do_editor_backup=do_editor_backup)
+    page.saveText(content, 0)
+    return page
+
+
+def nuke_page(request, pagename):
+    """ completely delete a page, everything in the pagedir """
+    page = PageEditor(request, pagename, do_editor_backup=False)
+    page.deletePage()
+    # really get rid of everything there:
+    fpath = page.getPagePath(check_create=0)
+    shutil.rmtree(fpath, True)

File MoinMoin/_tests/test_PageEditor.py

 from MoinMoin import wikiutil
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests import become_trusted
+
+# TODO: check if and where we can use the helpers:
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 class TestExpandVars(object):
     """PageEditor: testing page editor"""
         assert result and revision is 2
 
 coverage_modules = ['MoinMoin.PageEditor']
-

File MoinMoin/_tests/test_wikidicts.py

 from MoinMoin import wikidicts
 from MoinMoin import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests import become_trusted
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 class TestGroupPage:
 
         """
          tests if the dict cache for groups is refreshed after renaming a Group page
         """
-        become_trusted(self.request)
-        pagename = u'SomeGroup'
-        page = PageEditor(self.request, pagename, do_editor_backup=False)
-        body = " * ExampleUser"
-        try:
-            page.saveText(body, 0)
-        except:
-            pass
-
+        request = self.request
+        become_trusted(request)
+        page = create_page(request, u'SomeGroup', u" * ExampleUser")
         page.renamePage('AnotherGroup')
 
-        group = wikidicts.Group(self.request, '')
-        isgroup = self.request.cfg.cache.page_group_regex.search
-        grouppages = self.request.rootpage.getPageList(user='', filter=isgroup)
+        group = wikidicts.Group(request, '')
+        isgroup = request.cfg.cache.page_group_regex.search
+        grouppages = request.rootpage.getPageList(user='', filter=isgroup)
 
-        members, groups = self.request.dicts.expand_group(u'AnotherGroup')
-        page = PageEditor(self.request, u'AnotherGroup', do_editor_backup=0)
+        members, groups = request.dicts.expand_group(u'AnotherGroup')
 
-        # real delete AnotherGroup page from filesystem
-        page.deletePage()
-        fpath = page.getPagePath(check_create=0)
-        shutil.rmtree(fpath, True)
+        nuke_page(request, u'AnotherGroup')
 
         assert u'ExampleUser' in members
 
         """
          tests if the dict cache for groups is refreshed after copying a Group page
         """
-        become_trusted(self.request)
-        pagename = u'SomeGroup'
-        page = PageEditor(self.request, pagename, do_editor_backup=False)
-        body = " * ExampleUser"
-        try:
-            page.saveText(body, 0)
-        except:
-            pass
-
+        request = self.request
+        become_trusted(request)
+        page = create_page(request, u'SomeGroup', u" * ExampleUser")
         page.copyPage(u'OtherGroup')
 
-        group = wikidicts.Group(self.request, '')
-        isgroup = self.request.cfg.cache.page_group_regex.search
-        grouppages = self.request.rootpage.getPageList(user='', filter=isgroup)
+        group = wikidicts.Group(request, '')
+        isgroup = request.cfg.cache.page_group_regex.search
+        grouppages = request.rootpage.getPageList(user='', filter=isgroup)
 
-        members, groups = self.request.dicts.expand_group(u'OtherGroup')
-        page = PageEditor(self.request, u'OtherGroup', do_editor_backup=0)
+        members, groups = request.dicts.expand_group(u'OtherGroup')
 
-        # real delete Group page from filesystem
-        page = PageEditor(self.request, u'OtherGroup', do_editor_backup=0)
-        page.deletePage()
-        fpath = page.getPagePath(check_create=0)
-        shutil.rmtree(fpath, True)
-
-        # real delete Group page from filesystem
-        page = PageEditor(self.request, u'SomeGroup', do_editor_backup=0)
-        page.deletePage()
-        fpath = page.getPagePath(check_create=0)
-        shutil.rmtree(fpath, True)
+        nuke_page(request, u'OtherGroup')
+        nuke_page(request, u'SomeGroup')
 
         assert u'ExampleUser' in members
 
 coverage_modules = ['MoinMoin.wikidicts']
-

File MoinMoin/action/_tests/test_attachfile.py

 import os
 from MoinMoin.action import AttachFile
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests import become_trusted
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 def test_add_attachment(request):
     """Test if add_attachment() works"""
     pagename = "AutoCreatedSillyPageToTestAttachments"
     filename = "AutoCreatedSillyAttachment"
 
-    editor = PageEditor(request, pagename)
-    editor.deletePage()
-    editor.saveText("Test text!", 0)
+    create_page(request, pagename, u"Foo!")
 
-    print "First of all, no exceptions should be raised!"
     AttachFile.add_attachment(request, pagename, filename, "Test content", True)
+    exists = AttachFile.exists(request, pagename, filename)
 
-    print "The save attachment should actually exist!"
-    assert AttachFile.exists(request, pagename, filename)
+    nuke_page(request, pagename)
+
+    assert exists
 
 def test_get_attachment_path_created_on_getFilename(request):
     """
     """
     pagename = "ThisPageDoesOnlyExistForThisTest"
     filename = ""
-    result = os.path.exists(AttachFile.getFilename(request, pagename, filename))
-    expect = True
+    file_exists = os.path.exists(AttachFile.getFilename(request, pagename, filename))
 
-    # real delete pagename from filesystem
-    import shutil
-    page = PageEditor(request, pagename, do_editor_backup=0)
-    page.deletePage()
-    fpath = page.getPagePath(check_create=0)
-    shutil.rmtree(fpath, True)
+    nuke_page(request, pagename)
 
-    assert expect == result
+    assert file_exists
 
 def test_getAttachUrl(request):
     """

File MoinMoin/macro/_tests/test_Action.py

 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
 
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 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)
+    pagename = u'AutoCreatedMoinMoinTemporaryTestPageForAction'
 
     def _make_macro(self):
         """Test helper"""
         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"""
+        request = self.request
+        become_trusted(request)
+
+        self.page = create_page(request, self.pagename, u'= title1 =\n||A||B||\n')
+        m = self._make_macro()
+        result = Action.macro_Action(m, 'raw')
+        nuke_page(request, self.pagename)
 
         expected = '<a href="./AutoCreatedMoinMoinTemporaryTestPageForAction?action=raw">raw</a>'
-        text = '= title1 =\n||A||B||\n'
-        self._createTestPage(text)
-        m = self._make_macro()
-        result = Action.macro_Action(m, 'raw')
-
         assert result == expected
 
 

File MoinMoin/macro/_tests/test_EmbedObject.py

 
     @license: GNU GPL, see COPYING for details.
 """
-import os, py
+
+import py
+
 from MoinMoin import macro
 from MoinMoin.action import AttachFile
-from MoinMoin.macro import EmbedObject
-from MoinMoin.Page import Page
-from MoinMoin.PageEditor import PageEditor
 
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 class TestEmbedObject:
     """ testing macro Action calling action raw """
+    pagename = u'AutoCreatedMoinMoinTemporaryTestPageForEmbedObject'
 
     def setup_class(self):
-        self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageForEmbedObject'
-        self.page = PageEditor(self.request, self.pagename)
-        AttachFile.getAttachDir(self.request, self.pagename)
-        filename = 'test.ogg'
-        filecontent = u'vorbis'
-        AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, overwrite=0)
-        filename = 'test.svg'
-        filecontent = u'SVG'
-        AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, overwrite=0)
-        filename = 'test.mpg'
-        filecontent = u'MPG'
-        AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, overwrite=0)
-        filename = 'test.pdf'
-        filecontent = u'PDF'
-        AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, overwrite=0)
-        filename = 'test.mp3'
-        filecontent = u'MP3'
-        AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, overwrite=0)
-        self.shouldDeleteTestPage = True
+        request = self.request
+        pagename = self.pagename
+
+        become_trusted(request)
+        self.page = create_page(request, pagename, u"Foo")
+
+        AttachFile.getAttachDir(request, pagename)
+        test_files = [
+            ('test.ogg', u'vorbis'),
+            ('test.svg', u'SVG'),
+            ('test.mpg', u'MPG'),
+            ('test.pdf', u'PDF'),
+            ('test.mp3', u'MP3'),
+        ]
+        for filename, filecontent in test_files:
+            AttachFile.add_attachment(request, pagename, filename, filecontent, overwrite=0)
 
     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)
+        nuke_page(self.request, self.pagename)
 
     def _make_macro(self):
         """ Test helper """
         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 testEmbedObjectMimetype(self):
         """ tests defined mimetyes """
-        files = ('test.ogg', 'test.svg', 'test.mpg', 'test.mp3')
-        mimetype = ('application/ogg', 'image/svg+xml', 'video/mpeg', 'audio/mpeg')
-        index = 0
-        for filename in files:
-            text = '= %s =' % filename
-            self._createTestPage(text)
+        tests = [
+            (u'test.ogg', 'application/ogg'),
+            (u'test.svg', 'image/svg+xml'),
+            (u'test.mpg', 'video/mpeg'),
+            (u'test.mp3', 'audio/mpeg'),
+        ]
+        for filename, mimetype in tests:
             m = self._make_macro()
-            result = m.execute('EmbedObject', u'%s' % filename)
-            assert mimetype[index] in result
-            index += 1
+            result = m.execute('EmbedObject', filename)
+            assert mimetype in result
 
     def testEmbedObjectDefaultValues(self):
         """ tests default values of macro EmbedObject """
-        text = '= Example ='
-        self._createTestPage(text)
         m = self._make_macro()
         filename = 'test.ogg'
         result = m.execute('EmbedObject', u'%s' % filename)
 
     def testEmbedObjectPercentHeight(self):
         """ tests a unit value for macro EmbedObject """
-        text = '= Example2 ='
-        self._createTestPage(text)
         m = self._make_macro()
         filename = 'test.ogg'
         height = '50 %' # also tests that space is allowed in there
 
     def testEmbedObjectFromUrl(self):
         """ tests using a URL for macro EmbedObject """
-        text = '= Example3 ='
-        self._createTestPage(text)
         m = self._make_macro()
         target = 'http://localhost/%s?action=AttachFile&do=view&target=test.ogg' % self.pagename
         result = m.execute('EmbedObject', u'target=%s, url_mimetype=application/ogg' % target)
         assert '<object data="http://localhost/AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=view&amp;target=test.ogg" type="application/ogg"' in result
 
 coverage_modules = ['MoinMoin.macro.EmbedObject']
-

File MoinMoin/macro/_tests/test_FootNote.py

 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
 
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 class TestFootNote:
     """ testing macro Action calling action raw """
+    pagename = u'AutoCreatedMoinMoinTemporaryTestPageForFootNote'
 
     def setup_class(self):
-        self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageForFootNote'
-        self.page = PageEditor(self.request, self.pagename)
-        self.shouldDeleteTestPage = True
+        become_trusted(self.request)
+        self.page = create_page(self.request, self.pagename, u"Foo!")
 
     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)
+        nuke_page(self.request, self.pagename)
 
     def _make_macro(self):
         """Test helper"""
 
 
 coverage_modules = ['MoinMoin.macro.FootNote']
-

File MoinMoin/macro/_tests/test_GetVal.py

 from MoinMoin import macro
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests import become_known
+
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 class TestGetVal:
     """GetVal: testing getVal macro """
+    pagename = u'MyDict'
 
-        # injected for you into the test class by moin test framework.
-    def setup_method(self, method):
-        become_known(self.request)
+    def setup_class(self):
+        become_trusted(self.request)
         self.cfg = self.request.cfg
-        self.pagename = u'MyDict'
-        self.page = PageEditor(self.request, self.pagename, do_editor_backup=0)
-        self.shouldDeleteTestPage = True
 
-        # 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_method(self, method):
-        if self.shouldDeleteTestPage:
-            page = PageEditor(self.request, self.pagename, do_editor_backup=0)
-            success_i, msg = page.deletePage()
-
-            fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
-            if os.path.exists(fpath):
-                os.remove(fpath)
-
+    def teardown_class(self):
+        nuke_page(self.request, self.pagename)
 
     def _make_macro(self):
         """Test helper"""
         m = self._make_macro()
         return m.execute(name, args)
 
-    def _createTestPage(self, body):
-        """ Create temporary page """
-        assert body is not None
-
-        self.request.reset()
-        try:
-            self.page.saveText(body, 0)
-        except:
-            pass
-
     def testGetValNoACLs(self):
         """ macro GetVal test: 'reads VAR' """
 
-        self.shouldDeleteTestPage = True
-        self._createTestPage(u' VAR:: This is an example')
+        self.page = create_page(self.request, self.pagename, u' VAR:: This is an example')
 
-        page = Page(self.request, self.pagename)
-        args = "%s,%s" % (self.pagename, u'VAR')
-        result = self._test_macro(u'GetVal', args)
+        result = self._test_macro(u'GetVal', "%s,%s" % (self.pagename, u'VAR'))
 
-        expected = "This is an example"
-        assert result == expected
+        assert result == "This is an example"
 
     def testGetValAfterADictPageIsDeleted(self):
         """ macro GetVal test: 'reads Dict var after another Dict is removed' """
+        request = self.request
 
-        self.shouldDeleteTestPage = True
+        page = create_page(request, u'SomeDict', u" EXAMPLE:: This is an example text")
+        page.deletePage()
 
-        pagename = u'SomeDict'
-        page = PageEditor(self.request, pagename, do_editor_backup=0)
-        body = u" EXAMPLE:: This is an example text"
-        try:
-            page.saveText(body, 0)
-        except:
-            pass
-        success_i, result = page.deletePage()
+        page = create_page(request, self.pagename, u' VAR:: This is a brand new example')
+        result = self._test_macro(u'GetVal', "%s,%s" % (self.pagename, u'VAR'))
 
-        self._createTestPage(u' VAR:: This is a brand new example')
-        page = Page(self.request, self.pagename)
-        args = "%s,%s" % (self.pagename, u'VAR')
-        result = self._test_macro(u'GetVal', args)
+        nuke_page(request, u'SomeDict')
 
-        expected = "This is a brand new example"
-        assert result == expected
+        assert result == "This is a brand new example"
 
     def testGetValACLs(self):
         """ macro GetVal test: 'cant read VAR on an ACL protected page' """
         py.test.skip("user has no rights to create acl pages")
-        self.shouldDeleteTestPage = True
-        self._createTestPage('#acl SomeUser:read,write All:delete\n VAR:: This is an example')
-        args = "%s,%s" % (self.pagename, u'VAR')
-        result = self._test_macro(u'GetVal', args)
-        expected = "&lt;&lt;GetVal: You don't have enough rights on this page&gt;&gt;"
-        assert result == expected
+        self.page = create_page(self.request, self.pagename,
+                                '#acl SomeUser:read,write All:delete\n VAR:: This is an example')
+        result = self._test_macro(u'GetVal', "%s,%s" % (self.pagename, u'VAR'))
+        assert result == "&lt;&lt;GetVal: You don't have enough rights on this page&gt;&gt;"
 
 coverage_modules = ['MoinMoin.macro.GetVal']
 

File MoinMoin/macro/_tests/test_Hits.py

 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
 
+from MoinMoin._tests import become_trusted, create_page, nuke_page
+
 class TestHits:
     """Hits: testing Hits macro """
+    pagename = u'AutoCreatedMoinMoinTemporaryTestPageForHits'
 
     def setup_class(self):
-        self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageForHits'
-        self.page = PageEditor(self.request, self.pagename)
+        request = self.request
+        become_trusted(request)
+        self.page = create_page(request, self.pagename, u"Foo!")
+
         # for that test eventlog needs to be empty
-        fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
+        fpath = 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()
+        caching.CacheEntry(request, 'charts', 'hitcounts', scope='wiki').remove()
 
     def teardown_class(self):
-        import shutil
-        page = PageEditor(self.request, self.pagename)
-        fpath = page.getPagePath(use_underlay=0, check_create=0)
-        shutil.rmtree(fpath, True)
+        nuke_page(self.request, self.pagename)
 
     def _make_macro(self):
         """Test helper"""
         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 _cleanStats(self):
         # cleans all involved cache and log files
         fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
 
     def testHitsNoArg(self):
         """ macro Hits test: 'no args for Hits (Hits is executed on current page) """
-        # Three log entries for the current page and one for WikiSandBox simulating viewing
+        # <count> log entries for the current page and one for WikiSandBox simulating viewing
+        count = 3
         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})
+        for i in range(count):
+            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
+        assert result == str(count)
 
     def testHitsForAll(self):
         """ macro Hits test: 'all=True' for Hits (all pages are counted for VIEWPAGE) """
-        # 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'})
+        # <count> * <num_pages> log entries for simulating viewing
+        pagenames = ['WikiSandBox', self.pagename]
+        num_pages = len(pagenames)
+        count = 2
+        for i in range(count):
+            for pagename in pagenames:
+                eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': pagename})
 
         result = self._test_macro(u'Hits', u'all=True')
         self._cleanStats()
-        expected = "4"
-        assert result == expected
+        assert result == str(count * num_pages)
 
     def testHitsForFilter(self):
         """ macro Hits test: 'event_type=SAVEPAGE' for Hits (SAVEPAGE counted for current page)"""
 
         result = self._test_macro(u'Hits', u'event_type=SAVEPAGE')
         self._cleanStats()
-        expected = "1"
-        assert result == expected
+        assert result == "1"
 
     def testHitsForAllAndFilter(self):
         """ macro test: 'all=True, event_type=SAVEPAGE' for Hits (all pages are counted for SAVEPAGE)"""
 
         result = self._test_macro(u'Hits', u'all=True, event_type=SAVEPAGE')
         self._cleanStats()
-        expected = "2"
-        assert result == expected
-
+        assert result == "2"
 
 coverage_modules = ['MoinMoin.macro.Hits']
-

File MoinMoin/macro/_tests/test_PageHits.py

 from MoinMoin.logfile import eventlog
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
-from MoinMoin._tests import become_trusted
+
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 class TestHits:
     """Hits: testing Hits macro """
+    pagename = u'AutoCreatedMoinMoinTemporaryTestPageForPageHits'
 
     def setup_class(self):
-        become_trusted(self.request)
-        self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageForPageHits'
-        self.page = PageEditor(self.request, self.pagename)
-        self.shouldDeleteTestPage = True
+        request = self.request
+        become_trusted(request)
+        self.page = create_page(request, self.pagename, u"Foo!")
+
         # for that test eventlog needs to be empty
-        fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
+        fpath = 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', 'pagehits', scope='wiki').remove()
-        caching.CacheEntry(self.request, 'charts', 'hitcounts', scope='wiki').remove()
-        arena = Page(self.request, self.pagename)
-        caching.CacheEntry(self.request, arena, 'hitcounts', scope='item').remove()
+        caching.CacheEntry(request, 'charts', 'pagehits', scope='wiki').remove()
+        caching.CacheEntry(request, 'charts', 'hitcounts', scope='wiki').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)
+        nuke_page(self.request, self.pagename)
 
     def _make_macro(self):
         """Test helper"""
         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 testPageHits(self):
         """ macro PageHits test: updating of cache from event-log for multiple call of PageHits"""
-        self.shouldDeleteTestPage = True
-        self._createTestPage('This is an example to test a macro')
-
-        # Three log entries for the current page and one for WikiSandBox simulating viewing
-        for counter in range(20):
+        count = 20
+        for counter in range(count):
             eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': 'PageHits'})
-            result = self._test_macro(u'PageHits', u'')
+            result = self._test_macro(u'PageHits', u'') # XXX SENSE???
 
         cache = caching.CacheEntry(self.request, 'charts', 'pagehits', scope='wiki', use_pickle=True)
         date, hits = 0, {}
                 date, hits = cache.content()
             except caching.CacheError:
                 cache.remove()
-        expected = 20
-        assert hits['PageHits'] == expected
+        assert hits['PageHits'] == count
 
 coverage_modules = ['MoinMoin.macro.PageHits']
-

File MoinMoin/macro/_tests/test_StatsChart.py

 from MoinMoin.logfile import eventlog
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
-from MoinMoin._tests import become_trusted
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 class TestStatsCharts:
     """StartsChart: testing StatsChart macro """
+    pagename = u'AutoCreatedMoinMoinTemporaryTestPageStatsChart'
 
     def setup_class(self):
-        self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageStatsChart'
-        self.page = PageEditor(self.request, self.pagename)
-        self.shouldDeleteTestPage = False
         become_trusted(self.request)
+        self.page = create_page(self.request, self.pagename, u"Foo!")
         # clean page scope cache entries
-        keys = ['text_html', 'pagelinks', ]
-        arena = Page(self.request, self.pagename)
-        for key in keys:
-            caching.CacheEntry(self.request, arena, key, scope='item').remove()
+        for key in ['text_html', 'pagelinks', ]:
+            caching.CacheEntry(self.request, self.page, key, 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)
+        nuke_page(self.request, self.pagename)
 
     def _make_macro(self):
         """Test helper"""
         m = self._make_macro()
         return m.execute(name, args)
 
-    def _createTestPage(self, body):
-        """ Create temporary page """
-        assert body is not None
-        self.request.reset()
-        try:
-            self.page.saveText(body, 0)
-        except self.page.Unchanged:
-            pass
-
     def testStatsChart_useragents(self):
         """ macro StatsChart useragents test: 'tests useragents' and clean page scope cache """
-        self.shouldDeleteTestPage = True
-        self._createTestPage('This is an example to test useragents from StatsChart macro without page cache')
-
         result = self._test_macro(u'StatsChart', u'useragents')
         expected = u'<form action="./AutoCreatedMoinMoinTemporaryTestPageStatsChart" method="GET"'
         assert expected in result
 
     def testStatsChart_hitcounts(self):
         """ macro StatsChart hitcounts test: 'tests hitcounts' and clean page scope cache  """
-        self.shouldDeleteTestPage = True
-        self._createTestPage('This is an example to test hitcounts from StatsChart macro without page cache')
-
         result = self._test_macro(u'StatsChart', u'hitcounts')
         expected = u'<form action="./AutoCreatedMoinMoinTemporaryTestPageStatsChart" method="GET"'
         assert expected in result
 
     def testStatsChart_languages(self):
         """ macro StatsChart languages test: 'tests languages' and clean page scope cache  """
-        self.shouldDeleteTestPage = True
-        self._createTestPage('This is an example to test languages from StatsChart macro without page cache')
-
         result = self._test_macro(u'StatsChart', u'hitcounts')
         expected = u'<form action="./AutoCreatedMoinMoinTemporaryTestPageStatsChart" method="GET"'
         assert expected in result
 
 coverage_modules = ['MoinMoin.stats']
-

File MoinMoin/security/_tests/test_security.py

 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.user import User
 
+from MoinMoin._tests import become_trusted, create_page, nuke_page
 
 class TestACLStringIterator(object):
 
             for right in mayNot:
                 assert not acl.may(self.request, user, right)
 
-    def testACLsWithoutEditLogEntry(self):
-        """ tests what are the page rights if edit-log entry doesn't exist
-            for a page where no access is given to
-        """
-        py.test.skip("test tricks out the caching system, page modifications without making an edit-log entry are not supported")
-        import os
-        from MoinMoin.PageEditor import PageEditor
-        pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
-
-        result = self.request.user.may.write(pagename)
-        page = PageEditor(self.request, pagename)
-        path = page.getPagePath(use_underlay=0, check_create=0)
-        if os.path.exists(path):
-            py.test.skip("%s exists. Won't overwrite exiting page" % self.dictPage)
-
-        try:
-            try:
-                os.mkdir(path)
-                revisionsDir = os.path.join(path, 'revisions')
-                os.mkdir(revisionsDir)
-                current = '00000001'
-                file(os.path.join(path, 'current'), 'w').write('%s\n' % current)
-                text = u'#acl All: \n'
-                file(os.path.join(revisionsDir, current), 'w').write(text)
-            except Exception, err:
-                py.test.skip("Can not be create test page: %s" % err)
-
-            assert not self.request.user.may.write(pagename)
-        finally:
-            if os.path.exists(path):
-                import shutil
-                page.deletePage()
-                shutil.rmtree(path, True)
 
 class TestPageAcls(object):
     """ security: real-life access control list on pages testing
         self.request.user = User(self.request, auth_username=u'WikiAdmin')
         self.request.user.valid = True
 
-        for pagename, page_content in self.pages:
-            page = PageEditor(self.request, pagename, do_editor_backup=False)
-            if not page.exists():
-                page.saveText(page_content, 0)
+        for page_name, page_content in self.pages:
+            create_page(self.request, page_name, page_content)
 
     def teardown_class(self):
         del self.config
         # Restore user
         self.request.user.name = self.savedUser
 
+        for page_name, dummy in self.pages:
+            nuke_page(self.request, page_name)
+
     def testPageACLs(self):
         """ security: test page acls """
         tests = [
                 assert not can_access
 
 coverage_modules = ['MoinMoin.security']
-