summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-10-01 13:49:58 -0400
committerLance Stout <lancestout@gmail.com>2010-10-01 13:49:58 -0400
commit9a34c9a9a1cb4ee6e34089f9e2aa204f7ed8c0c0 (patch)
tree90c8310c84281cdc13a37016b2bfc9d3352d6c41 /tests
parent26621311244c3546aa9a48bfdfe65021fe0861ec (diff)
downloadslixmpp-9a34c9a9a1cb4ee6e34089f9e2aa204f7ed8c0c0.tar.gz
slixmpp-9a34c9a9a1cb4ee6e34089f9e2aa204f7ed8c0c0.tar.bz2
slixmpp-9a34c9a9a1cb4ee6e34089f9e2aa204f7ed8c0c0.tar.xz
slixmpp-9a34c9a9a1cb4ee6e34089f9e2aa204f7ed8c0c0.zip
Modified event handling to use the event queue.
Updated tests to match. (Needed to add a small wait to make sure the event got through the queue before checking the results.)
Diffstat (limited to 'tests')
-rw-r--r--tests/test_events.py90
1 files changed, 66 insertions, 24 deletions
diff --git a/tests/test_events.py b/tests/test_events.py
index bbc5832e..df36969d 100644
--- a/tests/test_events.py
+++ b/tests/test_events.py
@@ -1,31 +1,73 @@
import sleekxmpp
+import time
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")
-
+
+ def setUp(self):
+ self.streamStart()
+
+ def tearDown(self):
+ self.streamClose()
+
+ def testEventHappening(self):
+ """Test handler working"""
+ happened = []
+
+ def handletestevent(event):
+ happened.append(True)
+
+ self.xmpp.add_event_handler("test_event", handletestevent)
+ self.xmpp.event("test_event")
+ self.xmpp.event("test_event")
+
+ # Give the event queue time to process.
+ time.sleep(0.1)
+
+ msg = "Event was not triggered the correct number of times: %s"
+ self.failUnless(happened == [True, True], msg)
+
+ def testDelEvent(self):
+ """Test handler working, then deleted and not triggered"""
+ happened = []
+
+ def handletestevent(event):
+ happened.append(True)
+
+ self.xmpp.add_event_handler("test_event", handletestevent)
+ self.xmpp.event("test_event", {})
+
+ self.xmpp.del_event_handler("test_event", handletestevent)
+
+ # Should not trigger because it was deleted
+ self.xmpp.event("test_event", {})
+
+ # Give the event queue time to process.
+ time.sleep(0.1)
+
+ msg = "Event was not triggered the correct number of times: %s"
+ self.failUnless(happened == [True], msg % happened)
+
+ def testDisposableEvent(self):
+ """Test disposable handler working, then not being triggered again."""
+ happened = []
+
+ def handletestevent(event):
+ happened.append(True)
+
+ self.xmpp.add_event_handler("test_event", handletestevent,
+ disposable=True)
+ self.xmpp.event("test_event", {})
+
+ # Should not trigger because it was deleted
+ self.xmpp.event("test_event", {})
+
+ # Give the event queue time to process.
+ time.sleep(0.1)
+
+ msg = "Event was not triggered the correct number of times: %s"
+ self.failUnless(happened == [True], msg % happened)
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestEvents)