Make JCL work with PyXMPP 1.0.1
Ignore-this: a67d7757208674a1c7479d122697fbc2 darcs-hash:20090701192440-86b55-e335b5eedc2585c79745c994e4826c26939ce689.gz
This commit is contained in:
@@ -406,7 +406,7 @@ class JCLCommandManager(CommandManager):
|
||||
label = _account.name + " (" + account_type \
|
||||
+ ")"
|
||||
field.add_option(label=label,
|
||||
values=[_account.name + "/" + user_jid])
|
||||
value=_account.name + "/" + user_jid)
|
||||
|
||||
def add_form_select_accounts(self, session_context,
|
||||
command_node, lang_class,
|
||||
@@ -461,7 +461,7 @@ class JCLCommandManager(CommandManager):
|
||||
label=lang_class.field_max_items)
|
||||
for value in ["25", "50", "75", "100", "150", "200"]:
|
||||
max_items_field.add_option(label=value,
|
||||
values=[value])
|
||||
value=value)
|
||||
result_form.as_xml(command_node)
|
||||
return (result_form, [])
|
||||
|
||||
@@ -545,7 +545,7 @@ class JCLCommandManager(CommandManager):
|
||||
for (account_type, type_label) in \
|
||||
self.component.account_manager.list_account_types(lang_class):
|
||||
field.add_option(label=type_label,
|
||||
values=[account_type])
|
||||
value=account_type)
|
||||
if self.component.is_admin(info_query.get_from()):
|
||||
result_form.add_field(name="user_jid",
|
||||
field_type="jid-single",
|
||||
@@ -1159,19 +1159,19 @@ class JCLCommandManager(CommandManager):
|
||||
label=lang_class.field_restart_delay,
|
||||
required=True)
|
||||
delay_field.add_option(label=lang_class.field_30_sec,
|
||||
values=["30"])
|
||||
value="30")
|
||||
delay_field.add_option(label=lang_class.field_60_sec,
|
||||
values=["60"])
|
||||
value="60")
|
||||
delay_field.add_option(label=lang_class.field_90_sec,
|
||||
values=["90"])
|
||||
value="90")
|
||||
delay_field.add_option(label=lang_class.field_120_sec,
|
||||
values=["120"])
|
||||
value="120")
|
||||
delay_field.add_option(label=lang_class.field_180_sec,
|
||||
values=["180"])
|
||||
value="180")
|
||||
delay_field.add_option(label=lang_class.field_240_sec,
|
||||
values=["240"])
|
||||
value="240")
|
||||
delay_field.add_option(label=lang_class.field_300_sec,
|
||||
values=["300"])
|
||||
value="300")
|
||||
result_form.add_field(name="announcement",
|
||||
field_type="text-multi",
|
||||
label=lang_class.field_announcement)
|
||||
@@ -1221,19 +1221,19 @@ class JCLCommandManager(CommandManager):
|
||||
label=lang_class.field_shutdown_delay,
|
||||
required=True)
|
||||
delay_field.add_option(label=lang_class.field_30_sec,
|
||||
values=["30"])
|
||||
value="30")
|
||||
delay_field.add_option(label=lang_class.field_60_sec,
|
||||
values=["60"])
|
||||
value="60")
|
||||
delay_field.add_option(label=lang_class.field_90_sec,
|
||||
values=["90"])
|
||||
value="90")
|
||||
delay_field.add_option(label=lang_class.field_120_sec,
|
||||
values=["120"])
|
||||
value="120")
|
||||
delay_field.add_option(label=lang_class.field_180_sec,
|
||||
values=["180"])
|
||||
value="180")
|
||||
delay_field.add_option(label=lang_class.field_240_sec,
|
||||
values=["240"])
|
||||
value="240")
|
||||
delay_field.add_option(label=lang_class.field_300_sec,
|
||||
values=["300"])
|
||||
value="300")
|
||||
result_form.add_field(name="announcement",
|
||||
field_type="text-multi",
|
||||
label=lang_class.field_announcement)
|
||||
|
||||
@@ -496,7 +496,7 @@ class AccountManager(object):
|
||||
else:
|
||||
label = option_value
|
||||
field.add_option(label=label,
|
||||
values=[option_value])
|
||||
value=option_value)
|
||||
try:
|
||||
post_func(None, default_func, bare_from_jid)
|
||||
except:
|
||||
@@ -661,6 +661,9 @@ class JCLComponent(Component, object):
|
||||
Start timer thread
|
||||
Call Component main loop
|
||||
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
|
||||
self._restart = True
|
||||
@@ -737,8 +740,9 @@ class JCLComponent(Component, object):
|
||||
and not self.stream.eof
|
||||
and self.stream.socket is not None):
|
||||
self.wait_event.wait(self.time_unit)
|
||||
self.handle_tick()
|
||||
self.__logger.debug(".")
|
||||
if not self.wait_event.is_set():
|
||||
self.handle_tick()
|
||||
self.__logger.debug(".")
|
||||
except Exception, exception:
|
||||
self.__logger.error("Error in timer thread:", exc_info=True)
|
||||
self.queue.put(exception)
|
||||
|
||||
@@ -33,6 +33,7 @@ from pyxmpp.jabber.dataforms import Form
|
||||
from pyxmpp.iq import Iq
|
||||
from pyxmpp.jabber.disco import DiscoItems
|
||||
from pyxmpp.jabber.dataforms import Field
|
||||
import pyxmpp.xmlextra
|
||||
|
||||
import jcl.tests
|
||||
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.tests import JCLTestCase
|
||||
|
||||
PYXMPP_NS = pyxmpp.xmlextra.COMMON_NS
|
||||
|
||||
class FieldNoType_TestCase(unittest.TestCase):
|
||||
def test_complete_xml_element(self):
|
||||
fake_iq = Iq(stanza_type="get",
|
||||
@@ -444,7 +447,7 @@ class CommandManager_TestCase(unittest.TestCase):
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<iq from='" + unicode(self.command_manager.component.jid)
|
||||
+ "' to='user@test.com' type='error' "
|
||||
+ "xmlns='http://pyxmpp.jabberstudio.org/xmlns/common'>"
|
||||
+ "xmlns='" + PYXMPP_NS + "'>"
|
||||
+ "<command xmlns='http://jabber.org/protocol/commands'"
|
||||
+ "node='command1' />"
|
||||
+ "<error type='cancel'><feature-not-implemented "
|
||||
@@ -475,7 +478,7 @@ class CommandManager_TestCase(unittest.TestCase):
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<iq from='" + unicode(self.command_manager.component.jid)
|
||||
+ "' to='user@test.com' type='error' "
|
||||
+ "xmlns='http://pyxmpp.jabberstudio.org/xmlns/common'>"
|
||||
+ "xmlns='" + PYXMPP_NS + "'>"
|
||||
+ "<command xmlns='http://jabber.org/protocol/commands'"
|
||||
+ "node='command1' />"
|
||||
+ "<error type='cancel'><service-unavailable "
|
||||
@@ -859,14 +862,14 @@ class JCLCommandManagerAddUserCommand_TestCase(JCLCommandManagerTestCase):
|
||||
result_iq = result[1].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<presence from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='" + new_jid + "' "
|
||||
+ "type='subscribe' />",
|
||||
result_iq, True, test_sibling=False))
|
||||
result_iq = result[2].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<message from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='" + new_jid + "'>"
|
||||
+ "<subject>" + _account.get_new_message_subject(Lang.en)
|
||||
+ "</subject>"
|
||||
@@ -876,7 +879,7 @@ class JCLCommandManagerAddUserCommand_TestCase(JCLCommandManagerTestCase):
|
||||
result_iq = result[3].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<presence from='account1@" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='" + new_jid + "' type='subscribe' />",
|
||||
result_iq, True, test_sibling=False))
|
||||
context_session = self.command_manager.sessions[session_id][1]
|
||||
@@ -1203,28 +1206,28 @@ class JCLCommandManagerDeleteUserCommand_TestCase(JCLCommandManagerTestCase):
|
||||
result_iq = result[1].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<presence from='account11@" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test1@test.com' "
|
||||
+ "type='unsubscribe' />",
|
||||
result_iq, True, test_sibling=False))
|
||||
result_iq = result[2].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<presence from='account11@" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test1@test.com' "
|
||||
+ "type='unsubscribed' />",
|
||||
result_iq, True, test_sibling=False))
|
||||
result_iq = result[3].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<presence from='account11@" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test2@test.com' "
|
||||
+ "type='unsubscribe' />",
|
||||
result_iq, True, test_sibling=False))
|
||||
result_iq = result[4].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<presence from='account11@" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test2@test.com' "
|
||||
+ "type='unsubscribed' />",
|
||||
result_iq, True, test_sibling=False))
|
||||
@@ -1540,14 +1543,14 @@ class JCLCommandManagerEndUserSessionCommand_TestCase(JCLCommandManagerTestCase)
|
||||
result_iq = result[1].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<presence from='account11@" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test1@test.com' "
|
||||
+ "type='unavailable' />",
|
||||
result_iq, True, test_sibling=False))
|
||||
result_iq = result[2].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<presence from='account11@" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test2@test.com' "
|
||||
+ "type='unavailable' />",
|
||||
result_iq, True, test_sibling=False))
|
||||
@@ -2527,14 +2530,14 @@ class JCLCommandManagerAnnounceCommand_TestCase(JCLCommandManagerTestCase):
|
||||
result_iq = result[1].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<message from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test1@test.com'>"
|
||||
+ "<body>test announce</body></message>",
|
||||
result_iq, True, test_sibling=False))
|
||||
result_iq = result[2].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<message from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test2@test.com'>"
|
||||
+ "<body>test announce</body></message>",
|
||||
result_iq, True, test_sibling=False))
|
||||
@@ -2628,7 +2631,7 @@ class JCLCommandManagerSetMOTDCommand_TestCase(JCLCommandManagerTestCase):
|
||||
result_iq = result[1].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<message from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test1@test.com'>"
|
||||
+ "<body>Message Of The Day</body></message>",
|
||||
result_iq, True, test_sibling=False))
|
||||
@@ -2705,7 +2708,7 @@ class JCLCommandManagerEditMOTDCommand_TestCase(JCLCommandManagerTestCase):
|
||||
result_iq = result[1].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<message from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test1@test.com'>"
|
||||
+ "<body>Message Of The Day</body></message>",
|
||||
result_iq, True, test_sibling=False))
|
||||
@@ -3037,14 +3040,14 @@ class JCLCommandManagerRestartCommand_TestCase(JCLCommandManagerTestCase):
|
||||
result_iq = result[1].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<message from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test1@test.com'>"
|
||||
+ "<body>service will be restarted in 1 second</body></message>",
|
||||
result_iq, True, test_sibling=False))
|
||||
result_iq = result[2].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<message from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test2@test.com'>"
|
||||
+ "<body>service will be restarted in 1 second</body></message>",
|
||||
result_iq, True, test_sibling=False))
|
||||
@@ -3190,14 +3193,14 @@ class JCLCommandManagerShutdownCommand_TestCase(JCLCommandManagerTestCase):
|
||||
result_iq = result[1].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<message from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test1@test.com'>"
|
||||
+ "<body>service will be shutdown in 1 second</body></message>",
|
||||
result_iq, True, test_sibling=False))
|
||||
result_iq = result[2].xmlnode
|
||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||
u"<message from='" + unicode(self.comp.jid) + "' "
|
||||
+ "xmlns=\"http://pyxmpp.jabberstudio.org/xmlns/common\" "
|
||||
+ "xmlns=\"" + PYXMPP_NS + "\" "
|
||||
+ "to='test2@test.com'>"
|
||||
+ "<body>service will be shutdown in 1 second</body></message>",
|
||||
result_iq, True, test_sibling=False))
|
||||
|
||||
@@ -54,13 +54,16 @@ import jcl.jabber.command as command
|
||||
from jcl.model.tests.account import ExampleAccount, Example2Account
|
||||
from jcl.tests import JCLTestCase
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
class MockStream(object):
|
||||
def __init__(self,
|
||||
jid="",
|
||||
secret="",
|
||||
server="",
|
||||
port=1,
|
||||
keepalive=None):
|
||||
keepalive=None,
|
||||
owner=None):
|
||||
self.sent = []
|
||||
self.connection_started = False
|
||||
self.connection_stopped = False
|
||||
@@ -222,7 +225,7 @@ class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
|
||||
message = Message(from_jid="user1@test.com",
|
||||
to_jid="account11@jcl.test.com")
|
||||
handler1 = HandlerMock()
|
||||
handler1.filter = lambda stanza, lang_class: None
|
||||
handler1.filter = lambda stanza, lang_class: None
|
||||
handler2 = HandlerMock()
|
||||
result = self.comp.apply_registered_behavior([[handler1], [handler2]],
|
||||
message)
|
||||
@@ -235,7 +238,7 @@ class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
|
||||
message = Message(from_jid="user1@test.com",
|
||||
to_jid="account11@jcl.test.com")
|
||||
handler1 = HandlerMock()
|
||||
handler1.filter = lambda stanza, lang_class: False
|
||||
handler1.filter = lambda stanza, lang_class: False
|
||||
handler2 = HandlerMock()
|
||||
result = self.comp.apply_registered_behavior([[handler1], [handler2]],
|
||||
message)
|
||||
@@ -248,7 +251,7 @@ class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
|
||||
message = Message(from_jid="user1@test.com",
|
||||
to_jid="account11@jcl.test.com")
|
||||
handler1 = HandlerMock()
|
||||
handler1.filter = lambda stanza, lang_class: ""
|
||||
handler1.filter = lambda stanza, lang_class: ""
|
||||
handler2 = HandlerMock()
|
||||
result = self.comp.apply_registered_behavior([[handler1], [handler2]],
|
||||
message)
|
||||
@@ -2970,7 +2973,7 @@ class JCLComponent_handle_command_TestCase(JCLComponent_TestCase):
|
||||
|
||||
|
||||
class JCLComponent_run_TestCase(JCLComponent_TestCase):
|
||||
"""run' tests"""
|
||||
"""run tests"""
|
||||
|
||||
def __comp_run(self):
|
||||
try:
|
||||
@@ -3032,6 +3035,7 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
|
||||
self.comp.stream = MockStreamLoopFailed()
|
||||
self.comp.stream_class = MockStreamLoopFailed
|
||||
self.comp.restart = False
|
||||
self.comp.time_unit = 10
|
||||
(result, time_to_wait) = self.comp.run()
|
||||
self.assertEquals(time_to_wait, 5)
|
||||
self.assertTrue(result)
|
||||
@@ -3040,6 +3044,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
|
||||
threads = threading.enumerate()
|
||||
self.assertEquals(len(threads), 1)
|
||||
self.assertFalse(self.comp.stream.connection_stopped)
|
||||
if self.comp.queue.qsize():
|
||||
raise self.comp.queue.get(0)
|
||||
|
||||
def test_run_startconnection_socketerror(self):
|
||||
"""Test when connection to Jabber server fails when starting"""
|
||||
@@ -3057,6 +3063,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
|
||||
self.assertFalse(self.comp.running)
|
||||
threads = threading.enumerate()
|
||||
self.assertEquals(len(threads), 1)
|
||||
if self.comp.queue.qsize():
|
||||
raise self.comp.queue.get(0)
|
||||
|
||||
def test_run_connection_closed(self):
|
||||
"""Test when connection to Jabber server is closed"""
|
||||
@@ -3075,6 +3083,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
|
||||
threads = threading.enumerate()
|
||||
self.assertEquals(len(threads), 1)
|
||||
self.assertFalse(self.comp.stream.connection_stopped)
|
||||
if self.comp.queue.qsize():
|
||||
raise self.comp.queue.get(0)
|
||||
|
||||
def test_run_unhandled_error(self):
|
||||
"""Test main loop unhandled error from a component handler"""
|
||||
@@ -3089,6 +3099,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
|
||||
threads = threading.enumerate()
|
||||
self.assertEquals(len(threads), 1)
|
||||
self.assertTrue(self.comp.stream.connection_stopped)
|
||||
if self.comp.queue.qsize():
|
||||
raise self.comp.queue.get(0)
|
||||
return
|
||||
self.fail("No exception caught")
|
||||
|
||||
@@ -3102,6 +3114,8 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
|
||||
threads = threading.enumerate()
|
||||
self.assertEquals(len(threads), 1)
|
||||
self.assertTrue(self.comp.stream.connection_stopped)
|
||||
if self.comp.queue.qsize():
|
||||
raise self.comp.queue.get(0)
|
||||
return
|
||||
self.fail("No exception caught")
|
||||
|
||||
@@ -3385,8 +3399,7 @@ def suite():
|
||||
return test_suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.addHandler(logging.StreamHandler())
|
||||
if '-v' in sys.argv:
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
unittest.main(defaultTest='suite')
|
||||
|
||||
Reference in New Issue
Block a user