summaryrefslogtreecommitdiff
path: root/tests/test_events.py
blob: bbc5832ec2ea4c34c433e840f0ae1ba4c9a26ea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sleekxmpp
from . sleektest import *


class TestEvents(SleekTest):
	
	def testEventHappening(self):
		"Test handler working"
		c = sleekxmpp.ClientXMPP('crap@wherever', 'password')
		happened = []
		def handletestevent(event):
			happened.append(True)
		c.add_event_handler("test_event", handletestevent)
		c.event("test_event", {})
		c.event("test_event", {})
		self.failUnless(happened == [True, True], "event did not get triggered twice")
	
	def testDelEvent(self):
		"Test handler working, then deleted and not triggered"
		c = sleekxmpp.ClientXMPP('crap@wherever', 'password')
		happened = []
		def handletestevent(event):
			happened.append(True)
		c.add_event_handler("test_event", handletestevent)
		c.event("test_event", {})
		c.del_event_handler("test_event", handletestevent)
		c.event("test_event", {}) # should not trigger because it was deleted
		self.failUnless(happened == [True], "event did not get triggered the correct number of times")
        

suite = unittest.TestLoader().loadTestsFromTestCase(TestEvents)