view MoinMoin/groups/_tests/ @ 4773:c3e904a9c00b

Groups 2009: BackendManager gets request object in __init__
author Dmitrijs Milajevs <>
date Sat, 30 May 2009 08:22:09 +0200
parents 8dcf18d0ae41
children fb0cce9e8621
line wrap: on
line source
# -*- 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):

    def setup_class(self):
        groups = {u'FirstGroup': frozenset([u"ExampleUser", u"SecondUser", u"JoeDoe"]),
                  u'SecondGroup': frozenset([u"ExampleUser", u"ThirdUser"])}

        self.Config.group_manager = lambda self, request: GroupManager(backends=[BackendManager(request=request, backend=groups)])

    def setup_method(self, method):
        self.group_manager = self.request.cfg.group_manager(self.request)

    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(request=self.request,

        # 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']