comparison MoinMoin/groups/backends/_tests/__init__.py @ 4803:167db6117bb4

Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Thu, 11 Jun 2009 13:48:54 +0200
parents 3b05bf18c0d1
children ca8fcf330aa8
comparison
equal deleted inserted replaced
4802:878b5a87ba3b 4803:167db6117bb4
11 """ 11 """
12 12
13 from py.test import raises 13 from py.test import raises
14 14
15 from MoinMoin import security 15 from MoinMoin import security
16 from MoinMoin._tests import wikiconfig
17 16
18 class Config(wikiconfig.Config):
19 # Simply drop the "Group" postfix for group names given to a backend.
20 # Note: in the real world, this would not work good enough:
21 to_backend_name = lambda self, group_name: group_name[:-5]
22 # Add "Group" postfix for group names received from a backend.
23 # Note: in the real world, this would not work good enough:
24 to_group_name = lambda self, backend_name:'%sGroup' % backend_name
25 17
26 class BackendTest(object): 18 class BackendTest(object):
27 19
28 test_groups = {u'EditorGroup': [u'AdminGroup', u'John', u'JoeDoe', u'Editor1'], 20 test_groups = {u'EditorGroup': [u'AdminGroup', u'John', u'JoeDoe', u'Editor1', u'John'],
29 u'AdminGroup': [u'Admin1', u'Admin2', u'John'], 21 u'AdminGroup': [u'Admin1', u'Admin2', u'John'],
30 u'OtherGroup': [u'SomethingOther'], 22 u'OtherGroup': [u'SomethingOther'],
31 u'RecursiveGroup': [u'Something', u'OtherRecursiveGroup'], 23 u'RecursiveGroup': [u'Something', u'OtherRecursiveGroup'],
32 u'OtherRecursiveGroup': [u'RecursiveGroup', u'Anything'], 24 u'OtherRecursiveGroup': [u'RecursiveGroup', u'Anything'],
33 u'ThirdRecursiveGroup': [u'ThirdRecursiveGroup', u'Banana']} 25 u'ThirdRecursiveGroup': [u'ThirdRecursiveGroup', u'Banana']}
38 u'OtherGroup': [u'SomethingOther'], 30 u'OtherGroup': [u'SomethingOther'],
39 u'RecursiveGroup': [u'Anything', u'Something'], 31 u'RecursiveGroup': [u'Anything', u'Something'],
40 u'OtherRecursiveGroup': [u'Anything', u'Something'], 32 u'OtherRecursiveGroup': [u'Anything', u'Something'],
41 u'ThirdRecursiveGroup': [u'Banana']} 33 u'ThirdRecursiveGroup': [u'Banana']}
42 34
43 # These backend group names do not follow moin convention:
44 mapped_groups = {u'Editor': [u'Admin', u'John', u'JoeDoe', u'Editor1'],
45 u'Admin': [u'Admin1', u'Admin2', u'John'],
46 u'Other': [u'SomethingOther'],
47 u'Recursive': [u'Something', u'OtherRecursive'],
48 u'OtherRecursive': [u'Recursive', u'Anything'],
49 u'ThirdRecursive': [u'ThirdRecursive', u'Banana']}
50
51 def test_contains(self): 35 def test_contains(self):
52 """ 36 """
53 Test group_wiki Backend and Group containment methods. 37 Test group_wiki Backend and Group containment methods.
54 """ 38 """
55 groups = self.request.groups 39 groups = self.request.groups
56 40
57 for (group, members) in self.expanded_groups.iteritems(): 41 for group, members in self.expanded_groups.iteritems():
58 print group 42 print group
59 assert group in groups 43 assert group in groups
60 for member in members: 44 for member in members:
61 assert member in groups[group] 45 assert member in groups[group]
62 46
63 raises(KeyError, lambda: groups[u'NotExistingGroup']) 47 raises(KeyError, lambda: groups[u'NotExistingGroup'])
64 48
65 def test_iter(self): 49 def test_iter(self):
66 groups = self.request.groups 50 groups = self.request.groups
67 51
68 for (group, members) in self.expanded_groups.iteritems(): 52 for group, members in self.expanded_groups.iteritems():
69 returned_members = [x for x in groups[group]] 53 returned_members = [x for x in groups[group]]
70 assert len(returned_members) == len(members) 54 assert len(returned_members) == len(members)
71 for member in members: 55 for member in members:
72 assert member in returned_members 56 assert member in returned_members
73 57
126 assert acl.may(request, u"Someone", "read") 110 assert acl.may(request, u"Someone", "read")
127 assert not acl.may(request, u"Someone", "write") 111 assert not acl.may(request, u"Someone", "write")
128 assert not acl.may(request, u"Someone", "delete") 112 assert not acl.may(request, u"Someone", "delete")
129 assert not acl.may(request, u"Someone", "admin") 113 assert not acl.may(request, u"Someone", "admin")
130 114
131 class BackendTestMapping(BackendTest):
132 """
133 Test group name mapping:
134 moin -> backend (e.g. "AdminGroup" -> "ImportantAdminGroup")
135 backend -> moin (e.g. "ImportantAdminGroup" -> "AdminGroup")
136
137 Moin expects group names to match the page_group_regex (e.g. "AdminGroup"),
138 but a backend might want to use different group names (e.g. just "ImportantAdminGroup").
139 """
140 test_groups = {u'ImportantEditorGroup': [u'ImportantAdminGroup', u'John',
141 u'JoeDoe', u'Editor'],
142 u'ImportantAdminGroup': [u'Admin', u'Admin2', u'John'],
143 u'ImportantOtherGroup': [u'SomethingOther'],
144 u'ImportantRecursiveGroup': [u'Something', u'ImportantOtherRecursiveGroup'],
145 u'ImportantOtherRecursiveGroup': [u'ImportantRecursiveGroup', u'Anything'],
146 u'ImportantThirdRecursiveGroup': [u'ImportantThirdRecursiveGroup', u'Banana']}
147
148 115
149 coverage_modules = ['MoinMoin.groups.backends.config_group'] 116 coverage_modules = ['MoinMoin.groups.backends.config_group']
150 117