changeset 2313:e8b6de8fbcb4

Merge with my devel branch.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Fri, 22 Jun 2007 17:59:11 +0200
parents 1369b1f31497 (current diff) a85d51778eda (diff)
children 02824b69a95c
files
diffstat 2 files changed, 42 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/_tests/test_events.py	Fri Jun 22 17:59:11 2007 +0200
@@ -0,0 +1,37 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - tests for MoinMoin.events module
+
+    @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin.request.CLI import Request
+import MoinMoin.events as events
+
+def test_get_handlers():
+    """Test if there are any event handlers. There should be some internal ones"""
+    
+    request = Request()
+    assert(events.get_handlers(request.cfg))
+
+def test_send_event():
+    """Test if event handlers are called and if proper messages are returned"""
+    
+    return_string = u"test_send_event"
+    
+    def event_handler(event):
+        return return_string
+    
+    request = Request()
+    request.cfg.event_handlers = [event_handler]
+    event = events.Event(request)
+    
+    print "A proper event handler should be called, and an 1-element list of messages returned"
+    assert(events.send_event(event)[0] == return_string)
+
+def test_subscribable_events():
+    """Test if there are any subscribable events. There should be some."""
+    
+    print "There should be at least a few subscribable events!"
+    assert(events.get_subscribable_events())
--- a/MoinMoin/events/__init__.py	Fri Jun 22 17:24:24 2007 +0200
+++ b/MoinMoin/events/__init__.py	Fri Jun 22 17:59:11 2007 +0200
@@ -145,16 +145,16 @@
 
 
 def send_event(event):
-    """Function called from outside to process an event"""
+    """Function called from outside to process an event
+    
+    @return: a list of messages returned by handlers
+    @rtype: list
+    """
    
     # A list of messages generated by event handlers, passed back to caller
     msg = []
     cfg = event.request.cfg
     
-    # Find all available event handlers
-    if cfg.event_handlers is None:
-        register_handlers(cfg)
-    
     # Try to handle the event with each available handler (for now)
     for handle in cfg.event_handlers:
         retval = handle(event)