changeset 4772:8dcf18d0ae41

Groups 2009: pep8. MoinMoin.groups _test renamed to _tests
author Dmitrijs Milajevs <dimazest@gmail.com>
date Sat, 30 May 2009 08:06:59 +0200
parents d85a2b2f120b
children c3e904a9c00b
files MoinMoin/groups/_test/test_backend_manager.py MoinMoin/groups/_test/test_group_manager.py MoinMoin/groups/_test/test_group_manager_acl.py MoinMoin/groups/_tests/test_backend_manager.py MoinMoin/groups/_tests/test_group_manager.py MoinMoin/groups/_tests/test_group_manager_acl.py
diffstat 6 files changed, 288 insertions(+), 288 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/groups/_test/test_backend_manager.py	Wed May 27 21:07:59 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +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 TestBackendManagerAPI(object):
-    """
-    This tastcase test Backend manager API
-    """
-
-    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):
-        """
-        Test of the __getitem__ API method. It should return a group
-        object by the group name.
-        """
-        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):
-        """
-        Test of the __contains__ API method. It checks if a group is
-        avaliable via this backend. Check is done by group's name.
-        """
-        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):
-        """
-        Test of membergroups API method. It lists all groups where
-        member is a member of. It should  return a list of group names.
-        """
-        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):
-    """
-    This class tests mapping of the group names from a backend to the
-    moin and from the moin to a backend.
-
-    Here the simplest situation is considered. Moin expect groups to
-    be named as *Group, but backend stores group names without this prefix.
-
-    When group names are passed or retrieved from the backend they
-    should be mapped.
-    """
-
-    def setup_class(self):
-        self.admin_group = frozenset([u'Admin', u'JohnDoe'])
-        self.editor_group = frozenset([u'MainEditor', u'JohnDoe'])
-
-        # Group names here do not follow moin convention: they do not
-        # have group prefix.
-        groups = {u'Admin': self.admin_group,
-                  u'Editor': self.editor_group}
-
-        # Simply drop last five letters, what is length of word "Group"
-        mapper_to_backend = lambda group_name: group_name[:-5]
-        # Add "Group" postfix for every group name received from a backend
-        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/_test/test_group_manager.py	Wed May 27 21:07:59 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-
-"""
-MoinMoin.groups.GroupManager test
-
-@copyright: 2009 MoinMoin:DmitrijsMilajevs
-@license: GPL, see COPYING for details
-"""
-
-from py.test import raises
-
-from MoinMoin.groups import BackendManager, GroupManager
-
-
-class TestGroupManagerAPI(object):
-    """
-    Performs test of the API of GroupManager.
-    """
-
-    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', u'Cherry'])
-
-        first_backend = BackendManager({u'AdminGroup': self.admin_group,
-                                        u'EditorGroup': self.editor_group,
-                                        u'FruitGroup': self.fruit_group})
-
-        self.user_group = frozenset([u'JohnDoe', u'Bob', u'Joe'])
-        self.city_group = frozenset([u'Bolzano', u'Riga', u'London'])
-        # Suppose, someone hacked second backend
-        # and added himself to AdminGroup
-        self.second_admin_group = frozenset([u'TheHacker'])
-
-        second_backend = BackendManager({u'UserGroup': self.user_group,
-                                         u'CityGroup': self.city_group,
-                                         # Here group name clash occurs.
-                                         # AdminGroup is defined in both
-                                         # first_backend and second_backend.
-                                         u'AdminGroup': self.second_admin_group})
-
-        self.group_manager = GroupManager(backends = [first_backend,
-                                                      second_backend])
-
-    def test_getitem(self):
-        """
-        Tests __getitem__ API method. It should return a group by its name.
-        """
-        assert self.fruit_group == self.group_manager[u'FruitGroup']
-        raises(KeyError, lambda: self.group_manager[u'not existing group'])
-
-    def test_clashed_getitem(self):
-        """
-        This test check situation when groups with a same name are
-        defined in several backends. In this case, the only one
-        backend must be taken in consideration, that backend which is
-        defined first in the backends list.
-        """
-        admin_group = self.group_manager[u'AdminGroup']
-
-        assert self.admin_group == admin_group
-
-        # Nevertheless, TheHacker added himself to the second backend,
-        # it must not be taken into consideration, because AdminGroup is defined
-        # in first backend
-        assert u'TheHacker' not in admin_group
-
-    def test_iter(self):
-        """
-        Tests __iter__ API method. It should iterate over all groups
-        available via backends. It should avoid group name clashes.
-        """
-        all_group_names = [group_name for group_name in self.group_manager]
-
-        assert 5 == len(all_group_names)
-        # There are no duplicates
-        assert len(set(all_group_names)) == len(all_group_names)
-
-    def test_contains(self):
-        """
-        Tests __contains__ API method. It should check if a group
-        called group_name is available via some backend.
-        """
-        assert u'UserGroup' in self.group_manager
-        assert u'not existing group' not in self.group_manager
-
-    def test_membergroups(self):
-        """
-        Tests membergroups API method. It should lists all groups
-        where member is a member of. It should return a list of group
-        names.
-        """
-        apple_groups = self.group_manager.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_manager.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/_test/test_group_manager_acl.py	Wed May 27 21:07:59 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-MoinMoin.groups.GroupManager ACL Tests
-
-@copyright: 2009 MoinMoin:DmitrijsMilajevs
-            2008 MoinMoin:MelitaMihaljevic
-@license: GPL, see COPYING for details
-"""
-
-from MoinMoin import security
-from MoinMoin.groups import BackendManager, GroupManager
-
-
-class TestGroupManagerACL:
-    """
-    Test how GroupManager works with acl code.
-    """
-
-    from MoinMoin._tests import wikiconfig
-    class Config(wikiconfig.Config):
-        pass
-
-    def setup_class(self):
-        groups = {u'FirstGroup': frozenset([u"ExampleUser", u"SecondUser", u"JoeDoe"]),
-                  u'SecondGroup': frozenset([u"ExampleUser", u"ThirdUser"])}
-        group_manager = GroupManager([BackendManager(groups)])
-
-        self.Config.group_manager = group_manager
-
-    def testConfigBackendAcl(self):
-        """
-        test if the group config backend works with acl code
-        """
-        # define acl rights for FirstGroup, members of group can read and write
-        acl_rights = ["FirstGroup:admin,read,write"]
-        acl = security.AccessControlList(self.request.cfg, acl_rights)
-
-        allow = acl.may(self.request, u"JoeDoe", "admin")
-        # JoeDoe has admin rights because he is a member of group FirstGroup     
-        assert allow
-
-        allow = acl.may(self.request, u"AnotherUser", "admin")
-        # AnotherUser has no read rights because he is not a member of group FirstGroup
-        assert not allow
-
-    def testConfigBackend(self):
-        """
-        tests getting a group from the group manager, does group
-        membership tests.
-        """
-        # define config groups
-        groups = {'A': set(['a1', 'a2']),
-                  'B': set(['b1', 'b2']),
-                 }
-
-        # create config group manager backend object
-        group_manager_backend = GroupManager(BackendManager([groups]))
-
-        # check that a group named 'A' is available via the config backend
-        assert 'A' in group_manager_backend
-
-        # check that a group named 'C' is not available via the config backend
-        assert 'C' not in group_manager_backend
-
-        # get group object for a group named 'A'
-        group_A = group_manager_backend['A']
-
-        # check that a1 is a member of group A
-        assert 'a1' in group_A
-
-        # check that b1 is not a member of group A
-        assert 'b1' not in group_A
-
-coverage_modules = ['MoinMoin.groups']
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/groups/_tests/test_backend_manager.py	Sat May 30 08:06:59 2009 +0200
@@ -0,0 +1,109 @@
+# -*- 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 TestBackendManagerAPI(object):
+    """
+    This tastcase test Backend manager API
+    """
+
+    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):
+        """
+        Test of the __getitem__ API method. It should return a group
+        object by the group name.
+        """
+        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):
+        """
+        Test of the __contains__ API method. It checks if a group is
+        avaliable via this backend. Check is done by group's name.
+        """
+        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):
+        """
+        Test of membergroups API method. It lists all groups where
+        member is a member of. It should  return a list of group names.
+        """
+        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):
+    """
+    This class tests mapping of the group names from a backend to the
+    moin and from the moin to a backend.
+
+    Here the simplest situation is considered. Moin expect groups to
+    be named as *Group, but backend stores group names without this prefix.
+
+    When group names are passed or retrieved from the backend they
+    should be mapped.
+    """
+
+    def setup_class(self):
+        self.admin_group = frozenset([u'Admin', u'JohnDoe'])
+        self.editor_group = frozenset([u'MainEditor', u'JohnDoe'])
+
+        # Group names here do not follow moin convention: they do not
+        # have group prefix.
+        groups = {u'Admin': self.admin_group,
+                  u'Editor': self.editor_group}
+
+        # Simply drop last five letters, what is length of word "Group"
+        mapper_to_backend = lambda group_name: group_name[:-5]
+        # Add "Group" postfix for every group name received from a backend
+        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']
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/groups/_tests/test_group_manager.py	Sat May 30 08:06:59 2009 +0200
@@ -0,0 +1,105 @@
+# -*- coding: iso-8859-1 -*-
+
+"""
+MoinMoin.groups.GroupManager test
+
+@copyright: 2009 MoinMoin:DmitrijsMilajevs
+@license: GPL, see COPYING for details
+"""
+
+from py.test import raises
+
+from MoinMoin.groups import BackendManager, GroupManager
+
+
+class TestGroupManagerAPI(object):
+    """
+    Performs test of the API of GroupManager.
+    """
+
+    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', u'Cherry'])
+
+        first_backend = BackendManager({u'AdminGroup': self.admin_group,
+                                        u'EditorGroup': self.editor_group,
+                                        u'FruitGroup': self.fruit_group})
+
+        self.user_group = frozenset([u'JohnDoe', u'Bob', u'Joe'])
+        self.city_group = frozenset([u'Bolzano', u'Riga', u'London'])
+        # Suppose, someone hacked second backend
+        # and added himself to AdminGroup
+        self.second_admin_group = frozenset([u'TheHacker'])
+
+        second_backend = BackendManager({u'UserGroup': self.user_group,
+                                         u'CityGroup': self.city_group,
+                                         # Here group name clash occurs.
+                                         # AdminGroup is defined in both
+                                         # first_backend and second_backend.
+                                         u'AdminGroup': self.second_admin_group})
+
+        self.group_manager = GroupManager(backends = [first_backend,
+                                                      second_backend])
+
+    def test_getitem(self):
+        """
+        Tests __getitem__ API method. It should return a group by its name.
+        """
+        assert self.fruit_group == self.group_manager[u'FruitGroup']
+        raises(KeyError, lambda: self.group_manager[u'not existing group'])
+
+    def test_clashed_getitem(self):
+        """
+        This test check situation when groups with a same name are
+        defined in several backends. In this case, the only one
+        backend must be taken in consideration, that backend which is
+        defined first in the backends list.
+        """
+        admin_group = self.group_manager[u'AdminGroup']
+
+        assert self.admin_group == admin_group
+
+        # Nevertheless, TheHacker added himself to the second backend,
+        # it must not be taken into consideration, because AdminGroup is defined
+        # in first backend
+        assert u'TheHacker' not in admin_group
+
+    def test_iter(self):
+        """
+        Tests __iter__ API method. It should iterate over all groups
+        available via backends. It should avoid group name clashes.
+        """
+        all_group_names = [group_name for group_name in self.group_manager]
+
+        assert 5 == len(all_group_names)
+        # There are no duplicates
+        assert len(set(all_group_names)) == len(all_group_names)
+
+    def test_contains(self):
+        """
+        Tests __contains__ API method. It should check if a group
+        called group_name is available via some backend.
+        """
+        assert u'UserGroup' in self.group_manager
+        assert u'not existing group' not in self.group_manager
+
+    def test_membergroups(self):
+        """
+        Tests membergroups API method. It should lists all groups
+        where member is a member of. It should return a list of group
+        names.
+        """
+        apple_groups = self.group_manager.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_manager.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']
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/groups/_tests/test_group_manager_acl.py	Sat May 30 08:06:59 2009 +0200
@@ -0,0 +1,74 @@
+# -*- coding: iso-8859-1 -*-
+"""
+MoinMoin.groups.GroupManager ACL Tests
+
+@copyright: 2009 MoinMoin:DmitrijsMilajevs
+            2008 MoinMoin:MelitaMihaljevic
+@license: GPL, see COPYING for details
+"""
+
+from MoinMoin import security
+from MoinMoin.groups import BackendManager, GroupManager
+
+
+class TestGroupManagerACL:
+    """
+    Test how GroupManager works with acl code.
+    """
+
+    from MoinMoin._tests import wikiconfig
+    class Config(wikiconfig.Config):
+        pass
+
+    def setup_class(self):
+        groups = {u'FirstGroup': frozenset([u"ExampleUser", u"SecondUser", u"JoeDoe"]),
+                  u'SecondGroup': frozenset([u"ExampleUser", u"ThirdUser"])}
+        group_manager = GroupManager([BackendManager(groups)])
+
+        self.Config.group_manager = group_manager
+
+    def testConfigBackendAcl(self):
+        """
+        test if the group config backend works with acl code
+        """
+        # define acl rights for FirstGroup, members of group can read and write
+        acl_rights = ["FirstGroup:admin,read,write"]
+        acl = security.AccessControlList(self.request.cfg, acl_rights)
+
+        allow = acl.may(self.request, u"JoeDoe", "admin")
+        # JoeDoe has admin rights because he is a member of group FirstGroup
+        assert allow
+
+        allow = acl.may(self.request, u"AnotherUser", "admin")
+        # AnotherUser has no read rights because he is not a member of group FirstGroup
+        assert not allow
+
+    def testConfigBackend(self):
+        """
+        tests getting a group from the group manager, does group
+        membership tests.
+        """
+        # define config groups
+        groups = {'A': set(['a1', 'a2']),
+                  'B': set(['b1', 'b2']),
+                 }
+
+        # create config group manager backend object
+        group_manager_backend = GroupManager(BackendManager([groups]))
+
+        # check that a group named 'A' is available via the config backend
+        assert 'A' in group_manager_backend
+
+        # check that a group named 'C' is not available via the config backend
+        assert 'C' not in group_manager_backend
+
+        # get group object for a group named 'A'
+        group_A = group_manager_backend['A']
+
+        # check that a1 is a member of group A
+        assert 'a1' in group_A
+
+        # check that b1 is not a member of group A
+        assert 'b1' not in group_A
+
+coverage_modules = ['MoinMoin.groups']