Skip to content
Snippets Groups Projects
Commit 7e137adf authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

Backed out changeset e1fd1ca926b4

This kind of work will come after 0.13
parent d79f73a6
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
This diff is collapsed.
'''
Created on Oct 18, 2009
@author: stephan
'''
import unittest
import common.configpaths
common.configpaths.gajimpaths.init(None)
common.configpaths.gajimpaths.init_profile("tmp-test-profile")
from common import logging_helpers
logging_helpers.set_quiet()
from interface import Interface
class Test(unittest.TestCase):
def test_instantiation(self):
''' Test that we can proper initialize and do not fail on globals '''
interface = Interface()
interface.run()
def test_dispatch(self):
''' Test dispatcher forwarding network events to handler_* methods '''
sut = Interface()
success = sut.dispatch('No Such Event', None, None)
self.assertFalse(success, msg="Unexisting event handled")
success = sut.dispatch('STANZA_ARRIVED', None, None)
self.assertTrue(success, msg="Existing event must be handled")
def test_register_unregister_single_handler(self):
''' Register / Unregister a custom event handler '''
sut = Interface()
event = 'TESTS_ARE_COOL_EVENT'
self.called = False
def handler(account, data):
self.assertEqual(account, 'account')
self.assertEqual(data, 'data')
self.called = True
self.assertFalse(self.called)
sut.register_handler('TESTS_ARE_COOL_EVENT', handler)
sut.dispatch(event, 'account', 'data')
self.assertTrue(self.called, msg="Handler should have been called")
self.called = False
sut.unregister_handler('TESTS_ARE_COOL_EVENT', handler)
sut.dispatch(event, 'account', 'data')
self.assertFalse(self.called, msg="Handler should no longer be called")
def test_dispatch_to_multiple_handlers(self):
''' Register and dispatch a single event to multiple handlers '''
sut = Interface()
event = 'SINGLE_EVENT'
self.called_a = False
self.called_b = False
def handler_a(account, data):
self.assertFalse(self.called_a, msg="One must only be notified once")
self.called_a = True
def handler_b(account, data):
self.assertFalse(self.called_b, msg="One must only be notified once")
self.called_b = True
sut.register_handler(event, handler_a)
sut.register_handler(event, handler_b)
# register again
sut.register_handler('SOME_OTHER_EVENT', handler_b)
sut.register_handler(event, handler_a)
sut.dispatch(event, 'account', 'data')
self.assertTrue(self.called_a and self.called_b,
msg="Both handlers should have been called")
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.test']
unittest.main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment