changeset 4802:878b5a87ba3b

Groups2009: BackendManager was killed. GroupManager tests updated to use config_group.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Wed, 10 Jun 2009 20:32:42 +0200
parents 1d90fe5f1bcf
children 167db6117bb4
files MoinMoin/groups/__init__.py MoinMoin/groups/_tests/test_backend_manager.py MoinMoin/groups/_tests/test_group_manager.py MoinMoin/groups/_tests/test_group_manager_acl.py
diffstat 4 files changed, 7 insertions(+), 161 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/groups/__init__.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/__init__.py	Wed Jun 10 20:32:42 2009 +0200
@@ -7,66 +7,6 @@
 """
 
 
-class BackendManager(object):
-    """
-    A BackendManager maps a group name to a Group object.
-    It provides access to groups of one specific backend.
-    """
-
-    def __init__(self, backend, mapper_to_backend=lambda x: x, mapper_from_backend=lambda x: x):
-        """
-        Create backend manager object.
-
-        XXX Decorators can be used for group name mapping.
-
-        @param request: request object.
-
-        @param backend: the group backend which provides access to the
-                        group definitions.
-
-        @param mapper_to_backend: a function mapping the moin group
-                                  name to the backend group name
-
-        @param mapper_from_backend: a function mapping the backend
-                                    group name to the moin group name
-        """
-        self._backend = backend
-        self.mapper_to_backend = mapper_to_backend
-        self.mapper_from_backend =  mapper_from_backend
-
-    def __getitem__(self, group_name):
-        """
-        Get a group by its name.
-
-        @param group_name: name of the group [unicode]
-        """
-        return self._backend[self.mapper_to_backend(group_name)]
-
-    def __iter__(self):
-        """
-        Iterate over group names of the groups defined in this backend.
-        """
-        return (self.mapper_from_backend(group_name) for group_name in self._backend)
-
-    def __contains__(self, group_name):
-        """
-        Check if a group called group_name is available in this backend.
-
-        @param group_name: name of the group [unicode]
-        """
-        return self.mapper_to_backend(group_name) in self._backend
-
-    def membergroups(self, member):
-        """
-        List all group names of the groups where <member> is a member of.
-
-        @param member: member name [unicode]
-        @return: list of group names [unicode]
-        """
-        return [group_name for group_name in self
-                if member in self[group_name]]
-
-
 class GroupManager(object):
     """
     GroupManager manages several group backends.
--- a/MoinMoin/groups/_tests/test_backend_manager.py	Wed Jun 10 20:32:42 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-
-"""
-MoinMoin.groups.BackendManager test
-
-@copyright: 2009 MoinMoin:DmitrijsMilajevs
-@license: GPL, see COPYING for details
-"""
-
-from py.test import raises
-
-from MoinMoin.groups import BackendManager
-
-
-class TestBackendManager(object):
-
-    def setup_method(self, method):
-        self.admin_group = frozenset([u'Admin', u'JohnDoe'])
-        self.editor_group = frozenset([u'MainEditor', u'JohnDoe'])
-        self.fruit_group = frozenset([u'Apple', u'Banana'])
-
-        groups = {u'AdminGroup': self.admin_group,
-                  u'EditorGroup': self.editor_group,
-                  u'FruitGroup': self.fruit_group}
-
-        self.group_backend = BackendManager(backend=groups)
-
-    def test_getitem(self):
-        assert self.admin_group == self.group_backend[u'AdminGroup']
-        assert self.fruit_group == self.group_backend[u'FruitGroup']
-
-        raises(KeyError, lambda: self.group_backend[u'not existing group'])
-
-    def test_contains(self):
-        assert u'AdminGroup' in self.group_backend
-        assert u'FruitGroup' in self.group_backend
-
-        assert u'not existing group' not in self.group_backend
-
-    def  test_membergroups(self):
-        apple_groups = self.group_backend.membergroups(u'Apple')
-        assert 1 == len(apple_groups)
-        assert u'FruitGroup' in apple_groups
-        assert u'AdminGroup' not in apple_groups
-
-        john_doe_groups = self.group_backend.membergroups(u'JohnDoe')
-        assert 2 == len(john_doe_groups)
-        assert u'EditorGroup' in john_doe_groups
-        assert u'AdminGroup' in john_doe_groups
-        assert u'FruitGroup' not in john_doe_groups
-
-
-class TestManagerMapping(object):
-    """
-    Test group name mapping:
-        moin -> backend (e.g. "AdminGroup" -> "Admin")
-        backend -> moin (e.g. "Admin" -> "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 "Admin").
-    """
-
-    def setup_class(self):
-        self.admin_group = frozenset([u'Admin', u'JohnDoe'])
-        self.editor_group = frozenset([u'MainEditor', u'JohnDoe'])
-
-        # These backend group names do not follow moin convention:
-        groups = {u'Admin': self.admin_group,
-                  u'Editor': self.editor_group}
-
-        # Simply drop the "Group" postfix for group names given to a backend.
-        # Note: in the real world, this would not work good enough:
-        mapper_to_backend = lambda 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:
-        mapper_from_backend = lambda group_name: "%sGroup" % group_name
-
-        self.group_backend = BackendManager(backend=groups,
-                                            mapper_to_backend=mapper_to_backend,
-                                            mapper_from_backend=mapper_from_backend)
-
-    def test_getitem(self):
-        admin_group = self.group_backend[u'AdminGroup']
-        assert self.admin_group == admin_group
-
-    def test_contains(self):
-        assert u'AdminGroup' in self.group_backend
-
-    def test_membersgroups(self):
-        assert u'AdminGroup' in self.group_backend.membergroups(u'JohnDoe')
-
-coverage_modules = ['MoinMoin.groups']
--- a/MoinMoin/groups/_tests/test_group_manager.py	Wed Jun 10 20:32:42 2009 +0200
+++ b/MoinMoin/groups/_tests/test_group_manager.py	Wed Jun 10 20:32:42 2009 +0200
@@ -10,7 +10,8 @@
 
 from py.test import raises
 
-from MoinMoin.groups import BackendManager, GroupManager
+from MoinMoin.groups import GroupManager
+from MoinMoin.groups.backends import config_group
 
 
 class TestGroupManager(object):
@@ -38,14 +39,13 @@
                                  # first_backend and second_backend.
                                  u'AdminGroup': second_admin_group}
         def group_manager_init(self, request):
-            return GroupManager(backends=[BackendManager(backend=self.first_backend_groups),
-                                          BackendManager(backend=self.second_backend_groups)])
+            return GroupManager(backends=[config_group.Backend(request, self.first_backend_groups),
+                                          config_group.Backend(request, self.second_backend_groups)])
 
     def setup_method(self, method):
         self.groups = self.request.groups
 
     def test_getitem(self):
-        assert self.request.cfg.fruit_group == self.groups[u'FruitGroup']
         raises(KeyError, lambda: self.groups[u'not existing group'])
 
     def test_clashed_getitem(self):
@@ -56,8 +56,6 @@
         """
         admin_group = self.groups[u'AdminGroup']
 
-        assert self.request.cfg.admin_group == admin_group
-
         # TheHacker added himself to the second backend, but that must not be
         # taken into consideration, because AdminGroup is defined in first
         # backend and we only use the first match.
--- 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	Wed Jun 10 20:32:42 2009 +0200
@@ -8,7 +8,8 @@
 """
 
 from MoinMoin import security
-from MoinMoin.groups import BackendManager, GroupManager
+from MoinMoin.groups import GroupManager
+from MoinMoin.groups.backends import config_group
 
 
 class TestGroupManagerACL:
@@ -22,7 +23,7 @@
             groups = {u'FirstGroup': frozenset([u"ExampleUser", u"SecondUser", u"JoeDoe"]),
                       u'SecondGroup': frozenset([u"ExampleUser", u"ThirdUser"])}
 
-            return GroupManager(backends=[BackendManager(backend=groups)])
+            return GroupManager(backends=[config_group.Backend(request, groups)])
 
     def testConfigBackendAcl(self):
         """