1
# -*- coding: iso-8859-1 -*-
4
MoinMoin.datastruct.backends.composite_groups test
6
@copyright: 2009 MoinMoin:DmitrijsMilajevs
7
@license: GPL, see COPYING for details
10
from py.test import raises
12
from MoinMoin.datastruct.backends._tests import GroupsBackendTest
13
from MoinMoin.datastruct import ConfigGroups, CompositeGroups, GroupDoesNotExistError
14
from MoinMoin._tests import wikiconfig
15
from MoinMoin import security
18
class TestCompositeGroupsBackend(GroupsBackendTest):
20
class Config(wikiconfig.Config):
22
def groups(self, request):
23
groups = GroupsBackendTest.test_groups
24
return CompositeGroups(request, ConfigGroups(request, groups))
27
class TestCompositeGroup(object):
29
class Config(wikiconfig.Config):
31
admin_group = frozenset([u'Admin', u'JohnDoe'])
32
editor_group = frozenset([u'MainEditor', u'JohnDoe'])
33
fruit_group = frozenset([u'Apple', u'Banana', u'Cherry'])
35
first_backend_groups = {u'AdminGroup': admin_group,
36
u'EditorGroup': editor_group,
37
u'FruitGroup': fruit_group}
39
user_group = frozenset([u'JohnDoe', u'Bob', u'Joe'])
40
city_group = frozenset([u'Bolzano', u'Riga', u'London'])
42
# Suppose, someone hacked second backend and added himself to AdminGroup
43
second_admin_group = frozenset([u'TheHacker'])
45
second_backend_groups = {u'UserGroup': user_group,
46
u'CityGroup': city_group,
47
# Here group name clash occurs.
48
# AdminGroup is defined in both
49
# first_backend and second_backend.
50
u'AdminGroup': second_admin_group}
52
def groups(self, request):
53
return CompositeGroups(request,
54
ConfigGroups(request, self.first_backend_groups),
55
ConfigGroups(request, self.second_backend_groups))
57
def setup_method(self, method):
58
self.groups = self.request.groups
60
def test_getitem(self):
61
raises(GroupDoesNotExistError, lambda: self.groups[u'NotExistingGroup'])
63
def test_clashed_getitem(self):
65
Check the case when groups of the same name are defined in multiple
66
backends. __getitem__ should return the first match (backends are
67
considered in the order they are given in the backends list).
69
admin_group = self.groups[u'AdminGroup']
71
# TheHacker added himself to the second backend, but that must not be
72
# taken into consideration, because AdminGroup is defined in first
73
# backend and we only use the first match.
74
assert u'TheHacker' not in admin_group
77
all_group_names = list(self.groups)
79
assert 5 == len(all_group_names)
80
# There are no duplicates
81
assert len(set(all_group_names)) == len(all_group_names)
83
def test_contains(self):
84
assert u'UserGroup' in self.groups
85
assert u'not existing group' not in self.groups
88
coverage_modules = ['MoinMoin.datastruct.backends.composite_groups']