changeset 3575:baa5bfe1b8e1

test_wikidicts: refactored tests to more useful names, changed defaults for the string list
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 11 May 2008 17:56:49 +0200
parents 0b7eb697e952
children 6b1b444b45f9
files MoinMoin/_tests/__init__.py MoinMoin/_tests/test_wikidicts.py
diffstat 2 files changed, 34 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/__init__.py	Sun May 11 08:26:52 2008 +0200
+++ b/MoinMoin/_tests/__init__.py	Sun May 11 17:56:49 2008 +0200
@@ -49,6 +49,17 @@
     if su_name not in request.cfg.superuser:
         request.cfg.superuser.append(su_name)
 
+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()
 
 # Creating and destroying test pages --------------------------------
 
@@ -79,20 +90,7 @@
     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()
-
-def create_random_string(name_len=14, count=3000):
-    """ creates a list of random names """
-    name_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
-    # long list of names
-    return [u"%s" % random_string(name_len, name_chars) for counter in range(count)]
+def create_random_string_list(length=14, count=10):
+    """ creates a list of random strings """
+    chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+    return [u"%s" % random_string(length, chars) for counter in range(count)]
--- a/MoinMoin/_tests/test_wikidicts.py	Sun May 11 08:26:52 2008 +0200
+++ b/MoinMoin/_tests/test_wikidicts.py	Sun May 11 17:56:49 2008 +0200
@@ -15,7 +15,7 @@
 from MoinMoin import Page
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.user import User
-from MoinMoin._tests import append_page, become_trusted, create_page, create_random_string, nuke_page, nuke_user
+from MoinMoin._tests import append_page, become_trusted, create_page, create_random_string_list, nuke_page, nuke_user
 
 class TestGroupPage:
 
@@ -159,15 +159,15 @@
 
     def testAppendingGroupPage(self):
         """
-         tests appending a name to a large list of group members
+         tests scalability by appending a name to a large list of group members
         """
         # long list of users
-        name = [u" * %s" % text for text in create_random_string(name_len=20, count=30000)]
+        page_content = [u" * %s" % member for member in create_random_string_list(length=15, count=30000)]
         request = self.request
         become_trusted(request)
 
-        test_user = create_random_string(name_len=20, count=1)[0]
-        page = create_page(request, u'UserGroup', "\n".join(name))
+        test_user = create_random_string_list(length=15, count=1)[0]
+        page = create_page(request, u'UserGroup', "\n".join(page_content))
         page = append_page(request, u'UserGroup', u' * %s' % test_user)
 
         members, groups = request.dicts.expand_group(u'UserGroup')
@@ -180,14 +180,14 @@
          tests appending a username to a large list of group members and user creation
         """
         # long list of users
-        name = [u" * %s" % text for text in create_random_string()]
+        page_content = [u" * %s" % member for member in create_random_string_list()]
 
         request = self.request
         become_trusted(request)
 
-        test_user = create_random_string(name_len=20, count=1)[0]
+        test_user = create_random_string_list(length=15, count=1)[0]
 
-        page = create_page(request, u'UserGroup', "\n".join(name))
+        page = create_page(request, u'UserGroup', "\n".join(page_content))
         page = append_page(request, u'UserGroup', u' * %s' % test_user)
 
         # now shortly later we create a user object
@@ -206,17 +206,17 @@
          tests appending a member to a large list of group members and recreating the page without the member
         """
         # long list of users
-        name = [u" * %s" % text for text in create_random_string()]
-        content = "\n".join(name)
+        page_content = [u" * %s" % member for member in create_random_string_list()]
+        page_content = "\n".join(page_content)
         request = self.request
         become_trusted(request)
 
-        test_user = create_random_string(name_len=20, count=1)[0]
+        test_user = create_random_string_list(length=15, count=1)[0]
 
-        page = create_page(request, u'UserGroup', content)
+        page = create_page(request, u'UserGroup', page_content)
         page = append_page(request, u'UserGroup', u' * %s' % test_user)
         # saves the text without test_user
-        page.saveText(content, 0)
+        page.saveText(page_content, 0)
 
         members, groups = request.dicts.expand_group(u'UserGroup')
         nuke_page(request, u'UserGroup')
@@ -230,13 +230,13 @@
         request = self.request
         become_trusted(request)
 
-        test_user = create_random_string(name_len=20, count=1)[0]
-        name = u" * %s\n" % test_user
-        page = create_page(request, u'UserGroup', name)
+        test_user = create_random_string_list(length=15, count=1)[0]
+        member = u" * %s\n" % test_user
+        page = create_page(request, u'UserGroup', member)
         # next member saved  as trivial change
-        test_user = create_random_string(name_len=20, count=1)[0]
-        name = u" * %s\n" % test_user
-        page.saveText(name, 0, trivial=1)
+        test_user = create_random_string_list(length=15, count=1)[0]
+        member = u" * %s\n" % test_user
+        page.saveText(member, 0, trivial=1)
 
         members, groups = request.dicts.expand_group(u'UserGroup')
         nuke_page(request, u'UserGroup')