view MoinMoin/groups/_tests/test_group_manager_acl.py @ 4774:fb0cce9e8621

Groups 2009: Moin.groups.GroupManager is initialized with a request initialization.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Sun, 31 May 2009 21:17:34 +0200
parents c3e904a9c00b
children 0a0387a9eb1e
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 group_manager_init(self, request):
            groups = {u'FirstGroup': frozenset([u"ExampleUser", u"SecondUser", u"JoeDoe"]),
                      u'SecondGroup': frozenset([u"ExampleUser", u"ThirdUser"])}

            return GroupManager(backends=[BackendManager(request=request, backend=groups)])

    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


coverage_modules = ['MoinMoin.groups']