changeset 3557:9052c06d4ae3

test_wikidicts: some more tests for group pages
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Mon, 05 May 2008 22:10:44 +0200
parents 2b6f1d6c485d
children 44d1cd70e74c
files MoinMoin/_tests/__init__.py MoinMoin/_tests/test_wikidicts.py
diffstat 2 files changed, 83 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/__init__.py	Mon May 05 20:38:56 2008 +0200
+++ b/MoinMoin/_tests/__init__.py	Mon May 05 22:10:44 2008 +0200
@@ -7,10 +7,11 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import shutil
+import os, shutil
 
+from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
-
+from MoinMoin import caching, user
 # Promoting the test user -------------------------------------------
 # Usually the tests run as anonymous user, but for some stuff, you
 # need more privs...
@@ -59,6 +60,15 @@
     page.saveText(content, 0)
     return page
 
+def append_page(request, pagename, content, do_editor_backup=False):
+    """ appends some conetent to an existing page """
+    # reads the raw text of the existing page
+    raw = Page(request, pagename).get_raw_body()
+    # adds the new content to the old
+    content = "%s\n%s\n"% (raw, content)
+    page = PageEditor(request, pagename, do_editor_backup=do_editor_backup)
+    page.saveText(content, 0)
+    return page
 
 def nuke_page(request, pagename):
     """ completely delete a page, everything in the pagedir """
@@ -67,3 +77,15 @@
     # really get rid of everything there:
     fpath = page.getPagePath(check_create=0)
     shutil.rmtree(fpath, True)
+
+def nuke_user(request, username):
+    """ completely delete a user """
+    user_dir = request.cfg.user_dir
+    user_id = user.getUserId(request, username)
+    # really get rid of the user
+    fpath = os.path.join(user_dir, user_id)
+    os.remove(fpath)
+    # delete cache
+    arena = 'user'
+    key = 'name2id'
+    caching.CacheEntry(request, arena, key, scope='wiki').remove()
--- a/MoinMoin/_tests/test_wikidicts.py	Mon May 05 20:38:56 2008 +0200
+++ b/MoinMoin/_tests/test_wikidicts.py	Mon May 05 22:10:44 2008 +0200
@@ -14,7 +14,8 @@
 from MoinMoin import wikidicts
 from MoinMoin import Page
 from MoinMoin.PageEditor import PageEditor
-from MoinMoin._tests import become_trusted, create_page, nuke_page
+from MoinMoin.user import User
+from MoinMoin._tests import append_page, become_trusted, create_page, nuke_page, nuke_user
 
 class TestGroupPage:
 
@@ -156,4 +157,61 @@
 
         assert u'ExampleUser' in members
 
+    def testAppendingGroupPage(self):
+        """
+         tests appending a name to a large list of group members
+        """
+        from MoinMoin.util import random_string
+        name_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+        name_len = 14
+        # long list of users
+        name =  [u" * %s" % random_string(name_len, name_chars) for counter in range(30000)]
+
+        request = self.request
+        become_trusted(request)
+        test_user = random_string(name_len, name_chars)
+        page = create_page(request, u'UserGroup', "\n".join(name))
+        page = append_page(request, u'UserGroup', u' * %s' % test_user)
+
+        group = wikidicts.Group(request, '')
+        isgroup = request.cfg.cache.page_group_regex.search
+        grouppages = request.rootpage.getPageList(user='', filter=isgroup)
+
+        members, groups = request.dicts.expand_group(u'UserGroup')
+        nuke_page(request, u'UserGroup')
+
+        assert test_user in members
+
+    def testUserAppendingGroupPage(self):
+        """
+         tests appending a username to a large list of group members and user creation
+        """
+        from MoinMoin.util import random_string
+        name_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+        name_len = 14
+        # long list of users
+        name =  [u" * %s" % random_string(name_len, name_chars) for counter in range(3000)]
+
+        request = self.request
+        become_trusted(request)
+        test_user = random_string(name_len, name_chars)
+
+        page = create_page(request, u'UserGroup', "\n".join(name))
+        page = append_page(request, u'UserGroup', u' * %s' % test_user)
+
+        # now shortly later we create a user object
+        user = User(request, name=test_user)
+        if not user.exists():
+            User(request, name=test_user, password=test_user).save()
+
+        group = wikidicts.Group(request, '')
+        isgroup = request.cfg.cache.page_group_regex.search
+        grouppages = request.rootpage.getPageList(user='', filter=isgroup)
+
+        members, groups = request.dicts.expand_group(u'UserGroup')
+        nuke_page(request, u'UserGroup')
+        nuke_user(request, test_user)
+
+        assert test_user in members
+
 coverage_modules = ['MoinMoin.wikidicts']