changeset 1019:afe0afe4e1a6

recursive rename
author "Luis Henrique Fagundes <lhfagundes@gmail.com>"
date Sun, 30 Oct 2011 00:24:26 -0200
parents dfbe65482a03
children 80043704f37e
files MoinMoin/converter/_tests/test_include.py MoinMoin/items/__init__.py MoinMoin/items/_tests/test_Item.py
diffstat 3 files changed, 57 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/_tests/test_include.py	Sat Oct 29 20:09:50 2011 -0200
+++ b/MoinMoin/converter/_tests/test_include.py	Sun Oct 30 00:24:26 2011 -0200
@@ -74,7 +74,7 @@
 
         page1._render_data()
 
-    def test_IncludeOfSingleLinePage(self):
+    def test_InlineInclude(self):
         # issue #28
         update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}"')
 
--- a/MoinMoin/items/__init__.py	Sat Oct 29 20:09:50 2011 -0200
+++ b/MoinMoin/items/__init__.py	Sun Oct 30 00:24:26 2011 -0200
@@ -293,7 +293,7 @@
                               {moin_page.namespace: '',
                                xlink.namespace: 'xlink',
                                html.namespace: 'html',
-                              })
+                               })
 
     def _render_data_highlight(self):
         # override this in child classes
@@ -312,23 +312,23 @@
                                last_rev_id=rev_ids and rev_ids[-1],
                                meta_rendered='',
                                data_rendered='',
-                              )
+                               )
 
     def meta_filter(self, meta):
         """ kill metadata entries that we set automatically when saving """
         kill_keys = [# shall not get copied from old rev to new rev
-                     SYSITEM_VERSION,
-                     NAME_OLD,
-                     # are automatically implanted when saving
-                     NAME,
-                     ITEMID, REVID, DATAID,
-                     HASH_ALGORITHM,
-                     SIZE,
-                     COMMENT,
-                     MTIME,
-                     ACTION,
-                     ADDRESS, HOSTNAME, USERID,
-                    ]
+            SYSITEM_VERSION,
+            NAME_OLD,
+            # are automatically implanted when saving
+            NAME,
+            ITEMID, REVID, DATAID,
+            HASH_ALGORITHM,
+            SIZE,
+            COMMENT,
+            MTIME,
+            ACTION,
+            ADDRESS, HOSTNAME, USERID,
+            ]
         for key in kill_keys:
             meta.pop(key, None)
         return meta
@@ -378,6 +378,9 @@
 
     def _rename(self, name, comment, action):
         self._save(self.meta, self.data, name=name, action=action, comment=comment)
+        for child in self.get_index():
+            item = Item.create(child[0])
+            item._save(item.meta, item.data, name='/'.join((name, child[1])), action=action, comment=comment)
 
     def rename(self, name, comment=u''):
         """
--- a/MoinMoin/items/_tests/test_Item.py	Sat Oct 29 20:09:50 2011 -0200
+++ b/MoinMoin/items/_tests/test_Item.py	Sun Oct 30 00:24:26 2011 -0200
@@ -11,7 +11,7 @@
 
 from flask import g as flaskg
 
-from MoinMoin._tests import become_trusted
+from MoinMoin._tests import become_trusted, update_item
 from MoinMoin.items import Item, ApplicationXTar, NonExistent, Binary, Text, Image, TransformableBitmapImage, MarkupItem
 from MoinMoin.config import CONTENTTYPE, ADDRESS, COMMENT, HOSTNAME, USERID, ACTION
 
@@ -203,6 +203,44 @@
         assert item.meta['comment'] == u'renamed'
         assert item.data == u'test_data'
 
+    def test_rename_recursion(self):
+        update_item(u'Page', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Page 1')
+        update_item(u'Page/Child', {CONTENTTYPE: u'text/x.moin.wiki'}, u'this is child')
+        update_item(u'Page/Child/Another', {CONTENTTYPE: u'text/x.moin.wiki'}, u'another child')
+
+        item = Item.create(u'Page')
+        item.rename(u'Renamed_Page', comment=u'renamed')
+
+        # items at original name and its contents after renaming
+        item = Item.create(u'Page')
+        assert item.name == u'Page'
+        assert item.meta[CONTENTTYPE] == 'application/x-nonexistent'
+        item = Item.create(u'Page/Child')
+        assert item.name == u'Page/Child'
+        assert item.meta[CONTENTTYPE] == 'application/x-nonexistent'
+        item = Item.create(u'Page/Child/Another')
+        assert item.name == u'Page/Child/Another'
+        assert item.meta[CONTENTTYPE] == 'application/x-nonexistent'
+
+        # item at new name and its contents after renaming
+        item = Item.create(u'Renamed_Page')
+        assert item.name == u'Renamed_Page'
+        assert item.meta['name_old'] == u'Page'
+        assert item.meta['comment'] == u'renamed'
+        assert item.data == u'Page 1'
+
+        item = Item.create(u'Renamed_Page/Child')
+        assert item.name == u'Renamed_Page/Child'
+        assert item.meta['name_old'] == u'Page/Child'
+        assert item.meta['comment'] == u'renamed'
+        assert item.data == u'this is child'
+
+        item = Item.create(u'Renamed_Page/Child/Another')
+        assert item.name == u'Renamed_Page/Child/Another'
+        assert item.meta['name_old'] == u'Page/Child/Another'
+        assert item.meta['comment'] == u'renamed'
+        assert item.data == u'another child'
+
     def test_delete(self):
         name = u'Test_Item2'
         contenttype = u'text/plain;charset=utf-8'