Back to index

moin  1.9.0~rc2
test_events.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - tests for MoinMoin.events module
00004 
00005     @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 import py
00010 
00011 import MoinMoin.events as events
00012 import MoinMoin.events.notification as notification
00013 import MoinMoin.events.jabbernotify as jabbernotify
00014 from MoinMoin.Page import Page
00015 from MoinMoin.user import User
00016 
00017 def test_get_handlers(request):
00018     """Test if there are any event handlers. There should be some internal ones"""
00019 
00020     assert events.get_handlers(request.cfg)
00021 
00022 def test_send_event(request):
00023     """Test if event handlers are called and if proper messages are returned"""
00024 
00025     py.test.skip('broken test - global state is changed somehow that test_GetVal looks broken')
00026     return_string = u"test_send_event"
00027 
00028     def event_handler(event):
00029         return notification.Failure("Just a test")
00030 
00031     request.cfg.event_handlers = [event_handler]
00032     event = events.Event(request)
00033 
00034     print "A proper event handler must be called and an 1-element list of results returned"
00035     results = events.send_event(event)
00036     assert issubclass(results[0].__class__, events.EventResult)
00037 
00038 def test_subscribable_events(request):
00039     """Test if there are any subscribable events. There should be some."""
00040 
00041     print "There should be at least a few subscribable events!"
00042     assert events.get_subscribable_events()
00043 
00044 def test_page_change_message(request):
00045     page = Page(request, "FrontPage")
00046 
00047     print "Provided with a dumb change type argument, this should raise an exception!"
00048     py.test.raises(notification.UnknownChangeType, notification.page_change_message,
00049                    "StupidType", request, page, "en", revisions=page.getRevList())
00050 
00051 def test_user_created_event(request):
00052     py.test.skip("Test is wrong, because it assumes send_notification will be called - but if there is no superuser subscribed to UserCreatedEvent, then no notification needs to be sent.")
00053     class server_dummy:
00054         def __init__(self):
00055             self.sent = False
00056 
00057         def send_notification(self, *args):
00058             self.sent = True
00059 
00060     event = events.UserCreatedEvent(request, User(request))
00061     request.cfg.notification_server = server_dummy()
00062     request.cfg.secrets = "thisisnotsecret"
00063 
00064     jabbernotify.handle_user_created(event)
00065     assert request.cfg.notification_server.sent is True
00066 
00067 def test_filter_subscriber_list(request):
00068     user = User(request)
00069     event = events.Event(request)
00070 
00071     print "User is subscribed to this event on jabber."
00072     print "This means, that he should stay on the list."
00073     user.jid = "user@example.com"
00074     user.jabber_subscribed_events = [events.Event.__name__]
00075     subscribers = {"en": [user]}
00076     notification.filter_subscriber_list(event, subscribers, True)
00077     assert subscribers["en"]
00078 
00079     print "User is not subscribed to this event on jabber."
00080     print "The list should be empty."
00081     user.jid = "user@example.com"
00082     user.jabber_subscribed_events = []
00083     subscribers = {"en": [user]}
00084     notification.filter_subscriber_list(event, subscribers, True)
00085     assert not subscribers["en"]
00086 
00087     print "User is subscribed to this event on email."
00088     print "This means, that he should stay on the list."
00089     user.email = "user@example.com"
00090     user.email_subscribed_events = [events.Event.__name__]
00091     subscribers = {"en": [user]}
00092     notification.filter_subscriber_list(event, subscribers, False)
00093     assert subscribers["en"]
00094 
00095     print "User is not subscribed to this event on email."
00096     print "The list should be empty."
00097     user.email = "user@example.com"
00098     user.email_subscribed_events = []
00099     subscribers = {"en": [user]}
00100     notification.filter_subscriber_list(event, subscribers, False)
00101     assert not subscribers["en"]
00102 
00103 coverage_modules = ["MoinMoin.events"]