changeset 3503:383fda7ebfd1

tests: add some clarifications to become_trusted/become_valid, use become_trusted instead of become_superuser when it does not need superuser permissions
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Apr 2008 22:23:22 +0200
parents 02b73ceab324
children 7ee94ad36708
files MoinMoin/_tests/__init__.py MoinMoin/_tests/test_PageEditor.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 7 files changed, 23 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/__init__.py	Sun Apr 13 21:41:06 2008 +0200
+++ b/MoinMoin/_tests/__init__.py	Sun Apr 13 22:23:22 2008 +0200
@@ -7,25 +7,28 @@
     @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 """
+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
+        we have a user profile for this user as the ACL system will check if
+        there is a userid for this username.
+        Thus, for testing purposes (e.g. if you need delete rights), it is
+        easier to use become_trusted().
+    """
     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)
+    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 (and thus in "Known" ACL pseudo group),
+        also make the user valid (see notes in become_valid()),
         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.
     """
--- a/MoinMoin/_tests/test_PageEditor.py	Sun Apr 13 21:41:06 2008 +0200
+++ b/MoinMoin/_tests/test_PageEditor.py	Sun Apr 13 22:23:22 2008 +0200
@@ -12,7 +12,7 @@
 from MoinMoin import wikiutil
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests import become_superuser
+from MoinMoin._tests import become_trusted
 
 class TestExpandVars(object):
     """PageEditor: testing page editor"""
@@ -172,7 +172,7 @@
 
     def setup_method(self, method):
         self.old_handlers = self.request.cfg.event_handlers
-        become_superuser(self.request)
+        become_trusted(self.request)
 
     def teardown_method(self, method):
         self.request.cfg.event_handlers = self.old_handlers
--- a/MoinMoin/_tests/test_wikidicts.py	Sun Apr 13 21:41:06 2008 +0200
+++ b/MoinMoin/_tests/test_wikidicts.py	Sun Apr 13 22:23:22 2008 +0200
@@ -14,7 +14,7 @@
 from MoinMoin import wikidicts
 from MoinMoin import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests import become_superuser
+from MoinMoin._tests import become_trusted
 
 class TestGroupPage:
 
@@ -121,7 +121,7 @@
         """
          tests if the dict cache for groups is refreshed after renaming a Group page
         """
-        become_superuser(self.request)
+        become_trusted(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
         """
-        become_superuser(self.request)
+        become_trusted(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 21:41:06 2008 +0200
+++ b/MoinMoin/action/_tests/test_attachfile.py	Sun Apr 13 22:23:22 2008 +0200
@@ -9,12 +9,12 @@
 import os
 from MoinMoin.action import AttachFile
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests import become_superuser
+from MoinMoin._tests import become_trusted
 
 def test_add_attachment(request):
     """Test if add_attachment() works"""
 
-    become_superuser(request)
+    become_trusted(request)
     pagename = "AutoCreatedSillyPageToTestAttachments"
     filename = "AutoCreatedSillyAttachment"
 
--- a/MoinMoin/macro/_tests/test_GetVal.py	Sun Apr 13 21:41:06 2008 +0200
+++ b/MoinMoin/macro/_tests/test_GetVal.py	Sun Apr 13 22:23:22 2008 +0200
@@ -11,14 +11,14 @@
 from MoinMoin import macro
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests import become_superuser
+from MoinMoin._tests import become_known
 
 class TestGetVal:
     """GetVal: testing getVal macro """
 
         # injected for you into the test class by moin test framework.
     def setup_method(self, method):
-        become_superuser(self.request)
+        become_known(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 21:41:06 2008 +0200
+++ b/MoinMoin/macro/_tests/test_PageHits.py	Sun Apr 13 22:23:22 2008 +0200
@@ -12,13 +12,13 @@
 from MoinMoin.logfile import eventlog
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
-from MoinMoin._tests import become_superuser
+from MoinMoin._tests import become_trusted
 
 class TestHits:
     """Hits: testing Hits macro """
 
     def setup_class(self):
-        become_superuser(self.request)
+        become_trusted(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 21:41:06 2008 +0200
+++ b/MoinMoin/macro/_tests/test_StatsChart.py	Sun Apr 13 22:23:22 2008 +0200
@@ -12,7 +12,7 @@
 from MoinMoin.logfile import eventlog
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
-from MoinMoin._tests import become_superuser
+from MoinMoin._tests import become_trusted
 
 class TestStatsCharts:
     """StartsChart: testing StatsChart macro """
@@ -21,7 +21,7 @@
         self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageStatsChart'
         self.page = PageEditor(self.request, self.pagename)
         self.shouldDeleteTestPage = False
-        become_superuser(self.request)
+        become_trusted(self.request)
         # clean page scope cache entries
         keys = ['text_html', 'pagelinks', ]
         arena = Page(self.request, self.pagename)