changeset 4803:167db6117bb4

Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Thu, 11 Jun 2009 13:48:54 +0200
parents 878b5a87ba3b
children 3cea38408fe6
files MoinMoin/groups/__init__.py MoinMoin/groups/_tests/test_group_manager.py MoinMoin/groups/_tests/test_group_manager_acl.py MoinMoin/groups/backends/__init__.py MoinMoin/groups/backends/_tests/__init__.py MoinMoin/groups/backends/_tests/test_config_group.py MoinMoin/groups/backends/_tests/test_wiki_group.py MoinMoin/groups/backends/config_group.py MoinMoin/groups/backends/wiki_group.py
diffstat 9 files changed, 30 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/groups/__init__.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/__init__.py	Thu Jun 11 13:48:54 2009 +0200
@@ -71,7 +71,6 @@
             if callable(update_cache):
                 update_cache()
 
-
     def load_cache(self):
         for backend in self._backends:
             load_cache = getattr(backend, 'load_cache', None)
@@ -80,3 +79,4 @@
 
     def __repr__(self):
         return "<%s backends=%s>" % (self.__class__, self._backends)
+
--- a/MoinMoin/groups/_tests/test_group_manager.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/_tests/test_group_manager.py	Thu Jun 11 13:48:54 2009 +0200
@@ -12,12 +12,13 @@
 
 from MoinMoin.groups import GroupManager
 from MoinMoin.groups.backends import config_group
+from MoinMoin._tests import wikiconfig
 
 
 class TestGroupManager(object):
 
-    from MoinMoin._tests import wikiconfig
     class Config(wikiconfig.Config):
+
         admin_group = frozenset([u'Admin', u'JohnDoe'])
         editor_group = frozenset([u'MainEditor', u'JohnDoe'])
         fruit_group = frozenset([u'Apple', u'Banana', u'Cherry'])
@@ -38,6 +39,7 @@
                                  # AdminGroup is defined in both
                                  # first_backend and second_backend.
                                  u'AdminGroup': second_admin_group}
+
         def group_manager_init(self, request):
             return GroupManager(backends=[config_group.Backend(request, self.first_backend_groups),
                                           config_group.Backend(request, self.second_backend_groups)])
--- a/MoinMoin/groups/_tests/test_group_manager_acl.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/_tests/test_group_manager_acl.py	Thu Jun 11 13:48:54 2009 +0200
@@ -10,6 +10,7 @@
 from MoinMoin import security
 from MoinMoin.groups import GroupManager
 from MoinMoin.groups.backends import config_group
+from MoinMoin._tests import wikiconfig
 
 
 class TestGroupManagerACL:
@@ -17,8 +18,8 @@
     Test how GroupManager works with the acl code.
     """
 
-    from MoinMoin._tests import wikiconfig
     class Config(wikiconfig.Config):
+
         def group_manager_init(self, request):
             groups = {u'FirstGroup': frozenset([u"ExampleUser", u"SecondUser", u"JoeDoe"]),
                       u'SecondGroup': frozenset([u"ExampleUser", u"ThirdUser"])}
--- a/MoinMoin/groups/backends/__init__.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/backends/__init__.py	Thu Jun 11 13:48:54 2009 +0200
@@ -6,6 +6,7 @@
 @license: GPL, see COPYING for details
 """
 
+
 class BaseGroup(object):
 
     def __init__(self, request, name, backend):
@@ -80,17 +81,14 @@
 
         for member in self.members:
             if member not in yielded_members:
+                yielded_members.add(member)
                 yield member
-                yielded_members.add(member)
 
         groups = self.request.groups
         for group_name in self.member_groups:
             if group_name not in processed_groups:
                 for member in groups[group_name]._iter(yielded_members, processed_groups):
-                    if member not in yielded_members:
-                        yield member
-                        yielded_members.add(member)
-
+                    yield member
 
     def __iter__(self):
         """
@@ -111,7 +109,6 @@
         self.request = request
         self.page_group_regex = request.cfg.cache.page_group_regexact
 
-
     def __contains__(self, group_name):
         """
         Check if a group called <group_name> is available in this backend.
@@ -145,5 +142,5 @@
         return backend_group_name
 
     def __repr__(self):
-        return "<%s groups=%s>" % (self.__class__, [b for b in self] )
+        return "<%s groups=%s>" % (self.__class__, [b for b in self])
 
--- a/MoinMoin/groups/backends/_tests/__init__.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/backends/_tests/__init__.py	Thu Jun 11 13:48:54 2009 +0200
@@ -13,19 +13,11 @@
 from py.test import raises
 
 from MoinMoin import security
-from MoinMoin._tests import wikiconfig
 
-class Config(wikiconfig.Config):
-    # Simply drop the "Group" postfix for group names given to a backend.
-    # Note: in the real world, this would not work good enough:
-    to_backend_name = lambda self, group_name:  group_name[:-5]
-    # Add "Group" postfix for group names received from a backend.
-    # Note: in the real world, this would not work good enough:
-    to_group_name = lambda self, backend_name:'%sGroup' % backend_name
 
 class BackendTest(object):
 
-    test_groups = {u'EditorGroup': [u'AdminGroup', u'John', u'JoeDoe', u'Editor1'],
+    test_groups = {u'EditorGroup': [u'AdminGroup', u'John', u'JoeDoe', u'Editor1', u'John'],
                    u'AdminGroup': [u'Admin1', u'Admin2', u'John'],
                    u'OtherGroup': [u'SomethingOther'],
                    u'RecursiveGroup': [u'Something', u'OtherRecursiveGroup'],
@@ -40,21 +32,13 @@
                        u'OtherRecursiveGroup': [u'Anything', u'Something'],
                        u'ThirdRecursiveGroup': [u'Banana']}
 
-    # These backend group names do not follow moin convention:
-    mapped_groups = {u'Editor': [u'Admin', u'John', u'JoeDoe', u'Editor1'],
-                     u'Admin': [u'Admin1', u'Admin2', u'John'],
-                     u'Other': [u'SomethingOther'],
-                     u'Recursive': [u'Something', u'OtherRecursive'],
-                     u'OtherRecursive': [u'Recursive', u'Anything'],
-                     u'ThirdRecursive': [u'ThirdRecursive', u'Banana']}
-
     def test_contains(self):
         """
         Test group_wiki Backend and Group containment methods.
         """
         groups = self.request.groups
 
-        for (group, members) in self.expanded_groups.iteritems():
+        for group, members in self.expanded_groups.iteritems():
             print group
             assert group in groups
             for member in members:
@@ -65,7 +49,7 @@
     def test_iter(self):
         groups = self.request.groups
 
-        for (group, members) in self.expanded_groups.iteritems():
+        for group, members in self.expanded_groups.iteritems():
             returned_members = [x for x in groups[group]]
             assert len(returned_members) == len(members)
             for member in members:
@@ -128,23 +112,6 @@
         assert not acl.may(request, u"Someone", "delete")
         assert not acl.may(request, u"Someone", "admin")
 
-class BackendTestMapping(BackendTest):
-    """
-    Test group name mapping:
-        moin -> backend (e.g. "AdminGroup" -> "ImportantAdminGroup")
-        backend -> moin (e.g. "ImportantAdminGroup" -> "AdminGroup")
-
-    Moin expects group names to match the page_group_regex (e.g. "AdminGroup"),
-    but a backend might want to use different group names (e.g. just "ImportantAdminGroup").
-    """
-    test_groups = {u'ImportantEditorGroup': [u'ImportantAdminGroup', u'John',
-                                             u'JoeDoe', u'Editor'],
-                   u'ImportantAdminGroup': [u'Admin', u'Admin2', u'John'],
-                   u'ImportantOtherGroup': [u'SomethingOther'],
-                   u'ImportantRecursiveGroup': [u'Something', u'ImportantOtherRecursiveGroup'],
-                   u'ImportantOtherRecursiveGroup': [u'ImportantRecursiveGroup', u'Anything'],
-                   u'ImportantThirdRecursiveGroup': [u'ImportantThirdRecursiveGroup', u'Banana']}
-
 
 coverage_modules = ['MoinMoin.groups.backends.config_group']
 
--- a/MoinMoin/groups/backends/_tests/test_config_group.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/backends/_tests/test_config_group.py	Thu Jun 11 13:48:54 2009 +0200
@@ -10,27 +10,20 @@
 
 """
 
-from  MoinMoin.groups.backends._tests import BackendTest, BackendTestMapping, Config
+from  MoinMoin.groups.backends._tests import BackendTest
 from MoinMoin.groups.backends import config_group
 from MoinMoin.groups import GroupManager
+from MoinMoin._tests import wikiconfig
+
 
 class TestConfigBackend(BackendTest):
 
-    class Config(Config):
+    class Config(wikiconfig.Config):
+
         def group_manager_init(self, request):
             self.config_groups = BackendTest.test_groups
             return GroupManager(backends=[config_group.Backend(request)])
 
-class TestConfigBackendMapping(TestConfigBackend):
-
-    class Config(Config):
-        def group_manager_init(self, request):
-            backend = config_group.Backend(request, TestConfigBackend.mapped_groups)
-
-            backend.to_backend_name = self.to_backend_name
-            backend.to_group_name = self.to_group_name
-
-            return GroupManager(backends=[backend])
 
 coverage_modules = ['MoinMoin.groups.backends.config_group']
 
--- a/MoinMoin/groups/backends/_tests/test_wiki_group.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/backends/_tests/test_wiki_group.py	Thu Jun 11 13:48:54 2009 +0200
@@ -13,20 +13,22 @@
 from py.test import raises
 import re, shutil
 
-from  MoinMoin.groups.backends._tests import BackendTest, BackendTestMapping, Config
+from  MoinMoin.groups.backends._tests import BackendTest
 from MoinMoin.groups.backends import wiki_group
 from MoinMoin import Page, security
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.user import User
-from MoinMoin._tests import append_page, become_trusted, create_page, create_random_string_list, nuke_page, nuke_user
+from MoinMoin._tests import append_page, become_trusted, create_page, create_random_string_list, nuke_page, nuke_user, wikiconfig
 from MoinMoin.groups import GroupManager
 
+
 class TestWikiGroupPageParser(object):
     """
     Test what backend extracts from a group page and what is ignored.
     """
 
-    class Config(Config):
+    class Config(wikiconfig.Config):
+
         def group_manager_init(self, request):
             return GroupManager(backends=[wiki_group.Backend(request)])
 
@@ -83,7 +85,8 @@
 
 class TestWikiGroupBackend(BackendTest):
 
-    class Config(Config):
+    class Config(wikiconfig.Config):
+
         def group_manager_init(self, request):
             return GroupManager(backends=[wiki_group.Backend(request)])
 
--- a/MoinMoin/groups/backends/config_group.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/backends/config_group.py	Thu Jun 11 13:48:54 2009 +0200
@@ -2,7 +2,7 @@
 """
 MoinMoin - config group backend
 
-The wiki group backend enables you to define groups in a configuration file.
+The config group backend enables you to define groups in a configuration file.
 
 @copyright: 2009 MoinMoin:DmitrijsMilajevs
 @license: GPL, see COPYING for details
@@ -10,7 +10,9 @@
 
 from MoinMoin.groups.backends import BaseGroup, BaseBackend
 
+
 class Group(BaseGroup):
+
     def _load_group(self):
         request = self.request
         backend_group_name = self.to_backend_name(self.name)
@@ -27,6 +29,7 @@
         self.members = members_final
         self.member_groups = member_groups
 
+
 class Backend(BaseBackend):
 
     def __init__(self, request, groups=None):
--- a/MoinMoin/groups/backends/wiki_group.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/backends/wiki_group.py	Thu Jun 11 13:48:54 2009 +0200
@@ -4,7 +4,7 @@
 
 The wiki group backend enables you to define groups on wiki pages.  To
 find group pages, request.cfg.cache.page_group_regexact pattern is
-used.  To find group members, it parses theses pages and extracts the
+used.  To find group members, it parses these pages and extracts the
 first level list (wiki markup).
 
 @copyright: 2008 MoinMoin:ThomasWaldmann,