changeset 3502:02b73ceab324

tests: move code from MoinMoin._tests.common to MoinMoin._tests, rename gain_superuser_rights to become_superuser, add become_known and become_trusted
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Apr 2008 21:41:06 +0200
parents 159b08b1d9ff
children 383fda7ebfd1
files MoinMoin/_tests/__init__.py MoinMoin/_tests/common.py MoinMoin/_tests/test_PageEditor.py MoinMoin/_tests/test_packages.py MoinMoin/_tests/test_wikidicts.py MoinMoin/action/_tests/test_attachfile.py MoinMoin/macro/_tests/test_GetVal.py MoinMoin/macro/_tests/test_PageHits.py MoinMoin/macro/_tests/test_StatsChart.py
diffstat 9 files changed, 50 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/__init__.py	Sun Apr 13 18:04:46 2008 +0200
+++ b/MoinMoin/_tests/__init__.py	Sun Apr 13 21:41:06 2008 +0200
@@ -0,0 +1,35 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - some common code for testing
+
+    @copyright: 2007 MoinMoin:KarolNowak,
+                2008 MoinMoin:ThomasWaldmann
+    @license: GNU GPL, see COPYING for details.
+"""
+
+def become_known(request, username=u"KnownUser"):
+    """ modify request.user to make the user valid, so it is in acl group Known """
+    request.user.name = username
+    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_known(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 (and thus in "Known" ACL pseudo group),
+        also make the user trusted (and thus in "Trusted" ACL pseudo group).
+
+        TODO: check why many tests fail if we just use "become_known" instead
+              of "become_trusted". Then refactor to only use "become_known".
+
+        Note: being superuser is completely unrelated to ACL rights,
+              especially it is not related to ACL admin rights.
+    """
+    su_name = u"SuperUser"
+    become_trusted(request, su_name)
+    if su_name not in request.cfg.superuser:
+        request.cfg.superuser.append(su_name)
--- a/MoinMoin/_tests/common.py	Sun Apr 13 18:04:46 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - MoinMoin.packages tests - common code
-
-    @copyright: 2007 MoinMoin:KarolNowak
-    @license: GNU GPL, see COPYING for details.
-"""
-
-def gain_superuser_rights(request):
-    request.user.name = "SuperUserName"
-    request.user.valid = 1
-    request.user.may.name = request.user.name
-    request.cfg.superuser.append(request.user.name)
-    request.user.auth_method = request.cfg.auth_methods_trusted[0]
--- a/MoinMoin/_tests/test_PageEditor.py	Sun Apr 13 18:04:46 2008 +0200
+++ b/MoinMoin/_tests/test_PageEditor.py	Sun Apr 13 21:41:06 2008 +0200
@@ -12,7 +12,7 @@
 from MoinMoin import wikiutil
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests.common import gain_superuser_rights
+from MoinMoin._tests import become_superuser
 
 class TestExpandVars(object):
     """PageEditor: testing page editor"""
@@ -172,7 +172,7 @@
 
     def setup_method(self, method):
         self.old_handlers = self.request.cfg.event_handlers
-        gain_superuser_rights(self.request)
+        become_superuser(self.request)
 
     def teardown_method(self, method):
         self.request.cfg.event_handlers = self.old_handlers
--- a/MoinMoin/_tests/test_packages.py	Sun Apr 13 18:04:46 2008 +0200
+++ b/MoinMoin/_tests/test_packages.py	Sun Apr 13 21:41:06 2008 +0200
@@ -15,7 +15,7 @@
 from MoinMoin.Page import Page
 from MoinMoin.action.PackagePages import PackagePages
 from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, packLine, unpackLine
-from MoinMoin._tests.common import gain_superuser_rights
+from MoinMoin._tests import become_superuser
 
 
 class DebugPackage(Package, ScriptEngine):
@@ -66,7 +66,7 @@
 """).installPackage()
 
     def testBasicPackageThings(self):
-        gain_superuser_rights(self.request)
+        become_superuser(self.request)
         myPackage = DebugPackage(self.request, 'test')
         myPackage.installPackage()
         assert myPackage.msg == u'foo\nFooPage added \n'
--- a/MoinMoin/_tests/test_wikidicts.py	Sun Apr 13 18:04:46 2008 +0200
+++ b/MoinMoin/_tests/test_wikidicts.py	Sun Apr 13 21:41:06 2008 +0200
@@ -14,7 +14,7 @@
 from MoinMoin import wikidicts
 from MoinMoin import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests.common import gain_superuser_rights
+from MoinMoin._tests import become_superuser
 
 class TestGroupPage:
 
@@ -121,7 +121,7 @@
         """
          tests if the dict cache for groups is refreshed after renaming a Group page
         """
-        gain_superuser_rights(self.request)
+        become_superuser(self.request)
         pagename = u'SomeGroup'
         page = PageEditor(self.request, pagename, do_editor_backup=False)
         body = " * ExampleUser"
@@ -150,7 +150,7 @@
         """
          tests if the dict cache for groups is refreshed after copying a Group page
         """
-        gain_superuser_rights(self.request)
+        become_superuser(self.request)
         pagename = u'SomeGroup'
         page = PageEditor(self.request, pagename, do_editor_backup=False)
         body = " * ExampleUser"
--- a/MoinMoin/action/_tests/test_attachfile.py	Sun Apr 13 18:04:46 2008 +0200
+++ b/MoinMoin/action/_tests/test_attachfile.py	Sun Apr 13 21:41:06 2008 +0200
@@ -9,12 +9,12 @@
 import os
 from MoinMoin.action import AttachFile
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests.common import gain_superuser_rights
+from MoinMoin._tests import become_superuser
 
 def test_add_attachment(request):
     """Test if add_attachment() works"""
 
-    gain_superuser_rights(request)
+    become_superuser(request)
     pagename = "AutoCreatedSillyPageToTestAttachments"
     filename = "AutoCreatedSillyAttachment"
 
--- a/MoinMoin/macro/_tests/test_GetVal.py	Sun Apr 13 18:04:46 2008 +0200
+++ b/MoinMoin/macro/_tests/test_GetVal.py	Sun Apr 13 21:41:06 2008 +0200
@@ -11,14 +11,14 @@
 from MoinMoin import macro
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests.common import gain_superuser_rights
+from MoinMoin._tests import become_superuser
 
 class TestGetVal:
     """GetVal: testing getVal macro """
 
         # injected for you into the test class by moin test framework.
     def setup_method(self, method):
-        gain_superuser_rights(self.request)
+        become_superuser(self.request)
         self.cfg = self.request.cfg
         self.pagename = u'MyDict'
         self.page = PageEditor(self.request, self.pagename, do_editor_backup=0)
--- a/MoinMoin/macro/_tests/test_PageHits.py	Sun Apr 13 18:04:46 2008 +0200
+++ b/MoinMoin/macro/_tests/test_PageHits.py	Sun Apr 13 21:41:06 2008 +0200
@@ -12,13 +12,13 @@
 from MoinMoin.logfile import eventlog
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
-from MoinMoin._tests.common import gain_superuser_rights
+from MoinMoin._tests import become_superuser
 
 class TestHits:
     """Hits: testing Hits macro """
 
     def setup_class(self):
-        gain_superuser_rights(self.request)
+        become_superuser(self.request)
         self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageForPageHits'
         self.page = PageEditor(self.request, self.pagename)
         self.shouldDeleteTestPage = True
--- a/MoinMoin/macro/_tests/test_StatsChart.py	Sun Apr 13 18:04:46 2008 +0200
+++ b/MoinMoin/macro/_tests/test_StatsChart.py	Sun Apr 13 21:41:06 2008 +0200
@@ -12,7 +12,7 @@
 from MoinMoin.logfile import eventlog
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
-from MoinMoin._tests.common import gain_superuser_rights
+from MoinMoin._tests import become_superuser
 
 class TestStatsCharts:
     """StartsChart: testing StatsChart macro """
@@ -21,7 +21,7 @@
         self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageStatsChart'
         self.page = PageEditor(self.request, self.pagename)
         self.shouldDeleteTestPage = False
-        gain_superuser_rights(self.request)
+        become_superuser(self.request)
         # clean page scope cache entries
         keys = ['text_html', 'pagelinks', ]
         arena = Page(self.request, self.pagename)