view MoinMoin/groups/_tests/ @ 4803:167db6117bb4

Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
author Dmitrijs Milajevs <>
date Thu, 11 Jun 2009 13:48:54 +0200
parents 878b5a87ba3b
children 3cea38408fe6
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 GroupManager
from MoinMoin.groups.backends import config_group
from MoinMoin._tests import wikiconfig

class TestGroupManagerACL:
    Test how GroupManager works with the acl code.

    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=[config_group.Backend(request, 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']