Make JCL work with PyXMPP 1.0.1

Ignore-this: a67d7757208674a1c7479d122697fbc2

darcs-hash:20090701192440-86b55-e335b5eedc2585c79745c994e4826c26939ce689.gz
This commit is contained in:
David Rousselie
2009-07-01 21:24:40 +02:00
parent 24f81d1e90
commit 046bb70839
5 changed files with 67 additions and 47 deletions

View File

@@ -44,7 +44,7 @@ if __name__ == '__main__':
class MyTestProgram(unittest.TestProgram): class MyTestProgram(unittest.TestProgram):
def runTests(self): def runTests(self):
"""run tests but do not exit after""" """run tests but do not exit after"""
self.testRunner = unittest.TextTestRunner(verbosity=self.verbosity) self.testRunner = unittest.TextTestRunner(verbosity=self.verbosity)
self.testRunner.run(self.test) self.testRunner.run(self.test)
logger = logging.getLogger() logger = logging.getLogger()

View File

@@ -406,7 +406,7 @@ class JCLCommandManager(CommandManager):
label = _account.name + " (" + account_type \ label = _account.name + " (" + account_type \
+ ")" + ")"
field.add_option(label=label, field.add_option(label=label,
values=[_account.name + "/" + user_jid]) value=_account.name + "/" + user_jid)
def add_form_select_accounts(self, session_context, def add_form_select_accounts(self, session_context,
command_node, lang_class, command_node, lang_class,
@@ -461,7 +461,7 @@ class JCLCommandManager(CommandManager):
label=lang_class.field_max_items) label=lang_class.field_max_items)
for value in ["25", "50", "75", "100", "150", "200"]: for value in ["25", "50", "75", "100", "150", "200"]:
max_items_field.add_option(label=value, max_items_field.add_option(label=value,
values=[value]) value=value)
result_form.as_xml(command_node) result_form.as_xml(command_node)
return (result_form, []) return (result_form, [])
@@ -545,7 +545,7 @@ class JCLCommandManager(CommandManager):
for (account_type, type_label) in \ for (account_type, type_label) in \
self.component.account_manager.list_account_types(lang_class): self.component.account_manager.list_account_types(lang_class):
field.add_option(label=type_label, field.add_option(label=type_label,
values=[account_type]) value=account_type)
if self.component.is_admin(info_query.get_from()): if self.component.is_admin(info_query.get_from()):
result_form.add_field(name="user_jid", result_form.add_field(name="user_jid",
field_type="jid-single", field_type="jid-single",
@@ -1159,19 +1159,19 @@ class JCLCommandManager(CommandManager):
label=lang_class.field_restart_delay, label=lang_class.field_restart_delay,
required=True) required=True)
delay_field.add_option(label=lang_class.field_30_sec, delay_field.add_option(label=lang_class.field_30_sec,
values=["30"]) value="30")
delay_field.add_option(label=lang_class.field_60_sec, delay_field.add_option(label=lang_class.field_60_sec,
values=["60"]) value="60")
delay_field.add_option(label=lang_class.field_90_sec, delay_field.add_option(label=lang_class.field_90_sec,
values=["90"]) value="90")
delay_field.add_option(label=lang_class.field_120_sec, delay_field.add_option(label=lang_class.field_120_sec,
values=["120"]) value="120")
delay_field.add_option(label=lang_class.field_180_sec, delay_field.add_option(label=lang_class.field_180_sec,
values=["180"]) value="180")
delay_field.add_option(label=lang_class.field_240_sec, delay_field.add_option(label=lang_class.field_240_sec,
values=["240"]) value="240")
delay_field.add_option(label=lang_class.field_300_sec, delay_field.add_option(label=lang_class.field_300_sec,
values=["300"]) value="300")
result_form.add_field(name="announcement", result_form.add_field(name="announcement",
field_type="text-multi", field_type="text-multi",
label=lang_class.field_announcement) label=lang_class.field_announcement)
@@ -1221,19 +1221,19 @@ class JCLCommandManager(CommandManager):
label=lang_class.field_shutdown_delay, label=lang_class.field_shutdown_delay,
required=True) required=True)
delay_field.add_option(label=lang_class.field_30_sec, delay_field.add_option(label=lang_class.field_30_sec,
values=["30"]) value="30")
delay_field.add_option(label=lang_class.field_60_sec, delay_field.add_option(label=lang_class.field_60_sec,
values=["60"]) value="60")
delay_field.add_option(label=lang_class.field_90_sec, delay_field.add_option(label=lang_class.field_90_sec,
values=["90"]) value="90")
delay_field.add_option(label=lang_class.field_120_sec, delay_field.add_option(label=lang_class.field_120_sec,
values=["120"]) value="120")
delay_field.add_option(label=lang_class.field_180_sec, delay_field.add_option(label=lang_class.field_180_sec,
values=["180"]) value="180")
delay_field.add_option(label=lang_class.field_240_sec, delay_field.add_option(label=lang_class.field_240_sec,
values=["240"]) value="240")
delay_field.add_option(label=lang_class.field_300_sec, delay_field.add_option(label=lang_class.field_300_sec,
values=["300"]) value="300")
result_form.add_field(name="announcement", result_form.add_field(name="announcement",
field_type="text-multi", field_type="text-multi",
label=lang_class.field_announcement) label=lang_class.field_announcement)

View File

@@ -496,7 +496,7 @@ class AccountManager(object):
else: else:
label = option_value label = option_value
field.add_option(label=label, field.add_option(label=label,
values=[option_value]) value=option_value)
try: try:
post_func(None, default_func, bare_from_jid) post_func(None, default_func, bare_from_jid)
except: except:
@@ -661,6 +661,9 @@ class JCLComponent(Component, object):
Start timer thread Start timer thread
Call Component main loop Call Component main loop
Clean up when shutting down JCLcomponent Clean up when shutting down JCLcomponent
Return a boolean set to True if the component need to be restarted
and a delay to wait before restarting
""" """
wait_before_restart = 5 wait_before_restart = 5
self._restart = True self._restart = True
@@ -737,8 +740,9 @@ class JCLComponent(Component, object):
and not self.stream.eof and not self.stream.eof
and self.stream.socket is not None): and self.stream.socket is not None):
self.wait_event.wait(self.time_unit) self.wait_event.wait(self.time_unit)
self.handle_tick() if not self.wait_event.is_set():
self.__logger.debug(".") self.handle_tick()
self.__logger.debug(".")
except Exception, exception: except Exception, exception:
self.__logger.error("Error in timer thread:", exc_info=True) self.__logger.error("Error in timer thread:", exc_info=True)
self.queue.put(exception) self.queue.put(exception)

View File

@@ -33,6 +33,7 @@ from pyxmpp.jabber.dataforms import Form
from pyxmpp.iq import Iq from pyxmpp.iq import Iq
from pyxmpp.jabber.disco import DiscoItems from pyxmpp.jabber.disco import DiscoItems
from pyxmpp.jabber.dataforms import Field from pyxmpp.jabber.dataforms import Field
import pyxmpp.xmlextra
import jcl.tests import jcl.tests
from jcl.lang import Lang from jcl.lang import Lang
@@ -45,6 +46,8 @@ from jcl.model.account import Account, PresenceAccount, LegacyJID, User
from jcl.model.tests.account import ExampleAccount, Example2Account from jcl.model.tests.account import ExampleAccount, Example2Account
from jcl.tests import JCLTestCase from jcl.tests import JCLTestCase
PYXMPP_NS = pyxmpp.xmlextra.COMMON_NS
class FieldNoType_TestCase(unittest.TestCase): class FieldNoType_TestCase(unittest.TestCase):
def test_complete_xml_element(self): def test_complete_xml_element(self):
fake_iq = Iq(stanza_type="get", fake_iq = Iq(stanza_type="get",
@@ -444,7 +447,7 @@ class CommandManager_TestCase(unittest.TestCase):
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<iq from='" + unicode(self.command_manager.component.jid) u"<iq from='" + unicode(self.command_manager.component.jid)
+ "' to='user@test.com' type='error' " + "' to='user@test.com' type='error' "
+ "xmlns='http://pyxmpp.jabberstudio.org/xmlns/common'>" + "xmlns='" + PYXMPP_NS + "'>"
+ "<command xmlns='http://jabber.org/protocol/commands'" + "<command xmlns='http://jabber.org/protocol/commands'"
+ "node='command1' />" + "node='command1' />"
+ "<error type='cancel'><feature-not-implemented " + "<error type='cancel'><feature-not-implemented "
@@ -475,7 +478,7 @@ class CommandManager_TestCase(unittest.TestCase):
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<iq from='" + unicode(self.command_manager.component.jid) u"<iq from='" + unicode(self.command_manager.component.jid)
+ "' to='user@test.com' type='error' " + "' to='user@test.com' type='error' "
+ "xmlns='http://pyxmpp.jabberstudio.org/xmlns/common'>" + "xmlns='" + PYXMPP_NS + "'>"
+ "<command xmlns='http://jabber.org/protocol/commands'" + "<command xmlns='http://jabber.org/protocol/commands'"
+ "node='command1' />" + "node='command1' />"
+ "<error type='cancel'><service-unavailable " + "<error type='cancel'><service-unavailable "
@@ -859,14 +862,14 @@ class JCLCommandManagerAddUserCommand_TestCase(JCLCommandManagerTestCase):
result_iq = result[1].xmlnode result_iq = result[1].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<presence from='" + unicode(self.comp.jid) + "' " u"<presence from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='" + new_jid + "' " + "to='" + new_jid + "' "
+ "type='subscribe' />", + "type='subscribe' />",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
result_iq = result[2].xmlnode result_iq = result[2].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<message from='" + unicode(self.comp.jid) + "' " u"<message from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='" + new_jid + "'>" + "to='" + new_jid + "'>"
+ "<subject>" + _account.get_new_message_subject(Lang.en) + "<subject>" + _account.get_new_message_subject(Lang.en)
+ "</subject>" + "</subject>"
@@ -876,7 +879,7 @@ class JCLCommandManagerAddUserCommand_TestCase(JCLCommandManagerTestCase):
result_iq = result[3].xmlnode result_iq = result[3].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<presence from='account1@" + unicode(self.comp.jid) + "' " u"<presence from='account1@" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='" + new_jid + "' type='subscribe' />", + "to='" + new_jid + "' type='subscribe' />",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
context_session = self.command_manager.sessions[session_id][1] context_session = self.command_manager.sessions[session_id][1]
@@ -1203,28 +1206,28 @@ class JCLCommandManagerDeleteUserCommand_TestCase(JCLCommandManagerTestCase):
result_iq = result[1].xmlnode result_iq = result[1].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<presence from='account11@" + unicode(self.comp.jid) + "' " u"<presence from='account11@" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test1@test.com' " + "to='test1@test.com' "
+ "type='unsubscribe' />", + "type='unsubscribe' />",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
result_iq = result[2].xmlnode result_iq = result[2].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<presence from='account11@" + unicode(self.comp.jid) + "' " u"<presence from='account11@" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test1@test.com' " + "to='test1@test.com' "
+ "type='unsubscribed' />", + "type='unsubscribed' />",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
result_iq = result[3].xmlnode result_iq = result[3].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<presence from='account11@" + unicode(self.comp.jid) + "' " u"<presence from='account11@" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test2@test.com' " + "to='test2@test.com' "
+ "type='unsubscribe' />", + "type='unsubscribe' />",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
result_iq = result[4].xmlnode result_iq = result[4].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<presence from='account11@" + unicode(self.comp.jid) + "' " u"<presence from='account11@" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test2@test.com' " + "to='test2@test.com' "
+ "type='unsubscribed' />", + "type='unsubscribed' />",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
@@ -1540,14 +1543,14 @@ class JCLCommandManagerEndUserSessionCommand_TestCase(JCLCommandManagerTestCase)
result_iq = result[1].xmlnode result_iq = result[1].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<presence from='account11@" + unicode(self.comp.jid) + "' " u"<presence from='account11@" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test1@test.com' " + "to='test1@test.com' "
+ "type='unavailable' />", + "type='unavailable' />",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
result_iq = result[2].xmlnode result_iq = result[2].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<presence from='account11@" + unicode(self.comp.jid) + "' " u"<presence from='account11@" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test2@test.com' " + "to='test2@test.com' "
+ "type='unavailable' />", + "type='unavailable' />",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
@@ -2527,14 +2530,14 @@ class JCLCommandManagerAnnounceCommand_TestCase(JCLCommandManagerTestCase):
result_iq = result[1].xmlnode result_iq = result[1].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<message from='" + unicode(self.comp.jid) + "' " u"<message from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test1@test.com'>" + "to='test1@test.com'>"
+ "<body>test announce</body></message>", + "<body>test announce</body></message>",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
result_iq = result[2].xmlnode result_iq = result[2].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<message from='" + unicode(self.comp.jid) + "' " u"<message from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test2@test.com'>" + "to='test2@test.com'>"
+ "<body>test announce</body></message>", + "<body>test announce</body></message>",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
@@ -2628,7 +2631,7 @@ class JCLCommandManagerSetMOTDCommand_TestCase(JCLCommandManagerTestCase):
result_iq = result[1].xmlnode result_iq = result[1].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<message from='" + unicode(self.comp.jid) + "' " u"<message from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test1@test.com'>" + "to='test1@test.com'>"
+ "<body>Message Of The Day</body></message>", + "<body>Message Of The Day</body></message>",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
@@ -2705,7 +2708,7 @@ class JCLCommandManagerEditMOTDCommand_TestCase(JCLCommandManagerTestCase):
result_iq = result[1].xmlnode result_iq = result[1].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<message from='" + unicode(self.comp.jid) + "' " u"<message from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test1@test.com'>" + "to='test1@test.com'>"
+ "<body>Message Of The Day</body></message>", + "<body>Message Of The Day</body></message>",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
@@ -3037,14 +3040,14 @@ class JCLCommandManagerRestartCommand_TestCase(JCLCommandManagerTestCase):
result_iq = result[1].xmlnode result_iq = result[1].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<message from='" + unicode(self.comp.jid) + "' " u"<message from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test1@test.com'>" + "to='test1@test.com'>"
+ "<body>service will be restarted in 1 second</body></message>", + "<body>service will be restarted in 1 second</body></message>",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
result_iq = result[2].xmlnode result_iq = result[2].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<message from='" + unicode(self.comp.jid) + "' " u"<message from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test2@test.com'>" + "to='test2@test.com'>"
+ "<body>service will be restarted in 1 second</body></message>", + "<body>service will be restarted in 1 second</body></message>",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
@@ -3190,14 +3193,14 @@ class JCLCommandManagerShutdownCommand_TestCase(JCLCommandManagerTestCase):
result_iq = result[1].xmlnode result_iq = result[1].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<message from='" + unicode(self.comp.jid) + "' " u"<message from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test1@test.com'>" + "to='test1@test.com'>"
+ "<body>service will be shutdown in 1 second</body></message>", + "<body>service will be shutdown in 1 second</body></message>",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))
result_iq = result[2].xmlnode result_iq = result[2].xmlnode
self.assertTrue(jcl.tests.is_xml_equal(\ self.assertTrue(jcl.tests.is_xml_equal(\
u"<message from='" + unicode(self.comp.jid) + "' " u"<message from='" + unicode(self.comp.jid) + "' "
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" " + "xmlns=\"" + PYXMPP_NS + "\" "
+ "to='test2@test.com'>" + "to='test2@test.com'>"
+ "<body>service will be shutdown in 1 second</body></message>", + "<body>service will be shutdown in 1 second</body></message>",
result_iq, True, test_sibling=False)) result_iq, True, test_sibling=False))

View File

@@ -54,13 +54,16 @@ import jcl.jabber.command as command
from jcl.model.tests.account import ExampleAccount, Example2Account from jcl.model.tests.account import ExampleAccount, Example2Account
from jcl.tests import JCLTestCase from jcl.tests import JCLTestCase
logger = logging.getLogger()
class MockStream(object): class MockStream(object):
def __init__(self, def __init__(self,
jid="", jid="",
secret="", secret="",
server="", server="",
port=1, port=1,
keepalive=None): keepalive=None,
owner=None):
self.sent = [] self.sent = []
self.connection_started = False self.connection_started = False
self.connection_stopped = False self.connection_stopped = False
@@ -222,7 +225,7 @@ class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
message = Message(from_jid="user1@test.com", message = Message(from_jid="user1@test.com",
to_jid="account11@jcl.test.com") to_jid="account11@jcl.test.com")
handler1 = HandlerMock() handler1 = HandlerMock()
handler1.filter = lambda stanza, lang_class: None handler1.filter = lambda stanza, lang_class: None
handler2 = HandlerMock() handler2 = HandlerMock()
result = self.comp.apply_registered_behavior([[handler1], [handler2]], result = self.comp.apply_registered_behavior([[handler1], [handler2]],
message) message)
@@ -235,7 +238,7 @@ class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
message = Message(from_jid="user1@test.com", message = Message(from_jid="user1@test.com",
to_jid="account11@jcl.test.com") to_jid="account11@jcl.test.com")
handler1 = HandlerMock() handler1 = HandlerMock()
handler1.filter = lambda stanza, lang_class: False handler1.filter = lambda stanza, lang_class: False
handler2 = HandlerMock() handler2 = HandlerMock()
result = self.comp.apply_registered_behavior([[handler1], [handler2]], result = self.comp.apply_registered_behavior([[handler1], [handler2]],
message) message)
@@ -248,7 +251,7 @@ class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
message = Message(from_jid="user1@test.com", message = Message(from_jid="user1@test.com",
to_jid="account11@jcl.test.com") to_jid="account11@jcl.test.com")
handler1 = HandlerMock() handler1 = HandlerMock()
handler1.filter = lambda stanza, lang_class: "" handler1.filter = lambda stanza, lang_class: ""
handler2 = HandlerMock() handler2 = HandlerMock()
result = self.comp.apply_registered_behavior([[handler1], [handler2]], result = self.comp.apply_registered_behavior([[handler1], [handler2]],
message) message)
@@ -2970,7 +2973,7 @@ class JCLComponent_handle_command_TestCase(JCLComponent_TestCase):
class JCLComponent_run_TestCase(JCLComponent_TestCase): class JCLComponent_run_TestCase(JCLComponent_TestCase):
"""run' tests""" """run tests"""
def __comp_run(self): def __comp_run(self):
try: try:
@@ -3032,6 +3035,7 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
self.comp.stream = MockStreamLoopFailed() self.comp.stream = MockStreamLoopFailed()
self.comp.stream_class = MockStreamLoopFailed self.comp.stream_class = MockStreamLoopFailed
self.comp.restart = False self.comp.restart = False
self.comp.time_unit = 10
(result, time_to_wait) = self.comp.run() (result, time_to_wait) = self.comp.run()
self.assertEquals(time_to_wait, 5) self.assertEquals(time_to_wait, 5)
self.assertTrue(result) self.assertTrue(result)
@@ -3040,6 +3044,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
threads = threading.enumerate() threads = threading.enumerate()
self.assertEquals(len(threads), 1) self.assertEquals(len(threads), 1)
self.assertFalse(self.comp.stream.connection_stopped) self.assertFalse(self.comp.stream.connection_stopped)
if self.comp.queue.qsize():
raise self.comp.queue.get(0)
def test_run_startconnection_socketerror(self): def test_run_startconnection_socketerror(self):
"""Test when connection to Jabber server fails when starting""" """Test when connection to Jabber server fails when starting"""
@@ -3057,6 +3063,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
self.assertFalse(self.comp.running) self.assertFalse(self.comp.running)
threads = threading.enumerate() threads = threading.enumerate()
self.assertEquals(len(threads), 1) self.assertEquals(len(threads), 1)
if self.comp.queue.qsize():
raise self.comp.queue.get(0)
def test_run_connection_closed(self): def test_run_connection_closed(self):
"""Test when connection to Jabber server is closed""" """Test when connection to Jabber server is closed"""
@@ -3075,6 +3083,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
threads = threading.enumerate() threads = threading.enumerate()
self.assertEquals(len(threads), 1) self.assertEquals(len(threads), 1)
self.assertFalse(self.comp.stream.connection_stopped) self.assertFalse(self.comp.stream.connection_stopped)
if self.comp.queue.qsize():
raise self.comp.queue.get(0)
def test_run_unhandled_error(self): def test_run_unhandled_error(self):
"""Test main loop unhandled error from a component handler""" """Test main loop unhandled error from a component handler"""
@@ -3089,6 +3099,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
threads = threading.enumerate() threads = threading.enumerate()
self.assertEquals(len(threads), 1) self.assertEquals(len(threads), 1)
self.assertTrue(self.comp.stream.connection_stopped) self.assertTrue(self.comp.stream.connection_stopped)
if self.comp.queue.qsize():
raise self.comp.queue.get(0)
return return
self.fail("No exception caught") self.fail("No exception caught")
@@ -3102,6 +3114,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
threads = threading.enumerate() threads = threading.enumerate()
self.assertEquals(len(threads), 1) self.assertEquals(len(threads), 1)
self.assertTrue(self.comp.stream.connection_stopped) self.assertTrue(self.comp.stream.connection_stopped)
if self.comp.queue.qsize():
raise self.comp.queue.get(0)
return return
self.fail("No exception caught") self.fail("No exception caught")
@@ -3385,8 +3399,7 @@ def suite():
return test_suite return test_suite
if __name__ == '__main__': if __name__ == '__main__':
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler()) logger.addHandler(logging.StreamHandler())
if '-v' in sys.argv: if '-v' in sys.argv:
logger.setLevel(logging.INFO) logger.setLevel(logging.DEBUG)
unittest.main(defaultTest='suite') unittest.main(defaultTest='suite')