Back to index

moin  1.9.0~rc2
test_wiki_groups.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003 MoinMoin - MoinMoin.backends.wiki_group tests
00004 
00005 @copyright: 2003-2004 by Juergen Hermann <jh@web.de>,
00006             2007 by MoinMoin:ThomasWaldmann
00007             2008 by MoinMoin:MelitaMihaljevic
00008             2009 by MoinMoin:DmitrijsMilajevs
00009 @license: GNU GPL, see COPYING for details.
00010 """
00011 
00012 from py.test import raises
00013 import re, shutil
00014 
00015 from MoinMoin.datastruct.backends._tests import GroupsBackendTest
00016 from MoinMoin.datastruct import WikiGroups
00017 from MoinMoin import Page, security
00018 from MoinMoin.PageEditor import PageEditor
00019 from MoinMoin.user import User
00020 from MoinMoin._tests import append_page, become_trusted, create_page, create_random_string_list, nuke_page, nuke_user, wikiconfig
00021 
00022 
00023 class TestWikiGroupBackend(GroupsBackendTest):
00024 
00025     # Suppose that default configuration for the groups is used which
00026     # is WikiGroups backend.
00027 
00028     def setup_class(self):
00029         become_trusted(self.request)
00030 
00031         for group, members in self.test_groups.iteritems():
00032             page_text = ' * %s' % '\n * '.join(members)
00033             create_page(self.request, group, page_text)
00034 
00035     def teardown_class(self):
00036         become_trusted(self.request)
00037 
00038         for group in self.test_groups:
00039             nuke_page(self.request, group)
00040 
00041     def test_rename_group_page(self):
00042         """
00043         Tests if the groups cache is refreshed after renaming a Group page.
00044         """
00045         request = self.request
00046         become_trusted(request)
00047 
00048         page = create_page(request, u'SomeGroup', u" * ExampleUser")
00049         page.renamePage('AnotherGroup')
00050 
00051         result = u'ExampleUser' in request.groups[u'AnotherGroup']
00052         nuke_page(request, u'AnotherGroup')
00053 
00054         assert result is True
00055 
00056     def test_copy_group_page(self):
00057         """
00058         Tests if the groups cache is refreshed after copying a Group page.
00059         """
00060         request = self.request
00061         become_trusted(request)
00062 
00063         page = create_page(request, u'SomeGroup', u" * ExampleUser")
00064         page.copyPage(u'SomeOtherGroup')
00065 
00066         result = u'ExampleUser' in request.groups[u'SomeOtherGroup']
00067 
00068         nuke_page(request, u'OtherGroup')
00069         nuke_page(request, u'SomeGroup')
00070 
00071         assert result is True
00072 
00073     def test_appending_group_page(self):
00074         """
00075         Test scalability by appending a name to a large list of group members.
00076         """
00077         request = self.request
00078         become_trusted(request)
00079 
00080         # long list of users
00081         page_content = [u" * %s" % member for member in create_random_string_list(length=15, count=1234)]
00082         test_user = create_random_string_list(length=15, count=1)[0]
00083         create_page(request, u'UserGroup', "\n".join(page_content))
00084         append_page(request, u'UserGroup', u' * %s' % test_user)
00085         result = test_user in request.groups['UserGroup']
00086         nuke_page(request, u'UserGroup')
00087 
00088         assert result
00089 
00090     def test_user_addition_to_group_page(self):
00091         """
00092         Test addition of a username to a large list of group members.
00093         """
00094         request = self.request
00095         become_trusted(request)
00096 
00097         # long list of users
00098         page_content = [u" * %s" % member for member in create_random_string_list()]
00099         create_page(request, u'UserGroup', "\n".join(page_content))
00100 
00101         new_user = create_random_string_list(length=15, count=1)[0]
00102         append_page(request, u'UserGroup', u' * %s' % new_user)
00103         user = User(request, name=new_user)
00104         if not user.exists():
00105             User(request, name=new_user, password=new_user).save()
00106 
00107         result = new_user in request.groups[u'UserGroup']
00108         nuke_page(request, u'UserGroup')
00109         nuke_user(request, new_user)
00110 
00111         assert result
00112 
00113     def test_member_removed_from_group_page(self):
00114         """
00115         Tests appending a member to a large list of group members and
00116         recreating the page without the member.
00117         """
00118         request = self.request
00119         become_trusted(request)
00120 
00121         # long list of users
00122         page_content = [u" * %s" % member for member in create_random_string_list()]
00123         page_content = "\n".join(page_content)
00124         create_page(request, u'UserGroup', page_content)
00125 
00126         test_user = create_random_string_list(length=15, count=1)[0]
00127         page = append_page(request, u'UserGroup', u' * %s' % test_user)
00128 
00129         # saves the text without test_user
00130         page.saveText(page_content, 0)
00131         result = test_user in request.groups[u'UserGroup']
00132         nuke_page(request, u'UserGroup')
00133 
00134         assert not result
00135 
00136     def test_group_page_user_addition_trivial_change(self):
00137         """
00138         Test addition of a user to a group page by trivial change.
00139         """
00140         request = self.request
00141         become_trusted(request)
00142 
00143         test_user = create_random_string_list(length=15, count=1)[0]
00144         member = u" * %s\n" % test_user
00145         page = create_page(request, u'UserGroup', member)
00146 
00147         # next member saved  as trivial change
00148         test_user = create_random_string_list(length=15, count=1)[0]
00149         member = u" * %s\n" % test_user
00150         page.saveText(member, 0, trivial=1)
00151 
00152         result = test_user in request.groups[u'UserGroup']
00153 
00154         nuke_page(request, u'UserGroup')
00155 
00156         assert result
00157 
00158     def test_wiki_backend_page_acl_append_page(self):
00159         """
00160         Test if the wiki group backend works with acl code.
00161         First check acl rights of a user that is not a member of group
00162         then add user member to a page group and check acl rights
00163         """
00164         request = self.request
00165         become_trusted(request)
00166 
00167         create_page(request, u'NewGroup', u" * ExampleUser")
00168 
00169         acl_rights = ["NewGroup:read,write"]
00170         acl = security.AccessControlList(request.cfg, acl_rights)
00171 
00172         has_rights_before = acl.may(request, u"AnotherUser", "read")
00173 
00174         # update page - add AnotherUser to a page group NewGroup
00175         append_page(request, u'NewGroup', u" * AnotherUser")
00176 
00177         has_rights_after = acl.may(request, u"AnotherUser", "read")
00178 
00179         nuke_page(request, u'NewGroup')
00180 
00181         assert not has_rights_before, 'AnotherUser has no read rights because in the beginning he is not a member of a group page NewGroup'
00182         assert has_rights_after, 'AnotherUser must have read rights because after appendage he is member of NewGroup'
00183 
00184 coverage_modules = ['MoinMoin.datastruct.backends.wiki_groups']
00185