changeset 4810:3c0ce322472a

Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Sun, 14 Jun 2009 17:07:02 +0200
parents 415338464695
children 89497de6165d
files MoinMoin/groups/__init__.py MoinMoin/groups/_tests/test_group_manager.py MoinMoin/groups/backends/__init__.py MoinMoin/groups/backends/_tests/__init__.py
diffstat 4 files changed, 18 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/groups/__init__.py	Sun Jun 14 17:01:09 2009 +0200
+++ b/MoinMoin/groups/__init__.py	Sun Jun 14 17:07:02 2009 +0200
@@ -56,14 +56,9 @@
         return False
 
     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]]
+        # Dirty hack just to make code works, after GroupManager
+        # becomes a backend itself, no need in this.
+        return self._backends[0].groups_with_member(member)
 
     def __repr__(self):
         return "<%s backends=%s>" % (self.__class__, self._backends)
--- a/MoinMoin/groups/_tests/test_group_manager.py	Sun Jun 14 17:01:09 2009 +0200
+++ b/MoinMoin/groups/_tests/test_group_manager.py	Sun Jun 14 17:07:02 2009 +0200
@@ -74,17 +74,5 @@
         assert u'UserGroup' in self.groups
         assert u'not existing group' not in self.groups
 
-    def test_membergroups(self):
-        apple_groups = self.groups.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.groups.membergroups(u'JohnDoe')
-        assert 3 == len(john_doe_groups)
-        assert u'EditorGroup' in john_doe_groups
-        assert u'AdminGroup' in john_doe_groups
-        assert u'UserGroup' in john_doe_groups
-        assert u'FruitGroup' not in john_doe_groups
 
 coverage_modules = ['MoinMoin.groups']
--- a/MoinMoin/groups/backends/__init__.py	Sun Jun 14 17:01:09 2009 +0200
+++ b/MoinMoin/groups/backends/__init__.py	Sun Jun 14 17:07:02 2009 +0200
@@ -140,3 +140,17 @@
     def _retrieve_members(self, group_name):
         raise NotImplementedError()
 
+    def groups_with_member(self, member):
+        """
+        List all group names of groups containing <member>.
+
+        @param member: member name [unicode]
+        @return: list of group names [unicode]
+        """
+        for group_name in self:
+            try:
+                if member in self[group_name]:
+                    yield group_name
+            except KeyError:
+                pass
+
--- a/MoinMoin/groups/backends/_tests/__init__.py	Sun Jun 14 17:01:09 2009 +0200
+++ b/MoinMoin/groups/backends/_tests/__init__.py	Sun Jun 14 17:07:02 2009 +0200
@@ -61,7 +61,7 @@
     def test_membergroups(self):
         groups = self.request.groups
 
-        john_groups = groups.membergroups(u'John')
+        john_groups = list(groups.membergroups(u'John'))
         assert 2 == len(john_groups)
         assert u'EditorGroup' in john_groups
         assert u'AdminGroup' in john_groups