annotate MoinMoin/groups/_tests/test_backend_manager.py @ 4775:0a0387a9eb1e

Groups2009: BackendManager does not require request object in __init__
author Dmitrijs Milajevs <dimazest@gmail.com>
date Sun, 31 May 2009 21:17:49 +0200
parents c3e904a9c00b
children 1b84b35fbe91
rev   line source
4763
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
2
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
3 """
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
4 MoinMoin.groups.BackendManager test
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
5
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
6 @copyright: 2009 MoinMoin:DmitrijsMilajevs
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
7 @license: GPL, see COPYING for details
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
8 """
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
9
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
10 from py.test import raises
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
11
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
12 from MoinMoin.groups import BackendManager
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
13
4767
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
14
4766
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
15 class TestBackendManagerAPI(object):
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
16 """
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
17 This tastcase test Backend manager API
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
18 """
4767
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
19
4763
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
20 def setup_method(self, method):
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
21 self.admin_group = frozenset([u'Admin', u'JohnDoe'])
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
22 self.editor_group = frozenset([u'MainEditor', u'JohnDoe'])
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
23 self.fruit_group = frozenset([u'Apple', u'Banana'])
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
24
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
25 groups = {u'AdminGroup': self.admin_group,
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
26 u'EditorGroup': self.editor_group,
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
27 u'FruitGroup': self.fruit_group}
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
28
4775
0a0387a9eb1e Groups2009: BackendManager does not require request object in __init__
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4773
diff changeset
29 self.group_backend = BackendManager(backend=groups)
4763
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
30
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
31 def test_getitem(self):
4766
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
32 """
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
33 Test of the __getitem__ API method. It should return a group
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
34 object by the group name.
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
35 """
4763
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
36 assert self.admin_group == self.group_backend[u'AdminGroup']
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
37 assert self.fruit_group == self.group_backend[u'FruitGroup']
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
38
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
39 raises(KeyError, lambda: self.group_backend[u'not existing group'])
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
40
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
41 def test_contains(self):
4766
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
42 """
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
43 Test of the __contains__ API method. It checks if a group is
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
44 avaliable via this backend. Check is done by group's name.
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
45 """
4763
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
46 assert u'AdminGroup' in self.group_backend
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
47 assert u'FruitGroup' in self.group_backend
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
48
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
49 assert u'not existing group' not in self.group_backend
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
50
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
51 def test_membergroups(self):
4766
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
52 """
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
53 Test of membergroups API method. It lists all groups where
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
54 member is a member of. It should return a list of group names.
c198eff7b345 Groups 2009: Docstrings for the groups module tests, typos for tests
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4764
diff changeset
55 """
4763
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
56 apple_groups = self.group_backend.membergroups(u'Apple')
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
57 assert 1 == len(apple_groups)
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
58 assert u'FruitGroup' in apple_groups
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
59 assert u'AdminGroup' not in apple_groups
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
60
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
61 john_doe_groups = self.group_backend.membergroups(u'JohnDoe')
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
62 assert 2 == len(john_doe_groups)
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
63 assert u'EditorGroup' in john_doe_groups
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
64 assert u'AdminGroup' in john_doe_groups
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
65 assert u'FruitGroup' not in john_doe_groups
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
66
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
67
4767
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
68 class TestManagerMapping(object):
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
69 """
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
70 This class tests mapping of the group names from a backend to the
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
71 moin and from the moin to a backend.
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
72
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
73 Here the simplest situation is considered. Moin expect groups to
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
74 be named as *Group, but backend stores group names without this prefix.
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
75
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
76 When group names are passed or retrieved from the backend they
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
77 should be mapped.
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
78 """
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
79
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
80 def setup_class(self):
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
81 self.admin_group = frozenset([u'Admin', u'JohnDoe'])
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
82 self.editor_group = frozenset([u'MainEditor', u'JohnDoe'])
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
83
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
84 # Group names here do not follow moin convention: they do not
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
85 # have group prefix.
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
86 groups = {u'Admin': self.admin_group,
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
87 u'Editor': self.editor_group}
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
88
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
89 # Simply drop last five letters, what is length of word "Group"
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
90 mapper_to_backend = lambda group_name: group_name[:-5]
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
91 # Add "Group" postfix for every group name received from a backend
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
92 mapper_from_backend = lambda group_name: "%sGroup" % group_name
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
93
4775
0a0387a9eb1e Groups2009: BackendManager does not require request object in __init__
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4773
diff changeset
94 self.group_backend = BackendManager(backend=groups,
4767
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
95 mapper_to_backend=mapper_to_backend,
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
96 mapper_from_backend=mapper_from_backend)
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
97
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
98 def test_getitem(self):
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
99 admin_group = self.group_backend[u'AdminGroup']
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
100 assert self.admin_group == admin_group
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
101
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
102 def test_contains(self):
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
103 assert u'AdminGroup' in self.group_backend
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
104
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
105 def test_membersgroups(self):
3b34bbd60dca Groups2009: Group name mapping from moin to backend and vice versa
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4766
diff changeset
106 assert u'AdminGroup' in self.group_backend.membergroups(u'JohnDoe')
4769
55c40ed9dac1 Groups 2009: pep8 fix
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4767
diff changeset
107
4763
13a75c5f65c7 Groups2009: MoinMoin.groups module initial layout and tests. BackendManager and GroupManager classes were introduced.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
108 coverage_modules = ['MoinMoin.groups']