annotate MoinMoin/_tests/test_events.py @ 2328:495b09143c10

Add a new unit test for _filter_subscriber_list()
author Karol Nowak <grzywacz@sul.uni.lodz.pl>
date Tue, 26 Jun 2007 10:46:24 +0200
parents e6ebe6853e51
children 10be78f1fa97
rev   line source
2311
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - tests for MoinMoin.events module
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
4
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5 @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7 """
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
8
2327
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
9 import py
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
10
2311
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
11 import MoinMoin.events as events
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2314
diff changeset
12 import MoinMoin.events.notification as notification
2328
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
13 import MoinMoin.events.jabbernotify as jabbernotify
2327
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
14 from MoinMoin.Page import Page
2328
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
15 from MoinMoin.user import User
2311
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
16
2314
38b6ba04671b Fix issues pointed out by xorAxAx.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2311
diff changeset
17 def test_get_handlers(request):
2311
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
18 """Test if there are any event handlers. There should be some internal ones"""
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2314
diff changeset
19
2314
38b6ba04671b Fix issues pointed out by xorAxAx.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2311
diff changeset
20 assert events.get_handlers(request.cfg)
2311
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
21
2314
38b6ba04671b Fix issues pointed out by xorAxAx.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2311
diff changeset
22 def test_send_event(request):
2311
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
23 """Test if event handlers are called and if proper messages are returned"""
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
24
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
25 return_string = u"test_send_event"
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
26
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
27 def event_handler(event):
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2314
diff changeset
28 return notification.Failure("Just a test")
2311
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
29
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
30 request.cfg.event_handlers = [event_handler]
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
31 event = events.Event(request)
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
32
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2314
diff changeset
33 print "A proper event handler must be called and an 1-element list of results returned"
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2314
diff changeset
34 results = events.send_event(event)
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2314
diff changeset
35 assert issubclass(results[0].__class__, events.EventResult)
2311
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
36
2314
38b6ba04671b Fix issues pointed out by xorAxAx.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2311
diff changeset
37 def test_subscribable_events(request):
2311
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
38 """Test if there are any subscribable events. There should be some."""
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
39
1833361481ff Some unit test for the MoinMoin.events module.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
40 print "There should be at least a few subscribable events!"
2314
38b6ba04671b Fix issues pointed out by xorAxAx.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2311
diff changeset
41 assert events.get_subscribable_events()
2327
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
42
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
43 def test_page_change_message(request):
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
44 page = Page(request, "FrontPage")
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
45
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
46 print "Provided with a dumb change type argument, this should raise an exception!"
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
47 py.test.raises(notification.UnknownChangeType, notification.page_change_message,
e6ebe6853e51 Unit test; check if page_change_message() raises an exception.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
48 "StupidType", request, page, "en", revisions=page.getRevList())
2314
38b6ba04671b Fix issues pointed out by xorAxAx.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2311
diff changeset
49
2328
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
50 def test_filter_subscriber_list(request):
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
51 user = User(request)
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
52 event = events.Event(request)
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
53
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
54 print "User is subscribed to this event and wants to get notified by jabber."
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
55 print "This means, that he should stay on the list."
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
56 user.notify_by_jabber = True
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
57 user.subscribed_events = [events.Event.__name__]
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
58 subscribers = {"en": [user]}
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
59 jabbernotify._filter_subscriber_list(event, subscribers)
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
60 assert subscribers["en"]
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
61
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
62 print "User is subscribed to this event, but doesn't want to get notified by jabber."
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
63 print "The list should be empty."
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
64 user.notify_by_jabber = False
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
65 user.subscribed_events = [events.Event.__name__]
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
66 subscribers = {"en": [user]}
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
67 jabbernotify._filter_subscriber_list(event, subscribers)
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
68 assert not subscribers["en"]
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
69
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
70 print "User is not subscribed to this event, but wants to get notfied by jabber."
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
71 print "The list should be empty."
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
72 user.notify_by_jabber = True
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
73 user.subscribed_events = []
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
74 subscribers = {"en": [user]}
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
75 jabbernotify._filter_subscriber_list(event, subscribers)
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
76 assert not subscribers["en"]
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
77
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
78 print "User is neither subscribed to this event, nor wants jabber notifications."
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
79 print "The list should be empty."
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
80 user.notify_by_jabber = False
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
81 user.subscribed_events = []
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
82 subscribers = {"en": [user]}
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
83 jabbernotify._filter_subscriber_list(event, subscribers)
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
84 assert not subscribers["en"]
495b09143c10 Add a new unit test for _filter_subscriber_list()
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2327
diff changeset
85
2314
38b6ba04671b Fix issues pointed out by xorAxAx.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2311
diff changeset
86 coverage_modules = ["MoinMoin.events"]