changeset 5787:00704da830ea

Fixed bug in groups formatter which caused the last list item to be not in the group. Removed some tests that didn't make sense for me, added some new to detect this bug.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 02 Aug 2011 23:52:32 +0200
parents 8cb5ab136b87
children 89882824b375
files MoinMoin/datastruct/backends/_tests/test_wiki_groups.py MoinMoin/formatter/_tests/test_groups.py MoinMoin/formatter/groups.py
diffstat 3 files changed, 47 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/datastruct/backends/_tests/test_wiki_groups.py	Tue Aug 02 23:24:38 2011 +0200
+++ b/MoinMoin/datastruct/backends/_tests/test_wiki_groups.py	Tue Aug 02 23:52:32 2011 +0200
@@ -181,5 +181,39 @@
         assert not has_rights_before, 'AnotherUser has no read rights because in the beginning he is not a member of a group page NewGroup'
         assert has_rights_after, 'AnotherUser must have read rights because after appendage he is member of NewGroup'
 
+    def test_simple_group_page(self):
+        """
+        Tests if a simple group page is evaluated correctly.
+        """
+        request = self.request
+        become_trusted(request)
+        group_name = u'SimpleGroup'
+        page_text = u"""\
+ * FirstUser
+ * SecondUser
+ * LastUser"""
+        page = create_page(request, group_name, page_text)
+        group_members = set(request.groups[group_name])
+        assert group_members == set([u'FirstUser', u'SecondUser', u'LastUser'])
+        nuke_page(request, group_name)
+
+    def test_complex_group_page(self):
+        """
+        Tests if a complex group page is evaluated correctly.
+        """
+        request = self.request
+        become_trusted(request)
+        group_name = u'ComplexGroup'
+        page_text = u"""\
+ * FirstUser
+  * any text
+ * SecondUser
+ * LastUser
+  * any text"""
+        page = create_page(request, group_name, page_text)
+        group_members = set(request.groups[group_name])
+        assert group_members == set([u'FirstUser', u'SecondUser', u'LastUser'])
+        nuke_page(request, group_name)
+
 coverage_modules = ['MoinMoin.datastruct.backends.wiki_groups']
 
--- a/MoinMoin/formatter/_tests/test_groups.py	Tue Aug 02 23:24:38 2011 +0200
+++ b/MoinMoin/formatter/_tests/test_groups.py	Tue Aug 02 23:52:32 2011 +0200
@@ -56,19 +56,6 @@
         assert len(members) == 1
         assert u'extended link' in members
 
-    def test_extended_link_and_text(self):
-        text = """
- * [[extended link]] other text
- * other text [[extended link]]
- * other text [[extended link]] other text
-
-"""
-        members = self.get_members(text)
-        assert len(members) == 3
-        assert u'extended link other text' in members
-        assert u'other text extended link' in members
-        assert u'other text extended link other text' in members
-
     def test_ignore_not_first_level_list(self):
         text = """
  * first level
@@ -163,19 +150,6 @@
         assert len(members) == 1
         assert u'FrontPage' in members
 
-    def test_extended_link_and_text(self):
-        text = """
- * [[extended link]] other text
- * other text [[extended link]]
- * other text [[extended link]] other text
-
-"""
-        members = self.get_members(text)
-        assert len(members) == 3
-        assert u'extended link other text' in members
-        assert u'other text extended link' in members
-        assert u'other text extended link other text' in members
-
     def test_ignore_not_first_level_list(self):
         text = """
 * first level
--- a/MoinMoin/formatter/groups.py	Tue Aug 02 23:24:38 2011 +0200
+++ b/MoinMoin/formatter/groups.py	Tue Aug 02 23:52:32 2011 +0200
@@ -21,8 +21,7 @@
 
         self.members = []
         self._bullet_list_level = 0
-        self._inside_link = False
-        self._new_member = ''
+        self._catch_name = False
 
     def bullet_list(self, on, **kw):
         if on:
@@ -35,27 +34,24 @@
         return self.null()
 
     def listitem(self, on, **kw):
-        if self._bullet_list_level == 1:
-            if not on:
-                stripped_new_member = self._new_member.strip()
-                if stripped_new_member:
-                    self.members.append(stripped_new_member)
-            self._new_member = ''
+        if on and self._bullet_list_level == 1:
+            self._catch_name = True
         return self.null()
 
     def text(self, text, **kw):
-        if self._bullet_list_level == 1 and not self._inside_link:
-            self._new_member += text
+        if self._catch_name:
+            name = text.strip()
+            self.members.append(name)
+            self._catch_name = False
         return self.null()
 
     def pagelink(self, on, pagename='', page=None, **kw):
-        if self._bullet_list_level == 1:
-            self._inside_link = on
-            if not on:
-                if not pagename and page:
-                    pagename = page.page_name
-                pagename = wikiutil.normalize_pagename(pagename, self.request.cfg)
-                self._new_member += pagename
+        if self._catch_name:
+            if not pagename and page:
+                pagename = page.page_name
+            name = wikiutil.normalize_pagename(pagename, self.request.cfg)
+            self.members.append(name)
+            self._catch_name = False
         return self.null()
 
     def null(self, *args, **kw):