~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/datastruct/backends/_tests/test_composite_groups.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: iso-8859-1 -*-
2
 
 
3
 
"""
4
 
MoinMoin.datastruct.backends.composite_groups test
5
 
 
6
 
@copyright: 2009 MoinMoin:DmitrijsMilajevs
7
 
@license: GPL, see COPYING for details
8
 
"""
9
 
 
10
 
from py.test import raises
11
 
 
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
16
 
 
17
 
 
18
 
class TestCompositeGroupsBackend(GroupsBackendTest):
19
 
 
20
 
    class Config(wikiconfig.Config):
21
 
 
22
 
        def groups(self, request):
23
 
            groups = GroupsBackendTest.test_groups
24
 
            return CompositeGroups(request, ConfigGroups(request, groups))
25
 
 
26
 
 
27
 
class TestCompositeGroup(object):
28
 
 
29
 
    class Config(wikiconfig.Config):
30
 
 
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'])
34
 
 
35
 
        first_backend_groups = {u'AdminGroup': admin_group,
36
 
                                u'EditorGroup': editor_group,
37
 
                                u'FruitGroup': fruit_group}
38
 
 
39
 
        user_group = frozenset([u'JohnDoe', u'Bob', u'Joe'])
40
 
        city_group = frozenset([u'Bolzano', u'Riga', u'London'])
41
 
 
42
 
        # Suppose, someone hacked second backend and added himself to AdminGroup
43
 
        second_admin_group = frozenset([u'TheHacker'])
44
 
 
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}
51
 
 
52
 
        def groups(self, request):
53
 
            return CompositeGroups(request,
54
 
                                   ConfigGroups(request, self.first_backend_groups),
55
 
                                   ConfigGroups(request, self.second_backend_groups))
56
 
 
57
 
    def setup_method(self, method):
58
 
        self.groups = self.request.groups
59
 
 
60
 
    def test_getitem(self):
61
 
        raises(GroupDoesNotExistError, lambda: self.groups[u'NotExistingGroup'])
62
 
 
63
 
    def test_clashed_getitem(self):
64
 
        """
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).
68
 
        """
69
 
        admin_group = self.groups[u'AdminGroup']
70
 
 
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
75
 
 
76
 
    def test_iter(self):
77
 
        all_group_names = list(self.groups)
78
 
 
79
 
        assert 5 == len(all_group_names)
80
 
        # There are no duplicates
81
 
        assert len(set(all_group_names)) == len(all_group_names)
82
 
 
83
 
    def test_contains(self):
84
 
        assert u'UserGroup' in self.groups
85
 
        assert u'not existing group' not in self.groups
86
 
 
87
 
 
88
 
coverage_modules = ['MoinMoin.datastruct.backends.composite_groups']