changeset 2487:509cde9e567f

Fix test of Abort in PageEditor so that it restores the event handler list.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 22 Jul 2007 01:16:45 +0200
parents 0c66cfd93cd9
children c707250dca17
files MoinMoin/_tests/test_PageEditor.py
diffstat 1 files changed, 31 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_PageEditor.py	Sat Jul 21 02:32:43 2007 +0200
+++ b/MoinMoin/_tests/test_PageEditor.py	Sun Jul 22 01:16:45 2007 +0200
@@ -170,34 +170,38 @@
         return page.getPagePath(use_underlay=0, check_create=0)
 
 
-def testSave(request):
-    """Test if saveText() is interrupted if PagePreSave event handler returns Abort"""
-
-    def handler(event):
-        from MoinMoin.events import Abort
-        return Abort("This is just a test")
-
-    pagename = u'AutoCreatedMoinMoinTemporaryTestPageFortestSave'
-    testtext = u'ThisIsSomeStupidTestPageText!'
+class TestSave:
+    
+    def setup_method(self, method):
+        self.old_handlers = self.request.cfg.event_handlers
+        gain_superuser_rights(self.request)
+        
+    def teardown_method(self, method):
+        self.request.cfg.event_handlers = self.old_handlers
+        
+    def testSaveAbort(self):
+        """Test if saveText() is interrupted if PagePreSave event handler returns Abort"""
+    
+        def handler(event):
+            from MoinMoin.events import Abort
+            return Abort("This is just a test")
+    
+        pagename = u'AutoCreatedMoinMoinTemporaryTestPageFortestSave'
+        testtext = u'ThisIsSomeStupidTestPageText!'
 
-    gain_superuser_rights(request)
-    cfg = request.cfg
-    cfg.event_handlers = [handler]
-
-    page = Page(request, pagename)
-    if page.exists():
-        deleter = PageEditor(request, pagename)
-        deleter.deletePage()
-        print 'BODY:', deleter.body
-
-    editor = PageEditor(request, pagename)
-    print 'BODY:', editor.body
-    editor.saveText(testtext, 0)
-
-    print "PageEditor can't save a page if Abort is returned from PreSave event handlers"
-    page = Page(request, pagename)
-    assert page.body != testtext
+        self.request.cfg.event_handlers = [handler]
+        
+        page = Page(self.request, pagename)
+        if page.exists():
+            deleter = PageEditor(self.request, pagename)
+            deleter.deletePage()
+    
+        editor = PageEditor(self.request, pagename)
+        editor.saveText(testtext, 0)
+    
+        print "PageEditor can't save a page if Abort is returned from PreSave event handlers"
+        page = Page(self.request, pagename)
+        assert page.body != testtext
 
 
 coverage_modules = ['MoinMoin.PageEditor']
-