2010-07-20 16:22:25 +00:00
|
|
|
import sleekxmpp
|
2010-08-06 00:23:07 +00:00
|
|
|
from . sleektest import *
|
2010-05-20 20:09:04 +00:00
|
|
|
|
|
|
|
|
2010-07-20 16:22:25 +00:00
|
|
|
class TestEvents(SleekTest):
|
2010-05-20 20:09:04 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
2010-07-20 16:22:25 +00:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestEvents)
|