changeset 1992:d06e56e20b91

use more constants: ANON for anonymous
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 12 Feb 2013 20:11:39 +0100
parents 38e79cd2b320
children e0a036c7f7f7 02f24ba9623d
files MoinMoin/app.py MoinMoin/auth/_tests/test_auth.py MoinMoin/auth/_tests/test_http.py MoinMoin/auth/_tests/test_log.py MoinMoin/constants/misc.py MoinMoin/items/_tests/test_Blog.py MoinMoin/user.py
diffstat 7 files changed, 21 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/app.py	Tue Feb 12 17:54:59 2013 +0100
+++ b/MoinMoin/app.py	Tue Feb 12 20:11:39 2013 +0100
@@ -28,6 +28,7 @@
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
+from MoinMoin.constants.misc import ANON
 from MoinMoin.i18n import i18n_init
 from MoinMoin.i18n import _, L_, N_
 
@@ -223,7 +224,7 @@
 
     # if we still have no user obj, create a dummy:
     if not userobj:
-        userobj = user.User(name=u'anonymous', auth_method='invalid')
+        userobj = user.User(name=ANON, auth_method='invalid')
     # if we have a valid user we store it in the session
     if userobj.valid:
         session['user.itemid'] = userobj.itemid
--- a/MoinMoin/auth/_tests/test_auth.py	Tue Feb 12 17:54:59 2013 +0100
+++ b/MoinMoin/auth/_tests/test_auth.py	Tue Feb 12 20:11:39 2013 +0100
@@ -8,6 +8,7 @@
 from flask import g as flaskg
 
 from MoinMoin._tests import wikiconfig
+from MoinMoin.constants.misc import ANON
 from MoinMoin.auth import GivenAuth, handle_login, get_multistage_continuation_url
 from MoinMoin.user import create_user
 
@@ -57,7 +58,7 @@
     test_user1 = handle_login(flaskg.user, login_username='test_user', login_password='test_password', stage='moin')
     test_login_message = [u'Invalid username or password.']
     assert flaskg._login_messages == test_login_message
-    assert test_user1.name0 == u'anonymous'
+    assert test_user1.name0 == ANON
     assert not test_user1.valid
     # pop the message
     flaskg._login_messages.pop()
--- a/MoinMoin/auth/_tests/test_http.py	Tue Feb 12 17:54:59 2013 +0100
+++ b/MoinMoin/auth/_tests/test_http.py	Tue Feb 12 20:11:39 2013 +0100
@@ -10,6 +10,7 @@
 
 from MoinMoin.user import create_user
 from MoinMoin.auth.http import HTTPAuthMoin
+from MoinMoin.constants.misc import ANON
 
 
 class TestHTTPAuthMoin(object):
@@ -41,4 +42,4 @@
         flaskg.user.auth_method = 'invalid'
         test_user, bool_val = httpauthmoin_obj.request(flaskg.user)
         assert not test_user.valid
-        assert test_user.name0 == u'anonymous'
+        assert test_user.name0 == ANON
--- a/MoinMoin/auth/_tests/test_log.py	Tue Feb 12 17:54:59 2013 +0100
+++ b/MoinMoin/auth/_tests/test_log.py	Tue Feb 12 20:11:39 2013 +0100
@@ -8,8 +8,10 @@
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
+from flask import g as flaskg
+
 from MoinMoin.auth.log import AuthLog
-from flask import g as flaskg
+from MoinMoin.constants.misc import ANON
 
 
 class TestAuthLog(object):
@@ -19,13 +21,13 @@
         result = authlog_obj.login(flaskg.user)
         assert result.continue_flag
         test_user_obj = result.user_obj
-        assert test_user_obj.name0 == u'anonymous'
+        assert test_user_obj.name0 == ANON
 
     def test_request(self):
         authlog_obj = AuthLog()
         result = authlog_obj.request(flaskg.user)
         test_user, bool_value = result
-        assert test_user.name0 == u'anonymous'
+        assert test_user.name0 == ANON
         assert not test_user.valid
         assert bool_value
 
@@ -33,6 +35,6 @@
         authlog_obj = AuthLog()
         result = authlog_obj.logout(flaskg.user)
         test_user, bool_value = result
-        assert test_user.name0 == u'anonymous'
+        assert test_user.name0 == ANON
         assert not test_user.valid
         assert bool_value
--- a/MoinMoin/constants/misc.py	Tue Feb 12 17:54:59 2013 +0100
+++ b/MoinMoin/constants/misc.py	Tue Feb 12 20:11:39 2013 +0100
@@ -7,6 +7,8 @@
 
 import re
 
+ANON = u'anonymous'
+
 # Invalid characters - invisible characters that should not be in page
 # names. Prevent user confusion and wiki abuse, e.g u'\u202aFrontPage'.
 ITEM_INVALID_CHARS_REGEX = re.compile(
--- a/MoinMoin/items/_tests/test_Blog.py	Tue Feb 12 17:54:59 2013 +0100
+++ b/MoinMoin/items/_tests/test_Blog.py	Tue Feb 12 20:11:39 2013 +0100
@@ -12,6 +12,7 @@
 from MoinMoin._tests import become_trusted, update_item
 from MoinMoin.items import Item
 from MoinMoin.constants.keys import CONTENTTYPE, ITEMTYPE, PTIME, ACL, TAGS
+from MoinMoin.constants.misc import ANON
 from MoinMoin.items.blog import ITEMTYPE_BLOG, ITEMTYPE_BLOG_ENTRY
 from MoinMoin.items.blog import Blog, BlogEntry
 
@@ -122,10 +123,10 @@
             item._save(self.entry_meta, entry['data'], comment=self.comment)
         # publish the first three entries with specific ACLs
         # we are an "anonymous" user
-        self._publish_entry(self.entries[0], ptime=1000, acl=u"anonymous:read")
-        self._publish_entry(self.entries[1], ptime=3000, acl=u"anonymous:read")
+        self._publish_entry(self.entries[0], ptime=1000, acl=u"%s:read" % ANON)
+        self._publish_entry(self.entries[1], ptime=3000, acl=u"%s:read" % ANON)
         # specify no rights on the 3rd entry
-        self._publish_entry(self.entries[2], ptime=2000, acl=u"anonymous:")
+        self._publish_entry(self.entries[2], ptime=2000, acl=u"%s:" % ANON)
         # the blog is not empty and the 3rd entry is not displayed
         exclude_data_tokens = [self.NO_ENTRIES_MSG, self.entries[2]['data'], ]
         ordered_data = [self.data,
--- a/MoinMoin/user.py	Tue Feb 12 17:54:59 2013 +0100
+++ b/MoinMoin/user.py	Tue Feb 12 20:11:39 2013 +0100
@@ -37,6 +37,7 @@
 from MoinMoin import wikiutil
 from MoinMoin.constants.contenttypes import CONTENTTYPE_USER
 from MoinMoin.constants.keys import *
+from MoinMoin.constants.misc import ANON
 from MoinMoin.i18n import _, L_, N_
 from MoinMoin.mail import sendmail
 from MoinMoin.util.interwiki import getInterwikiHome, getInterwikiName, is_local_wiki
@@ -287,7 +288,7 @@
             users = search_users(**{NAME_EXACT: auth_username})
             if users:
                 itemid = users[0].meta[ITEMID]
-        if not itemid and _name and _name != 'anonymous':
+        if not itemid and _name and _name != ANON:
             users = search_users(**{NAME_EXACT: _name})
             if users:
                 itemid = users[0].meta[ITEMID]
@@ -331,7 +332,7 @@
             assert isinstance(names, list)
             return names[0]
         except IndexError:
-            return u'anonymous'
+            return ANON
 
     @property
     def language(self):