replace send_stanzas by returned value in handler. Pyxmpp will take care to send these stanzas
This commit is contained in:
@@ -40,6 +40,7 @@ from jcl.model.account import Account, User
|
|||||||
COMMAND_NS = "http://jabber.org/protocol/commands"
|
COMMAND_NS = "http://jabber.org/protocol/commands"
|
||||||
|
|
||||||
ACTION_COMPLETE = "complete"
|
ACTION_COMPLETE = "complete"
|
||||||
|
ACTION_EXECUTE = "execute"
|
||||||
ACTION_NEXT = "next"
|
ACTION_NEXT = "next"
|
||||||
ACTION_PREVIOUS = "prev"
|
ACTION_PREVIOUS = "prev"
|
||||||
ACTION_CANCEL = "cancel"
|
ACTION_CANCEL = "cancel"
|
||||||
@@ -157,6 +158,9 @@ class CommandManager(object):
|
|||||||
return [info_query.make_error_response(\
|
return [info_query.make_error_response(\
|
||||||
"feature-not-implemented")]
|
"feature-not-implemented")]
|
||||||
|
|
||||||
|
def apply_complete_command(self, info_query, short_command_name):
|
||||||
|
return self.apply_execute_command(info_query, short_command_name)
|
||||||
|
|
||||||
def apply_execute_command(self, info_query, short_command_name):
|
def apply_execute_command(self, info_query, short_command_name):
|
||||||
return self.execute_multi_step_command(\
|
return self.execute_multi_step_command(\
|
||||||
info_query,
|
info_query,
|
||||||
|
|||||||
@@ -898,8 +898,8 @@ class JCLComponent(Component, object):
|
|||||||
Handle IQ-get "jabber:iq:last" requests.
|
Handle IQ-get "jabber:iq:last" requests.
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("IQ:Last request")
|
self.__logger.debug("IQ:Last request")
|
||||||
self.apply_registered_behavior(self.iqlast_handlers, info_query)
|
return self.apply_registered_behavior(self.iqlast_handlers, info_query,
|
||||||
return 1
|
send_result=False)
|
||||||
|
|
||||||
def handle_get_gateway(self, info_query):
|
def handle_get_gateway(self, info_query):
|
||||||
"""Handle IQ-get "jabber:iq:gateway" requests.
|
"""Handle IQ-get "jabber:iq:gateway" requests.
|
||||||
@@ -911,8 +911,7 @@ class JCLComponent(Component, object):
|
|||||||
query = info_query.new_query("jabber:iq:gateway")
|
query = info_query.new_query("jabber:iq:gateway")
|
||||||
query.newTextChild(query.ns(), "desc", lang_class.get_gateway_desc)
|
query.newTextChild(query.ns(), "desc", lang_class.get_gateway_desc)
|
||||||
query.newTextChild(query.ns(), "prompt", lang_class.get_gateway_prompt)
|
query.newTextChild(query.ns(), "prompt", lang_class.get_gateway_prompt)
|
||||||
self.send_stanzas([info_query])
|
return [info_query]
|
||||||
return 1
|
|
||||||
|
|
||||||
def handle_set_gateway(self, info_query):
|
def handle_set_gateway(self, info_query):
|
||||||
"""
|
"""
|
||||||
@@ -929,8 +928,7 @@ class JCLComponent(Component, object):
|
|||||||
query.newTextChild(query.ns(), "jid", jid)
|
query.newTextChild(query.ns(), "jid", jid)
|
||||||
# XEP-0100 - section 6: should be <jid> but PSI only work with <prompt>
|
# XEP-0100 - section 6: should be <jid> but PSI only work with <prompt>
|
||||||
query.newTextChild(query.ns(), "prompt", jid)
|
query.newTextChild(query.ns(), "prompt", jid)
|
||||||
self.send_stanzas([info_query])
|
return [info_query]
|
||||||
return 1
|
|
||||||
|
|
||||||
def disco_get_info(self, node, info_query):
|
def disco_get_info(self, node, info_query):
|
||||||
"""
|
"""
|
||||||
@@ -974,15 +972,14 @@ class JCLComponent(Component, object):
|
|||||||
query = info_query.new_query("jabber:iq:version")
|
query = info_query.new_query("jabber:iq:version")
|
||||||
query.newTextChild(query.ns(), "name", self.name)
|
query.newTextChild(query.ns(), "name", self.name)
|
||||||
query.newTextChild(query.ns(), "version", self.version)
|
query.newTextChild(query.ns(), "version", self.version)
|
||||||
self.send_stanzas([info_query])
|
return [info_query]
|
||||||
return 1
|
|
||||||
|
|
||||||
def handle_get_register(self, info_query):
|
def handle_get_register(self, info_query):
|
||||||
"""Send back register form to user
|
"""Send back register form to user
|
||||||
see node structure in disco_get_items()
|
see node structure in disco_get_items()
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("GET_REGISTER")
|
self.__logger.debug("GET_REGISTER")
|
||||||
self.apply_behavior(\
|
return self.apply_behavior(\
|
||||||
info_query,
|
info_query,
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_get_register(info_query,
|
self.account_manager.account_get_register(info_query,
|
||||||
@@ -997,21 +994,17 @@ class JCLComponent(Component, object):
|
|||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.root_get_register(info_query,
|
self.account_manager.root_get_register(info_query,
|
||||||
lang_class),
|
lang_class),
|
||||||
send_result=True)
|
send_result=False)
|
||||||
|
|
||||||
def handle_set_register(self, info_query):
|
def handle_set_register(self, info_query):
|
||||||
"""Handle user registration response
|
"""Handle user registration response
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("SET_REGISTER")
|
self.__logger.debug("SET_REGISTER")
|
||||||
lang_class = \
|
|
||||||
self.lang.get_lang_class_from_node(info_query.get_node())
|
|
||||||
from_jid = info_query.get_from()
|
from_jid = info_query.get_from()
|
||||||
remove = info_query.xpath_eval("r:query/r:remove",
|
remove = info_query.xpath_eval("r:query/r:remove",
|
||||||
{"r": "jabber:iq:register"})
|
{"r": "jabber:iq:register"})
|
||||||
if remove:
|
if remove:
|
||||||
result = self.account_manager.remove_all_accounts(from_jid)
|
return self.account_manager.remove_all_accounts(from_jid)
|
||||||
self.send_stanzas(result)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
x_node = info_query.xpath_eval("jir:query/jxd:x",
|
x_node = info_query.xpath_eval("jir:query/jxd:x",
|
||||||
{"jir": "jabber:iq:register",
|
{"jir": "jabber:iq:register",
|
||||||
@@ -1023,65 +1016,61 @@ class JCLComponent(Component, object):
|
|||||||
apply_filter_func=lambda filter_func, stanza, lang_class: \
|
apply_filter_func=lambda filter_func, stanza, lang_class: \
|
||||||
filter_func(stanza, lang_class, x_data),
|
filter_func(stanza, lang_class, x_data),
|
||||||
apply_handle_func=lambda handle_func, stanza, lang_class, data, result: \
|
apply_handle_func=lambda handle_func, stanza, lang_class, data, result: \
|
||||||
handle_func(stanza, lang_class, data, x_data))
|
handle_func(stanza, lang_class, data, x_data),
|
||||||
|
send_result=False)
|
||||||
|
|
||||||
def handle_presence_available(self, stanza):
|
def handle_presence_available(self, stanza):
|
||||||
"""Handle presence availability
|
"""Handle presence availability
|
||||||
if presence sent to the component ('if not name'), presence is sent to
|
if presence sent to the component ('if not name'), presence is sent to
|
||||||
all accounts for current user. Otherwise, send presence from current account.
|
all accounts for current user. Otherwise, send presence from current
|
||||||
|
account.
|
||||||
"""
|
"""
|
||||||
result = self.apply_registered_behavior(self.presence_available_handlers,
|
self.__logger.debug("PRESENCE_AVAILABLE")
|
||||||
stanza)
|
return self.apply_registered_behavior(self.presence_available_handlers,
|
||||||
return result
|
stanza, send_result=False)
|
||||||
|
|
||||||
|
|
||||||
def handle_presence_unavailable(self, stanza):
|
def handle_presence_unavailable(self, stanza):
|
||||||
"""Handle presence unavailability
|
"""Handle presence unavailability
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("PRESENCE_UNAVAILABLE")
|
self.__logger.debug("PRESENCE_UNAVAILABLE")
|
||||||
result = self.apply_registered_behavior(self.presence_unavailable_handlers,
|
return self.apply_registered_behavior(self.presence_unavailable_handlers,
|
||||||
stanza)
|
stanza, send_result=False)
|
||||||
return result
|
|
||||||
|
|
||||||
def handle_presence_subscribe(self, stanza):
|
def handle_presence_subscribe(self, stanza):
|
||||||
"""Handle subscribe presence from user
|
"""Handle subscribe presence from user
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("PRESENCE_SUBSCRIBE")
|
self.__logger.debug("PRESENCE_SUBSCRIBE")
|
||||||
result = self.apply_registered_behavior(self.presence_subscribe_handlers,
|
return self.apply_registered_behavior(self.presence_subscribe_handlers,
|
||||||
stanza)
|
stanza, send_result=False)
|
||||||
return result
|
|
||||||
|
|
||||||
def handle_presence_subscribed(self, stanza):
|
def handle_presence_subscribed(self, stanza):
|
||||||
"""Handle subscribed presence from user
|
"""Handle subscribed presence from user
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("PRESENCE_SUBSCRIBED")
|
self.__logger.debug("PRESENCE_SUBSCRIBED")
|
||||||
return 1
|
return []
|
||||||
|
|
||||||
def handle_presence_unsubscribe(self, stanza):
|
def handle_presence_unsubscribe(self, stanza):
|
||||||
"""Handle unsubscribe presence from user
|
"""Handle unsubscribe presence from user
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("PRESENCE_UNSUBSCRIBE")
|
self.__logger.debug("PRESENCE_UNSUBSCRIBE")
|
||||||
result = self.apply_registered_behavior(self.presence_unsubscribe_handlers,
|
return self.apply_registered_behavior(self.presence_unsubscribe_handlers,
|
||||||
stanza)
|
stanza, send_result=False)
|
||||||
return result
|
|
||||||
|
|
||||||
def handle_presence_unsubscribed(self, stanza):
|
def handle_presence_unsubscribed(self, stanza):
|
||||||
"""Handle unsubscribed presence from user
|
"""Handle unsubscribed presence from user
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("PRESENCE_UNSUBSCRIBED")
|
self.__logger.debug("PRESENCE_UNSUBSCRIBED")
|
||||||
presence = Presence(from_jid=stanza.get_to(),
|
return [Presence(from_jid=stanza.get_to(),
|
||||||
to_jid=stanza.get_from(),
|
to_jid=stanza.get_from(),
|
||||||
stanza_type="unavailable")
|
stanza_type="unavailable")]
|
||||||
self.send_stanzas([presence])
|
|
||||||
return 1
|
|
||||||
|
|
||||||
def handle_message(self, message):
|
def handle_message(self, message):
|
||||||
"""Handle new message
|
"""Handle new message
|
||||||
Handle password response message
|
Handle password response message
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("MESSAGE: " + str(message.get_body()))
|
self.__logger.debug("MESSAGE: " + str(message.get_body()))
|
||||||
self.apply_registered_behavior(self.msg_handlers, message)
|
return self.apply_registered_behavior(self.msg_handlers, message,
|
||||||
return 1
|
send_result=False)
|
||||||
|
|
||||||
def handle_command(self, info_query):
|
def handle_command(self, info_query):
|
||||||
"""
|
"""
|
||||||
@@ -1096,23 +1085,22 @@ class JCLComponent(Component, object):
|
|||||||
if action is None:
|
if action is None:
|
||||||
action = "execute"
|
action = "execute"
|
||||||
try:
|
try:
|
||||||
result = command.command_manager.apply_command_action(info_query,
|
return command.command_manager.apply_command_action(info_query,
|
||||||
command_node,
|
command_node,
|
||||||
action)
|
action)
|
||||||
self.send_stanzas(result)
|
|
||||||
except:
|
except:
|
||||||
self.__logger.error("Error in command " + str(command_node) +
|
self.__logger.error("Error in command " + str(command_node) +
|
||||||
" with " + str(info_query) + ":",
|
" with " + str(info_query) + ":",
|
||||||
exc_info=True)
|
exc_info=True)
|
||||||
return 1
|
return []
|
||||||
|
|
||||||
def handle_vcard(self, info_query):
|
def handle_vcard(self, info_query):
|
||||||
"""
|
"""
|
||||||
Handle VCard request
|
Handle VCard request
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("VCard request")
|
self.__logger.debug("VCard request")
|
||||||
self.apply_registered_behavior(self.vcard_handlers, info_query)
|
return self.apply_registered_behavior(self.vcard_handlers, info_query,
|
||||||
return 1
|
send_result=False)
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Utils
|
# Utils
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import traceback
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import pyxmpp.error as error
|
import pyxmpp.error as error
|
||||||
|
import pyxmpp.jid
|
||||||
|
|
||||||
from jcl.error import FieldError, MandatoryFieldError, NotWellFormedFieldError
|
from jcl.error import FieldError, MandatoryFieldError, NotWellFormedFieldError
|
||||||
import jcl.jabber as jabber
|
import jcl.jabber as jabber
|
||||||
@@ -68,10 +69,10 @@ class SetRegisterHandler(object):
|
|||||||
return self.handle_error(\
|
return self.handle_error(\
|
||||||
MandatoryFieldError("name"),
|
MandatoryFieldError("name"),
|
||||||
info_query, lang_class)
|
info_query, lang_class)
|
||||||
if not self.field_name_regexp.match(form["name"].value):
|
if pyxmpp.jid.node_invalid_re.search(form["name"].value):
|
||||||
return self.handle_error(\
|
return self.handle_error(\
|
||||||
NotWellFormedFieldError("name",
|
NotWellFormedFieldError("name",
|
||||||
lang_class.arobase_in_name_forbidden),
|
lang_class.forbidden_char_in_name),
|
||||||
info_query, lang_class)
|
info_query, lang_class)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -248,6 +248,20 @@ class CommandManager_TestCase(unittest.TestCase):
|
|||||||
"execute")
|
"execute")
|
||||||
self.assertEquals(result, [])
|
self.assertEquals(result, [])
|
||||||
|
|
||||||
|
def test_complete_admin_command_action_as_admin(self):
|
||||||
|
self.command_manager.commands["command1"] = (True,
|
||||||
|
command.root_node_re)
|
||||||
|
self.command_manager.apply_execute_command = \
|
||||||
|
lambda iq, command_name: []
|
||||||
|
self.command_manager.component = MockComponent()
|
||||||
|
info_query = Iq(stanza_type="set",
|
||||||
|
from_jid="admin@test.com",
|
||||||
|
to_jid="jcl.test.com")
|
||||||
|
result = self.command_manager.apply_command_action(info_query,
|
||||||
|
"command1",
|
||||||
|
"complete")
|
||||||
|
self.assertEquals(result, [])
|
||||||
|
|
||||||
def test_apply_admin_command_action_as_admin_fulljid(self):
|
def test_apply_admin_command_action_as_admin_fulljid(self):
|
||||||
self.command_manager.commands["command1"] = (True,
|
self.command_manager.commands["command1"] = (True,
|
||||||
command.root_node_re)
|
command.root_node_re)
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ from jcl.tests import JCLTestCase
|
|||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class MockStream(object):
|
class MockStream(object):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
jid="",
|
jid="",
|
||||||
@@ -120,6 +121,7 @@ class MockStream(object):
|
|||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MockStreamNoConnect(MockStream):
|
class MockStreamNoConnect(MockStream):
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.connection_started = True
|
self.connection_started = True
|
||||||
@@ -127,14 +129,17 @@ class MockStreamNoConnect(MockStream):
|
|||||||
def loop_iter(self, timeout):
|
def loop_iter(self, timeout):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
class MockStreamRaiseException(MockStream):
|
class MockStreamRaiseException(MockStream):
|
||||||
def loop_iter(self, timeout):
|
def loop_iter(self, timeout):
|
||||||
raise Exception("in loop error")
|
raise Exception("in loop error")
|
||||||
|
|
||||||
|
|
||||||
class LangExample(Lang):
|
class LangExample(Lang):
|
||||||
class en(Lang.en):
|
class en(Lang.en):
|
||||||
type_example_name = "Type Example"
|
type_example_name = "Type Example"
|
||||||
|
|
||||||
|
|
||||||
class TestSubscribeHandler(DefaultSubscribeHandler):
|
class TestSubscribeHandler(DefaultSubscribeHandler):
|
||||||
def filter(self, message, lang_class):
|
def filter(self, message, lang_class):
|
||||||
if re.compile(".*%.*").match(message.get_to().node):
|
if re.compile(".*%.*").match(message.get_to().node):
|
||||||
@@ -143,10 +148,12 @@ class TestSubscribeHandler(DefaultSubscribeHandler):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class ErrorHandler(Handler):
|
class ErrorHandler(Handler):
|
||||||
def filter(self, stanza, lang_class):
|
def filter(self, stanza, lang_class):
|
||||||
raise Exception("test error")
|
raise Exception("test error")
|
||||||
|
|
||||||
|
|
||||||
class TestUnsubscribeHandler(DefaultUnsubscribeHandler):
|
class TestUnsubscribeHandler(DefaultUnsubscribeHandler):
|
||||||
def filter(self, message, lang_class):
|
def filter(self, message, lang_class):
|
||||||
if re.compile(".*%.*").match(message.get_to().node):
|
if re.compile(".*%.*").match(message.get_to().node):
|
||||||
@@ -155,6 +162,7 @@ class TestUnsubscribeHandler(DefaultUnsubscribeHandler):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class HandlerMock(object):
|
class HandlerMock(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.handled = []
|
self.handled = []
|
||||||
@@ -166,6 +174,7 @@ class HandlerMock(object):
|
|||||||
self.handled.append((stanza, lang_class, data))
|
self.handled.append((stanza, lang_class, data))
|
||||||
return [(stanza, lang_class, data)]
|
return [(stanza, lang_class, data)]
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_TestCase(JCLTestCase):
|
class JCLComponent_TestCase(JCLTestCase):
|
||||||
def _handle_tick_test_time_handler(self):
|
def _handle_tick_test_time_handler(self):
|
||||||
self.max_tick_count -= 1
|
self.max_tick_count -= 1
|
||||||
@@ -184,6 +193,7 @@ class JCLComponent_TestCase(JCLTestCase):
|
|||||||
self.comp.time_unit = 0
|
self.comp.time_unit = 0
|
||||||
self.saved_time_handler = None
|
self.saved_time_handler = None
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_constructor_TestCase(JCLComponent_TestCase):
|
class JCLComponent_constructor_TestCase(JCLComponent_TestCase):
|
||||||
"""Constructor tests"""
|
"""Constructor tests"""
|
||||||
|
|
||||||
@@ -192,6 +202,7 @@ class JCLComponent_constructor_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertTrue(Account._connection.tableExists("account"))
|
self.assertTrue(Account._connection.tableExists("account"))
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
|
class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
|
||||||
"""apply_registered_behavior tests"""
|
"""apply_registered_behavior tests"""
|
||||||
|
|
||||||
@@ -200,7 +211,8 @@ class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
|
|||||||
self.comp.stream_class = MockStreamNoConnect
|
self.comp.stream_class = MockStreamNoConnect
|
||||||
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")
|
||||||
result = self.comp.apply_registered_behavior([[ErrorHandler(None)]], message)
|
result = self.comp.apply_registered_behavior([[ErrorHandler(None)]],
|
||||||
|
message)
|
||||||
self.assertEquals(len(result), 1)
|
self.assertEquals(len(result), 1)
|
||||||
self.assertEquals(result[0].get_type(), "error")
|
self.assertEquals(result[0].get_type(), "error")
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(self.comp.stream.sent), 1)
|
||||||
@@ -272,6 +284,7 @@ class JCLComponent_apply_registered_behavior_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(len(handler1.handled), 1)
|
self.assertEquals(len(handler1.handled), 1)
|
||||||
self.assertEquals(len(handler2.handled), 0)
|
self.assertEquals(len(handler2.handled), 0)
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_time_handler_TestCase(JCLComponent_TestCase):
|
class JCLComponent_time_handler_TestCase(JCLComponent_TestCase):
|
||||||
"""time_handler' tests"""
|
"""time_handler' tests"""
|
||||||
|
|
||||||
@@ -285,6 +298,7 @@ class JCLComponent_time_handler_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(self.max_tick_count, 0)
|
self.assertEquals(self.max_tick_count, 0)
|
||||||
self.assertFalse(self.comp.running)
|
self.assertFalse(self.comp.running)
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_authenticated_handler_TestCase(JCLComponent_TestCase):
|
class JCLComponent_authenticated_handler_TestCase(JCLComponent_TestCase):
|
||||||
"""authenticated handler' tests"""
|
"""authenticated handler' tests"""
|
||||||
|
|
||||||
@@ -335,6 +349,7 @@ class JCLComponent_authenticated_handler_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(presence.get_to(), "test2@test.com")
|
self.assertEquals(presence.get_to(), "test2@test.com")
|
||||||
self.assertEquals(presence.get_node().prop("type"), "probe")
|
self.assertEquals(presence.get_node().prop("type"), "probe")
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_signal_handler_TestCase(JCLComponent_TestCase):
|
class JCLComponent_signal_handler_TestCase(JCLComponent_TestCase):
|
||||||
"""signal_handler' tests"""
|
"""signal_handler' tests"""
|
||||||
|
|
||||||
@@ -343,6 +358,7 @@ class JCLComponent_signal_handler_TestCase(JCLComponent_TestCase):
|
|||||||
self.comp.signal_handler(42, None)
|
self.comp.signal_handler(42, None)
|
||||||
self.assertFalse(self.comp.running)
|
self.assertFalse(self.comp.running)
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_handle_get_gateway_TestCase(JCLComponent_TestCase):
|
class JCLComponent_handle_get_gateway_TestCase(JCLComponent_TestCase):
|
||||||
"""handle_get_gateway' tests"""
|
"""handle_get_gateway' tests"""
|
||||||
|
|
||||||
@@ -352,9 +368,9 @@ class JCLComponent_handle_get_gateway_TestCase(JCLComponent_TestCase):
|
|||||||
info_query = Iq(stanza_type="get",
|
info_query = Iq(stanza_type="get",
|
||||||
from_jid="user1@test.com")
|
from_jid="user1@test.com")
|
||||||
info_query.new_query("jabber:iq:gateway")
|
info_query.new_query("jabber:iq:gateway")
|
||||||
self.comp.handle_get_gateway(info_query)
|
iqs_sent = self.comp.handle_get_gateway(info_query)
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(iqs_sent), 1)
|
||||||
iq_sent = self.comp.stream.sent[0]
|
iq_sent = iqs_sent[0]
|
||||||
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
||||||
self.assertEquals(len(iq_sent.xpath_eval("*/*")), 2)
|
self.assertEquals(len(iq_sent.xpath_eval("*/*")), 2)
|
||||||
desc_nodes = iq_sent.xpath_eval("jig:query/jig:desc",
|
desc_nodes = iq_sent.xpath_eval("jig:query/jig:desc",
|
||||||
@@ -366,6 +382,7 @@ class JCLComponent_handle_get_gateway_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(len(prompt_nodes), 1)
|
self.assertEquals(len(prompt_nodes), 1)
|
||||||
self.assertEquals(prompt_nodes[0].content, Lang.en.get_gateway_prompt)
|
self.assertEquals(prompt_nodes[0].content, Lang.en.get_gateway_prompt)
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_handle_set_gateway_TestCase(JCLComponent_TestCase):
|
class JCLComponent_handle_set_gateway_TestCase(JCLComponent_TestCase):
|
||||||
"""handle_set_gateway' tests"""
|
"""handle_set_gateway' tests"""
|
||||||
|
|
||||||
@@ -377,9 +394,9 @@ class JCLComponent_handle_set_gateway_TestCase(JCLComponent_TestCase):
|
|||||||
query = info_query.new_query("jabber:iq:gateway")
|
query = info_query.new_query("jabber:iq:gateway")
|
||||||
prompt = query.newChild(None, "prompt", None)
|
prompt = query.newChild(None, "prompt", None)
|
||||||
prompt.addContent("user@test.com")
|
prompt.addContent("user@test.com")
|
||||||
self.comp.handle_set_gateway(info_query)
|
iqs_sent = self.comp.handle_set_gateway(info_query)
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(iqs_sent), 1)
|
||||||
iq_sent = self.comp.stream.sent[0]
|
iq_sent = iqs_sent[0]
|
||||||
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
||||||
self.assertEquals(len(iq_sent.xpath_eval("*/*")), 2)
|
self.assertEquals(len(iq_sent.xpath_eval("*/*")), 2)
|
||||||
jid_nodes = iq_sent.xpath_eval("jig:query/jig:jid",
|
jid_nodes = iq_sent.xpath_eval("jig:query/jig:jid",
|
||||||
@@ -387,6 +404,7 @@ class JCLComponent_handle_set_gateway_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(len(jid_nodes), 1)
|
self.assertEquals(len(jid_nodes), 1)
|
||||||
self.assertEquals(jid_nodes[0].content, "user%test.com@jcl.test.com")
|
self.assertEquals(jid_nodes[0].content, "user%test.com@jcl.test.com")
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_disco_get_info_TestCase(JCLComponent_TestCase):
|
class JCLComponent_disco_get_info_TestCase(JCLComponent_TestCase):
|
||||||
"""disco_get_info' tests"""
|
"""disco_get_info' tests"""
|
||||||
|
|
||||||
@@ -399,14 +417,16 @@ class JCLComponent_disco_get_info_TestCase(JCLComponent_TestCase):
|
|||||||
disco_info = self.comp.disco_get_info(None, info_query)
|
disco_info = self.comp.disco_get_info(None, info_query)
|
||||||
self.assertEquals(disco_info.get_node(), None)
|
self.assertEquals(disco_info.get_node(), None)
|
||||||
self.assertEquals(len(self.comp.stream.sent), 0)
|
self.assertEquals(len(self.comp.stream.sent), 0)
|
||||||
self.assertEquals(disco_info.get_identities()[0].get_name(), self.comp.name)
|
self.assertEquals(disco_info.get_identities()[0].get_name(),
|
||||||
|
self.comp.name)
|
||||||
self.assertTrue(disco_info.has_feature("jabber:iq:version"))
|
self.assertTrue(disco_info.has_feature("jabber:iq:version"))
|
||||||
self.assertTrue(disco_info.has_feature(vcard.VCARD_NS))
|
self.assertTrue(disco_info.has_feature(vcard.VCARD_NS))
|
||||||
self.assertTrue(disco_info.has_feature("jabber:iq:last"))
|
self.assertTrue(disco_info.has_feature("jabber:iq:last"))
|
||||||
self.assertTrue(disco_info.has_feature("jabber:iq:register"))
|
self.assertTrue(disco_info.has_feature("jabber:iq:register"))
|
||||||
|
|
||||||
def test_disco_get_info_multiple_account_type(self):
|
def test_disco_get_info_multiple_account_type(self):
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
|
Example2Account)
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
info_query = Iq(stanza_type="get",
|
info_query = Iq(stanza_type="get",
|
||||||
@@ -436,7 +456,8 @@ class JCLComponent_disco_get_info_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertTrue(disco_info.has_feature("jabber:iq:register"))
|
self.assertTrue(disco_info.has_feature("jabber:iq:register"))
|
||||||
|
|
||||||
def test_disco_get_info_long_node(self):
|
def test_disco_get_info_long_node(self):
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
|
Example2Account)
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
info_query = Iq(stanza_type="get",
|
info_query = Iq(stanza_type="get",
|
||||||
@@ -479,6 +500,7 @@ class JCLComponent_disco_get_info_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(disco_info.get_identities()[0].get_name(),
|
self.assertEquals(disco_info.get_identities()[0].get_name(),
|
||||||
Lang.en.command_get_disabled_users_num)
|
Lang.en.command_get_disabled_users_num)
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_disco_get_items_TestCase(JCLComponent_TestCase):
|
class JCLComponent_disco_get_items_TestCase(JCLComponent_TestCase):
|
||||||
"""disco_get_items' tests"""
|
"""disco_get_items' tests"""
|
||||||
|
|
||||||
@@ -512,7 +534,8 @@ class JCLComponent_disco_get_items_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(disco_items, None)
|
self.assertEquals(disco_items, None)
|
||||||
|
|
||||||
def test_disco_get_items_unknown_node_multiple_account_types(self):
|
def test_disco_get_items_unknown_node_multiple_account_types(self):
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
|
Example2Account)
|
||||||
user1 = User(jid="user1@test.com")
|
user1 = User(jid="user1@test.com")
|
||||||
account11 = ExampleAccount(user=user1,
|
account11 = ExampleAccount(user=user1,
|
||||||
name="account11",
|
name="account11",
|
||||||
@@ -541,7 +564,8 @@ class JCLComponent_disco_get_items_TestCase(JCLComponent_TestCase):
|
|||||||
def test_disco_get_items_2types_no_node(self):
|
def test_disco_get_items_2types_no_node(self):
|
||||||
"""get_items on main entity. Must account types"""
|
"""get_items on main entity. Must account types"""
|
||||||
self.comp.lang = LangExample()
|
self.comp.lang = LangExample()
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
|
Example2Account)
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
user1 = User(jid="user1@test.com")
|
user1 = User(jid="user1@test.com")
|
||||||
@@ -575,7 +599,8 @@ class JCLComponent_disco_get_items_TestCase(JCLComponent_TestCase):
|
|||||||
def test_disco_get_items_2types_with_node(self):
|
def test_disco_get_items_2types_with_node(self):
|
||||||
"""get_items on the first account type node. Must return account list of
|
"""get_items on the first account type node. Must return account list of
|
||||||
that type for the current user"""
|
that type for the current user"""
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
|
Example2Account)
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
user1 = User(jid="user1@test.com")
|
user1 = User(jid="user1@test.com")
|
||||||
@@ -599,14 +624,16 @@ class JCLComponent_disco_get_items_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(disco_items.get_node(), "Example")
|
self.assertEquals(disco_items.get_node(), "Example")
|
||||||
self.assertEquals(len(disco_items.get_items()), 1)
|
self.assertEquals(len(disco_items.get_items()), 1)
|
||||||
disco_item = disco_items.get_items()[0]
|
disco_item = disco_items.get_items()[0]
|
||||||
self.assertEquals(unicode(disco_item.get_jid()), unicode(account11.jid) + "/Example")
|
self.assertEquals(unicode(disco_item.get_jid()),
|
||||||
|
unicode(account11.jid) + "/Example")
|
||||||
self.assertEquals(disco_item.get_node(), "Example/" + account11.name)
|
self.assertEquals(disco_item.get_node(), "Example/" + account11.name)
|
||||||
self.assertEquals(disco_item.get_name(), account11.long_name)
|
self.assertEquals(disco_item.get_name(), account11.long_name)
|
||||||
|
|
||||||
def test_disco_get_items_2types_with_node2(self):
|
def test_disco_get_items_2types_with_node2(self):
|
||||||
"""get_items on the second account type node. Must return account list of
|
"""get_items on the second account type node. Must return account list
|
||||||
that type for the current user"""
|
of that type for the current user"""
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
|
Example2Account)
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
user1 = User(jid="user1@test.com")
|
user1 = User(jid="user1@test.com")
|
||||||
@@ -636,7 +663,8 @@ class JCLComponent_disco_get_items_TestCase(JCLComponent_TestCase):
|
|||||||
|
|
||||||
def test_disco_get_items_2types_with_long_node(self):
|
def test_disco_get_items_2types_with_long_node(self):
|
||||||
"""get_items on a first type account. Must return nothing"""
|
"""get_items on a first type account. Must return nothing"""
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
|
Example2Account)
|
||||||
account1 = ExampleAccount(user=User(jid="user1@test.com"),
|
account1 = ExampleAccount(user=User(jid="user1@test.com"),
|
||||||
name="account1",
|
name="account1",
|
||||||
jid="account1@jcl.test.com")
|
jid="account1@jcl.test.com")
|
||||||
@@ -648,7 +676,8 @@ class JCLComponent_disco_get_items_TestCase(JCLComponent_TestCase):
|
|||||||
|
|
||||||
def test_disco_get_items_2types_with_long_node2(self):
|
def test_disco_get_items_2types_with_long_node2(self):
|
||||||
"""get_items on a second type account. Must return nothing"""
|
"""get_items on a second type account. Must return nothing"""
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
|
Example2Account)
|
||||||
account1 = Example2Account(user=User(jid="user1@test.com"),
|
account1 = Example2Account(user=User(jid="user1@test.com"),
|
||||||
name="account1",
|
name="account1",
|
||||||
jid="account1@jcl.test.com")
|
jid="account1@jcl.test.com")
|
||||||
@@ -681,16 +710,17 @@ class JCLComponent_disco_get_items_TestCase(JCLComponent_TestCase):
|
|||||||
"http://jabber.org/protocol/commands")
|
"http://jabber.org/protocol/commands")
|
||||||
self.assertEquals(len(disco_items.get_items()), 22)
|
self.assertEquals(len(disco_items.get_items()), 22)
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_handle_get_version_TestCase(JCLComponent_TestCase):
|
class JCLComponent_handle_get_version_TestCase(JCLComponent_TestCase):
|
||||||
"""handle_get_version' tests"""
|
"""handle_get_version' tests"""
|
||||||
|
|
||||||
def test_handle_get_version(self):
|
def test_handle_get_version(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.handle_get_version(Iq(stanza_type = "get", \
|
iqs_sent = self.comp.handle_get_version(Iq(stanza_type = "get", \
|
||||||
from_jid = "user1@test.com"))
|
from_jid = "user1@test.com"))
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(iqs_sent), 1)
|
||||||
iq_sent = self.comp.stream.sent[0]
|
iq_sent = iqs_sent[0]
|
||||||
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
||||||
self.assertEquals(len(iq_sent.xpath_eval("*/*")), 2)
|
self.assertEquals(len(iq_sent.xpath_eval("*/*")), 2)
|
||||||
name_nodes = iq_sent.xpath_eval("jiv:query/jiv:name", \
|
name_nodes = iq_sent.xpath_eval("jiv:query/jiv:name", \
|
||||||
@@ -702,17 +732,18 @@ class JCLComponent_handle_get_version_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(len(version_nodes), 1)
|
self.assertEquals(len(version_nodes), 1)
|
||||||
self.assertEquals(version_nodes[0].content, self.comp.version)
|
self.assertEquals(version_nodes[0].content, self.comp.version)
|
||||||
|
|
||||||
|
|
||||||
class JCLComponent_handle_get_register_TestCase(JCLComponent_TestCase):
|
class JCLComponent_handle_get_register_TestCase(JCLComponent_TestCase):
|
||||||
"""handle_get_register' tests"""
|
"""handle_get_register' tests"""
|
||||||
|
|
||||||
def test_handle_get_register_new(self):
|
def test_handle_get_register_new(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.handle_get_register(Iq(stanza_type = "get", \
|
iqs_sent = self.comp.handle_get_register(Iq(stanza_type = "get", \
|
||||||
from_jid = "user1@test.com", \
|
from_jid = "user1@test.com", \
|
||||||
to_jid = "jcl.test.com"))
|
to_jid = "jcl.test.com"))
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(iqs_sent), 1)
|
||||||
iq_sent = self.comp.stream.sent[0]
|
iq_sent = iqs_sent[0]
|
||||||
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
||||||
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title", \
|
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title", \
|
||||||
{"jir": "jabber:iq:register", \
|
{"jir": "jabber:iq:register", \
|
||||||
@@ -735,9 +766,9 @@ class JCLComponent_handle_get_register_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(fields[0].prop("label"), Lang.en.account_name)
|
self.assertEquals(fields[0].prop("label"), Lang.en.account_name)
|
||||||
self.assertEquals(fields[0].children.name, "required")
|
self.assertEquals(fields[0].children.name, "required")
|
||||||
|
|
||||||
def __check_get_register_new_type(self):
|
def __check_get_register_new_type(self, iqs_sent):
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(iqs_sent), 1)
|
||||||
iq_sent = self.comp.stream.sent[0]
|
iq_sent = iqs_sent[0]
|
||||||
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
||||||
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title", \
|
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title", \
|
||||||
{"jir": "jabber:iq:register", \
|
{"jir": "jabber:iq:register", \
|
||||||
@@ -798,10 +829,10 @@ class JCLComponent_handle_get_register_TestCase(JCLComponent_TestCase):
|
|||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount,)
|
self.comp.account_manager.account_classes = (ExampleAccount,)
|
||||||
self.comp.handle_get_register(Iq(stanza_type = "get", \
|
iqs_sent = self.comp.handle_get_register(Iq(stanza_type = "get", \
|
||||||
from_jid = "user1@test.com", \
|
from_jid = "user1@test.com", \
|
||||||
to_jid = "jcl.test.com"))
|
to_jid = "jcl.test.com"))
|
||||||
self.__check_get_register_new_type()
|
self.__check_get_register_new_type(iqs_sent)
|
||||||
|
|
||||||
def test_handle_get_register_exist(self):
|
def test_handle_get_register_exist(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
@@ -818,11 +849,11 @@ class JCLComponent_handle_get_register_TestCase(JCLComponent_TestCase):
|
|||||||
name="account21",
|
name="account21",
|
||||||
jid="account21@jcl.test.com")
|
jid="account21@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_get_register(Iq(stanza_type="get",
|
iqs_sent = self.comp.handle_get_register(Iq(stanza_type="get",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(iqs_sent), 1)
|
||||||
iq_sent = self.comp.stream.sent[0]
|
iq_sent = iqs_sent[0]
|
||||||
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
||||||
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title",
|
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title",
|
||||||
{"jir": "jabber:iq:register",
|
{"jir": "jabber:iq:register",
|
||||||
@@ -880,11 +911,11 @@ class JCLComponent_handle_get_register_TestCase(JCLComponent_TestCase):
|
|||||||
test_enum="choice1",
|
test_enum="choice1",
|
||||||
test_int=21)
|
test_int=21)
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_get_register(Iq(stanza_type="get",
|
iqs_sent = self.comp.handle_get_register(Iq(stanza_type="get",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="account1@jcl.test.com"))
|
to_jid="account1@jcl.test.com"))
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(iqs_sent), 1)
|
||||||
iq_sent = self.comp.stream.sent[0]
|
iq_sent = iqs_sent[0]
|
||||||
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
||||||
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title",
|
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title",
|
||||||
{"jir": "jabber:iq:register",
|
{"jir": "jabber:iq:register",
|
||||||
@@ -958,21 +989,23 @@ class JCLComponent_handle_get_register_TestCase(JCLComponent_TestCase):
|
|||||||
def test_handle_get_register_new_type1(self):
|
def test_handle_get_register_new_type1(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
self.comp.handle_get_register(Iq(stanza_type="get",
|
Example2Account)
|
||||||
|
iqs_sent = self.comp.handle_get_register(Iq(stanza_type="get",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="jcl.test.com/example"))
|
to_jid="jcl.test.com/example"))
|
||||||
self.__check_get_register_new_type()
|
self.__check_get_register_new_type(iqs_sent)
|
||||||
|
|
||||||
def test_handle_get_register_new_type2(self):
|
def test_handle_get_register_new_type2(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.account_manager.account_classes = (ExampleAccount, Example2Account)
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
self.comp.handle_get_register(Iq(stanza_type="get",
|
Example2Account)
|
||||||
|
iqs_sent = self.comp.handle_get_register(Iq(stanza_type="get",
|
||||||
from_jid=JID("user1@test.com"),
|
from_jid=JID("user1@test.com"),
|
||||||
to_jid=JID("jcl.test.com/example2")))
|
to_jid=JID("jcl.test.com/example2")))
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(iqs_sent), 1)
|
||||||
iq_sent = self.comp.stream.sent[0]
|
iq_sent = iqs_sent[0]
|
||||||
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
||||||
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title",
|
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title",
|
||||||
{"jir": "jabber:iq:register",
|
{"jir": "jabber:iq:register",
|
||||||
@@ -1014,7 +1047,7 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
to_jid="jcl.test.com")
|
to_jid="jcl.test.com")
|
||||||
query = iq_set.new_query("jabber:iq:register")
|
query = iq_set.new_query("jabber:iq:register")
|
||||||
x_data.as_xml(query, None)
|
x_data.as_xml(query, None)
|
||||||
self.comp.handle_set_register(iq_set)
|
stanza_sent = self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
_account = account.get_account("user1@test.com", "account1")
|
_account = account.get_account("user1@test.com", "account1")
|
||||||
@@ -1024,7 +1057,6 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
stanza_sent = self.comp.stream.sent
|
|
||||||
self.assertEquals(len(stanza_sent), 4)
|
self.assertEquals(len(stanza_sent), 4)
|
||||||
iq_result = stanza_sent[0]
|
iq_result = stanza_sent[0]
|
||||||
self.assertTrue(isinstance(iq_result, Iq))
|
self.assertTrue(isinstance(iq_result, Iq))
|
||||||
@@ -1075,7 +1107,7 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
to_jid="jcl.test.com")
|
to_jid="jcl.test.com")
|
||||||
query = iq_set.new_query("jabber:iq:register")
|
query = iq_set.new_query("jabber:iq:register")
|
||||||
x_data.as_xml(query, None)
|
x_data.as_xml(query, None)
|
||||||
self.comp.handle_set_register(iq_set)
|
stanza_sent = self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
_account = account.get_account("user1@test.com", "account1")
|
_account = account.get_account("user1@test.com", "account1")
|
||||||
@@ -1085,7 +1117,6 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
stanza_sent = self.comp.stream.sent
|
|
||||||
self.assertEquals(len(stanza_sent), 5)
|
self.assertEquals(len(stanza_sent), 5)
|
||||||
iq_result = stanza_sent[0]
|
iq_result = stanza_sent[0]
|
||||||
self.assertTrue(isinstance(iq_result, Iq))
|
self.assertTrue(isinstance(iq_result, Iq))
|
||||||
@@ -1139,7 +1170,7 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
to_jid="jcl.test.com/Example2")
|
to_jid="jcl.test.com/Example2")
|
||||||
query = iq_set.new_query("jabber:iq:register")
|
query = iq_set.new_query("jabber:iq:register")
|
||||||
x_data.as_xml(query, None)
|
x_data.as_xml(query, None)
|
||||||
self.comp.handle_set_register(iq_set)
|
stanza_sent = self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
_account = account.get_account("user1@test.com", "account1")
|
_account = account.get_account("user1@test.com", "account1")
|
||||||
@@ -1149,7 +1180,6 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
stanza_sent = self.comp.stream.sent
|
|
||||||
self.assertEquals(len(stanza_sent), 4)
|
self.assertEquals(len(stanza_sent), 4)
|
||||||
iq_result = stanza_sent[0]
|
iq_result = stanza_sent[0]
|
||||||
self.assertTrue(isinstance(iq_result, Iq))
|
self.assertTrue(isinstance(iq_result, Iq))
|
||||||
@@ -1208,7 +1238,7 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
to_jid="jcl.test.com")
|
to_jid="jcl.test.com")
|
||||||
query = iq_set.new_query("jabber:iq:register")
|
query = iq_set.new_query("jabber:iq:register")
|
||||||
x_data.as_xml(query, None)
|
x_data.as_xml(query, None)
|
||||||
self.comp.handle_set_register(iq_set)
|
stanza_sent = self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
_account = account.get_account("user1@test.com", "account1")
|
_account = account.get_account("user1@test.com", "account1")
|
||||||
@@ -1223,7 +1253,6 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(_account.test_int, 43)
|
self.assertEquals(_account.test_int, 43)
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
stanza_sent = self.comp.stream.sent
|
|
||||||
self.assertEquals(len(stanza_sent), 4)
|
self.assertEquals(len(stanza_sent), 4)
|
||||||
iq_result = stanza_sent[0]
|
iq_result = stanza_sent[0]
|
||||||
self.assertTrue(isinstance(iq_result, Iq))
|
self.assertTrue(isinstance(iq_result, Iq))
|
||||||
@@ -1355,14 +1384,13 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
to_jid="jcl.test.com")
|
to_jid="jcl.test.com")
|
||||||
query = iq_set.new_query("jabber:iq:register")
|
query = iq_set.new_query("jabber:iq:register")
|
||||||
x_data.as_xml(query)
|
x_data.as_xml(query)
|
||||||
self.comp.handle_set_register(iq_set)
|
stanza_sent = self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
_account = account.get_account("user1@test.com", "account1")
|
_account = account.get_account("user1@test.com", "account1")
|
||||||
self.assertEquals(_account, None)
|
self.assertEquals(_account, None)
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
stanza_sent = self.comp.stream.sent
|
|
||||||
self.assertEquals(len(stanza_sent), 1)
|
self.assertEquals(len(stanza_sent), 1)
|
||||||
self.assertTrue(isinstance(stanza_sent[0], Iq))
|
self.assertTrue(isinstance(stanza_sent[0], Iq))
|
||||||
self.assertEquals(stanza_sent[0].get_node().prop("type"), "error")
|
self.assertEquals(stanza_sent[0].get_node().prop("type"), "error")
|
||||||
@@ -1386,14 +1414,13 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
to_jid="jcl.test.com")
|
to_jid="jcl.test.com")
|
||||||
query = iq_set.new_query("jabber:iq:register")
|
query = iq_set.new_query("jabber:iq:register")
|
||||||
x_data.as_xml(query)
|
x_data.as_xml(query)
|
||||||
self.comp.handle_set_register(iq_set)
|
stanza_sent = self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
_account = account.get_account("user1@test.com", "account1")
|
_account = account.get_account("user1@test.com", "account1")
|
||||||
self.assertEquals(_account, None)
|
self.assertEquals(_account, None)
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
stanza_sent = self.comp.stream.sent
|
|
||||||
self.assertEquals(len(stanza_sent), 1)
|
self.assertEquals(len(stanza_sent), 1)
|
||||||
self.assertTrue(isinstance(stanza_sent[0], Iq))
|
self.assertTrue(isinstance(stanza_sent[0], Iq))
|
||||||
self.assertEquals(stanza_sent[0].get_node().prop("type"), "error")
|
self.assertEquals(stanza_sent[0].get_node().prop("type"), "error")
|
||||||
@@ -1416,7 +1443,7 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
to_jid="account1@jcl.test.com")
|
to_jid="account1@jcl.test.com")
|
||||||
query = iq_set.new_query("jabber:iq:register")
|
query = iq_set.new_query("jabber:iq:register")
|
||||||
x_data.as_xml(query, None)
|
x_data.as_xml(query, None)
|
||||||
self.comp.handle_set_register(iq_set)
|
stanza_sent = self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
_account = account.get_account("user1@test.com", "account1")
|
_account = account.get_account("user1@test.com", "account1")
|
||||||
@@ -1426,7 +1453,6 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
stanza_sent = self.comp.stream.sent
|
|
||||||
self.assertEquals(len(stanza_sent), 4)
|
self.assertEquals(len(stanza_sent), 4)
|
||||||
iq_result = stanza_sent[0]
|
iq_result = stanza_sent[0]
|
||||||
self.assertTrue(isinstance(iq_result, Iq))
|
self.assertTrue(isinstance(iq_result, Iq))
|
||||||
@@ -1504,7 +1530,7 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
to_jid="account1@jcl.test.com/Example")
|
to_jid="account1@jcl.test.com/Example")
|
||||||
query = iq_set.new_query("jabber:iq:register")
|
query = iq_set.new_query("jabber:iq:register")
|
||||||
x_data.as_xml(query)
|
x_data.as_xml(query)
|
||||||
self.comp.handle_set_register(iq_set)
|
stanza_sent = self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
_account = account.get_account("user1@test.com", "account1")
|
_account = account.get_account("user1@test.com", "account1")
|
||||||
@@ -1520,7 +1546,6 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(_account.test_int, 43)
|
self.assertEquals(_account.test_int, 43)
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
stanza_sent = self.comp.stream.sent
|
|
||||||
self.assertEquals(len(stanza_sent), 2)
|
self.assertEquals(len(stanza_sent), 2)
|
||||||
iq_result = stanza_sent[0]
|
iq_result = stanza_sent[0]
|
||||||
self.assertTrue(isinstance(iq_result, Iq))
|
self.assertTrue(isinstance(iq_result, Iq))
|
||||||
@@ -1557,7 +1582,7 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
to_jid="jcl.test.com")
|
to_jid="jcl.test.com")
|
||||||
query = iq_set.new_query("jabber:iq:register")
|
query = iq_set.new_query("jabber:iq:register")
|
||||||
query.newChild(None, "remove", None)
|
query.newChild(None, "remove", None)
|
||||||
self.comp.handle_set_register(iq_set)
|
stanza_sent = self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
self.assertEquals(account.get_accounts_count("user1@test.com"),
|
self.assertEquals(account.get_accounts_count("user1@test.com"),
|
||||||
@@ -1574,7 +1599,6 @@ class JCLComponent_handle_set_register_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
self.assertEquals(_account.jid, "account1@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
|
|
||||||
stanza_sent = self.comp.stream.sent
|
|
||||||
self.assertEquals(len(stanza_sent), 6)
|
self.assertEquals(len(stanza_sent), 6)
|
||||||
presence = stanza_sent[0]
|
presence = stanza_sent[0]
|
||||||
self.assertTrue(isinstance(presence, Presence))
|
self.assertTrue(isinstance(presence, Presence))
|
||||||
@@ -1623,11 +1647,10 @@ class JCLComponent_handle_presence_available_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_available(Presence(\
|
presence_sent = self.comp.handle_presence_available(Presence(\
|
||||||
stanza_type="available",
|
stanza_type="available",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="jcl.test.com"))
|
to_jid="jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 3)
|
self.assertEqual(len(presence_sent), 3)
|
||||||
self.assertEqual(len([presence
|
self.assertEqual(len([presence
|
||||||
for presence in presence_sent
|
for presence in presence_sent
|
||||||
@@ -1686,11 +1709,10 @@ class JCLComponent_handle_presence_available_TestCase(JCLComponent_TestCase):
|
|||||||
jid="u21%test.com@jcl.test.com",
|
jid="u21%test.com@jcl.test.com",
|
||||||
account=account2)
|
account=account2)
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_available(Presence(\
|
presence_sent = self.comp.handle_presence_available(Presence(\
|
||||||
stanza_type="available",
|
stanza_type="available",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="jcl.test.com"))
|
to_jid="jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 7)
|
self.assertEqual(len(presence_sent), 7)
|
||||||
self.assertEqual(len([presence
|
self.assertEqual(len([presence
|
||||||
for presence in presence_sent
|
for presence in presence_sent
|
||||||
@@ -1762,11 +1784,10 @@ class JCLComponent_handle_presence_available_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_available(Presence(\
|
presence_sent = self.comp.handle_presence_available(Presence(\
|
||||||
stanza_type="available",
|
stanza_type="available",
|
||||||
from_jid="unknown@test.com",
|
from_jid="unknown@test.com",
|
||||||
to_jid="jcl.test.com"))
|
to_jid="jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
|
|
||||||
def test_handle_presence_available_to_account(self):
|
def test_handle_presence_available_to_account(self):
|
||||||
@@ -1784,11 +1805,10 @@ class JCLComponent_handle_presence_available_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_available(Presence(\
|
presence_sent = self.comp.handle_presence_available(Presence(\
|
||||||
stanza_type="available",
|
stanza_type="available",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 1)
|
self.assertEqual(len(presence_sent), 1)
|
||||||
self.assertEqual(presence_sent[0].get_to(), "user1@test.com/resource")
|
self.assertEqual(presence_sent[0].get_to(), "user1@test.com/resource")
|
||||||
self.assertEqual(presence_sent[0].get_from(), "account11@jcl.test.com")
|
self.assertEqual(presence_sent[0].get_from(), "account11@jcl.test.com")
|
||||||
@@ -1811,11 +1831,10 @@ class JCLComponent_handle_presence_available_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_available(Presence(\
|
presence_sent = self.comp.handle_presence_available(Presence(\
|
||||||
stanza_type="available",
|
stanza_type="available",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="user1%test.com@jcl.test.com"))
|
to_jid="user1%test.com@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 1)
|
self.assertEqual(len(presence_sent), 1)
|
||||||
self.assertEqual(presence_sent[0].get_to(), "user1@test.com/resource")
|
self.assertEqual(presence_sent[0].get_to(), "user1@test.com/resource")
|
||||||
self.assertEqual(presence_sent[0].get_from(),
|
self.assertEqual(presence_sent[0].get_from(),
|
||||||
@@ -1838,11 +1857,10 @@ class JCLComponent_handle_presence_available_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_available(Presence(\
|
presence_sent = self.comp.handle_presence_available(Presence(\
|
||||||
stanza_type="available",
|
stanza_type="available",
|
||||||
from_jid="unknown@test.com",
|
from_jid="unknown@test.com",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
|
|
||||||
def test_handle_presence_available_to_unknown_account(self):
|
def test_handle_presence_available_to_unknown_account(self):
|
||||||
@@ -1860,11 +1878,10 @@ class JCLComponent_handle_presence_available_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_available(Presence(\
|
presence_sent = self.comp.handle_presence_available(Presence(\
|
||||||
stanza_type="available",
|
stanza_type="available",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="unknown@jcl.test.com"))
|
to_jid="unknown@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
|
|
||||||
def test_handle_presence_available_to_account_live_password(self):
|
def test_handle_presence_available_to_account_live_password(self):
|
||||||
@@ -1883,11 +1900,10 @@ class JCLComponent_handle_presence_available_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_available(Presence(\
|
messages_sent = self.comp.handle_presence_available(Presence(\
|
||||||
stanza_type="available",
|
stanza_type="available",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
messages_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(messages_sent), 1)
|
self.assertEqual(len(messages_sent), 1)
|
||||||
presence = messages_sent[0]
|
presence = messages_sent[0]
|
||||||
self.assertTrue(presence is not None)
|
self.assertTrue(presence is not None)
|
||||||
@@ -1912,11 +1928,10 @@ class JCLComponent_handle_presence_available_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_available(Presence(\
|
messages_sent = self.comp.handle_presence_available(Presence(\
|
||||||
stanza_type="available",
|
stanza_type="available",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
messages_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(messages_sent), 2)
|
self.assertEqual(len(messages_sent), 2)
|
||||||
password_message = None
|
password_message = None
|
||||||
presence = None
|
presence = None
|
||||||
@@ -1957,11 +1972,10 @@ class JCLComponent_handle_presence_unavailable_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unavailable(Presence(\
|
presence_sent = self.comp.handle_presence_unavailable(Presence(\
|
||||||
stanza_type="unavailable",
|
stanza_type="unavailable",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="jcl.test.com"))
|
to_jid="jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 3)
|
self.assertEqual(len(presence_sent), 3)
|
||||||
self.assertEqual(len([presence
|
self.assertEqual(len([presence
|
||||||
for presence in presence_sent
|
for presence in presence_sent
|
||||||
@@ -2023,11 +2037,10 @@ class JCLComponent_handle_presence_unavailable_TestCase(JCLComponent_TestCase):
|
|||||||
jid="u21%test.com@jcl.test.com",
|
jid="u21%test.com@jcl.test.com",
|
||||||
account=account2)
|
account=account2)
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unavailable(Presence(\
|
presence_sent = self.comp.handle_presence_unavailable(Presence(\
|
||||||
stanza_type="unavailable",
|
stanza_type="unavailable",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="jcl.test.com"))
|
to_jid="jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 7)
|
self.assertEqual(len(presence_sent), 7)
|
||||||
self.assertEqual(len([presence
|
self.assertEqual(len([presence
|
||||||
for presence in presence_sent
|
for presence in presence_sent
|
||||||
@@ -2099,11 +2112,10 @@ class JCLComponent_handle_presence_unavailable_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unavailable(Presence(\
|
presence_sent = self.comp.handle_presence_unavailable(Presence(\
|
||||||
stanza_type="unavailable",
|
stanza_type="unavailable",
|
||||||
from_jid="unknown@test.com",
|
from_jid="unknown@test.com",
|
||||||
to_jid="jcl.test.com"))
|
to_jid="jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
|
|
||||||
def test_handle_presence_unavailable_to_account(self):
|
def test_handle_presence_unavailable_to_account(self):
|
||||||
@@ -2121,11 +2133,10 @@ class JCLComponent_handle_presence_unavailable_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unavailable(Presence(\
|
presence_sent = self.comp.handle_presence_unavailable(Presence(\
|
||||||
stanza_type="unavailable",
|
stanza_type="unavailable",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 1)
|
self.assertEqual(len(presence_sent), 1)
|
||||||
self.assertEqual(presence_sent[0].get_to(), "user1@test.com/resource")
|
self.assertEqual(presence_sent[0].get_to(), "user1@test.com/resource")
|
||||||
self.assertEqual(presence_sent[0].get_from(), "account11@jcl.test.com")
|
self.assertEqual(presence_sent[0].get_from(), "account11@jcl.test.com")
|
||||||
@@ -2149,11 +2160,10 @@ class JCLComponent_handle_presence_unavailable_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unavailable(Presence(\
|
presence_sent = self.comp.handle_presence_unavailable(Presence(\
|
||||||
stanza_type="unavailable",
|
stanza_type="unavailable",
|
||||||
from_jid="user1@test.com/resource",
|
from_jid="user1@test.com/resource",
|
||||||
to_jid="user1%test.com@jcl.test.com"))
|
to_jid="user1%test.com@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 1)
|
self.assertEqual(len(presence_sent), 1)
|
||||||
self.assertEqual(presence_sent[0].get_to(), "user1@test.com/resource")
|
self.assertEqual(presence_sent[0].get_to(), "user1@test.com/resource")
|
||||||
self.assertEqual(presence_sent[0].get_from(),
|
self.assertEqual(presence_sent[0].get_from(),
|
||||||
@@ -2177,11 +2187,10 @@ class JCLComponent_handle_presence_unavailable_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unavailable(Presence(\
|
presence_sent = self.comp.handle_presence_unavailable(Presence(\
|
||||||
stanza_type="unavailable",
|
stanza_type="unavailable",
|
||||||
from_jid="unknown@test.com",
|
from_jid="unknown@test.com",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
|
|
||||||
def test_handle_presence_unavailable_to_unknown_account(self):
|
def test_handle_presence_unavailable_to_unknown_account(self):
|
||||||
@@ -2199,11 +2208,10 @@ class JCLComponent_handle_presence_unavailable_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unavailable(Presence(\
|
presence_sent = self.comp.handle_presence_unavailable(Presence(\
|
||||||
stanza_type="unavailable",
|
stanza_type="unavailable",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="unknown@jcl.test.com"))
|
to_jid="unknown@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
|
|
||||||
class JCLComponent_handle_presence_subscribe_TestCase(JCLComponent_TestCase):
|
class JCLComponent_handle_presence_subscribe_TestCase(JCLComponent_TestCase):
|
||||||
@@ -2222,11 +2230,10 @@ class JCLComponent_handle_presence_subscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_subscribe(Presence(\
|
presence_sent = self.comp.handle_presence_subscribe(Presence(\
|
||||||
stanza_type="subscribe",
|
stanza_type="subscribe",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="jcl.test.com"))
|
to_jid="jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 1)
|
self.assertEqual(len(presence_sent), 1)
|
||||||
self.assertEqual(presence_sent[0].get_to(), "user1@test.com")
|
self.assertEqual(presence_sent[0].get_to(), "user1@test.com")
|
||||||
self.assertEqual(presence_sent[0].get_from(), "jcl.test.com")
|
self.assertEqual(presence_sent[0].get_from(), "jcl.test.com")
|
||||||
@@ -2249,11 +2256,10 @@ class JCLComponent_handle_presence_subscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_subscribe(Presence(\
|
presence_sent = self.comp.handle_presence_subscribe(Presence(\
|
||||||
stanza_type="subscribe",
|
stanza_type="subscribe",
|
||||||
from_jid="unknown@test.com",
|
from_jid="unknown@test.com",
|
||||||
to_jid="jcl.test.com"))
|
to_jid="jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
|
|
||||||
def test_handle_presence_subscribe_to_account(self):
|
def test_handle_presence_subscribe_to_account(self):
|
||||||
@@ -2271,11 +2277,10 @@ class JCLComponent_handle_presence_subscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_subscribe(Presence(\
|
presence_sent = self.comp.handle_presence_subscribe(Presence(\
|
||||||
stanza_type="subscribe",
|
stanza_type="subscribe",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 1)
|
self.assertEqual(len(presence_sent), 1)
|
||||||
self.assertEqual(presence_sent[0].get_to(), "user1@test.com")
|
self.assertEqual(presence_sent[0].get_to(), "user1@test.com")
|
||||||
self.assertEqual(presence_sent[0].get_from(), "account11@jcl.test.com")
|
self.assertEqual(presence_sent[0].get_from(), "account11@jcl.test.com")
|
||||||
@@ -2298,11 +2303,10 @@ class JCLComponent_handle_presence_subscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_subscribe(Presence(\
|
presence_sent = self.comp.handle_presence_subscribe(Presence(\
|
||||||
stanza_type="subscribe",
|
stanza_type="subscribe",
|
||||||
from_jid="unknown@test.com",
|
from_jid="unknown@test.com",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
|
|
||||||
def test_handle_presence_subscribe_to_unknown_account(self):
|
def test_handle_presence_subscribe_to_unknown_account(self):
|
||||||
@@ -2320,11 +2324,10 @@ class JCLComponent_handle_presence_subscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_subscribe(Presence(\
|
presence_sent = self.comp.handle_presence_subscribe(Presence(\
|
||||||
stanza_type="subscribe",
|
stanza_type="subscribe",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="unknown@jcl.test.com"))
|
to_jid="unknown@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
|
|
||||||
def test_handle_presence_subscribe_to_registered_handlers(self):
|
def test_handle_presence_subscribe_to_registered_handlers(self):
|
||||||
@@ -2343,11 +2346,10 @@ class JCLComponent_handle_presence_subscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
result = self.comp.handle_presence_subscribe(Presence(\
|
sent = self.comp.handle_presence_subscribe(Presence(\
|
||||||
stanza_type="subscribe",
|
stanza_type="subscribe",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="user1%test.com@jcl.test.com"))
|
to_jid="user1%test.com@jcl.test.com"))
|
||||||
sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(sent), 2)
|
self.assertEqual(len(sent), 2)
|
||||||
self.assertTrue(type(sent[0]), Presence)
|
self.assertTrue(type(sent[0]), Presence)
|
||||||
self.assertEquals(sent[0].get_type(), "subscribe")
|
self.assertEquals(sent[0].get_type(), "subscribe")
|
||||||
@@ -2377,11 +2379,10 @@ class JCLComponent_handle_presence_unsubscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unsubscribe(Presence(\
|
presence_sent = self.comp.handle_presence_unsubscribe(Presence(\
|
||||||
stanza_type="unsubscribe",
|
stanza_type="unsubscribe",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 2)
|
self.assertEqual(len(presence_sent), 2)
|
||||||
presence = presence_sent[0]
|
presence = presence_sent[0]
|
||||||
self.assertEqual(presence.get_from(), "account11@jcl.test.com")
|
self.assertEqual(presence.get_from(), "account11@jcl.test.com")
|
||||||
@@ -2416,11 +2417,10 @@ class JCLComponent_handle_presence_unsubscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unsubscribe(Presence(\
|
presence_sent = self.comp.handle_presence_unsubscribe(Presence(\
|
||||||
stanza_type="unsubscribe",
|
stanza_type="unsubscribe",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 2)
|
self.assertEqual(len(presence_sent), 2)
|
||||||
presence = presence_sent[0]
|
presence = presence_sent[0]
|
||||||
self.assertEqual(presence.get_from(), "account11@jcl.test.com")
|
self.assertEqual(presence.get_from(), "account11@jcl.test.com")
|
||||||
@@ -2458,11 +2458,10 @@ class JCLComponent_handle_presence_unsubscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unsubscribe(Presence(\
|
presence_sent = self.comp.handle_presence_unsubscribe(Presence(\
|
||||||
stanza_type="unsubscribe",
|
stanza_type="unsubscribe",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="jcl.test.com"))
|
to_jid="jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 6)
|
self.assertEqual(len(presence_sent), 6)
|
||||||
presence = presence_sent[0]
|
presence = presence_sent[0]
|
||||||
self.assertEqual(presence.get_from(), "account11@jcl.test.com")
|
self.assertEqual(presence.get_from(), "account11@jcl.test.com")
|
||||||
@@ -2523,11 +2522,10 @@ class JCLComponent_handle_presence_unsubscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unsubscribe(Presence(\
|
presence_sent = self.comp.handle_presence_unsubscribe(Presence(\
|
||||||
stanza_type="unsubscribe",
|
stanza_type="unsubscribe",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="user1%test.com@jcl.test.com"))
|
to_jid="user1%test.com@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 2)
|
self.assertEqual(len(presence_sent), 2)
|
||||||
presence = presence_sent[0]
|
presence = presence_sent[0]
|
||||||
self.assertEqual(presence.get_from(), "user1%test.com@jcl.test.com")
|
self.assertEqual(presence.get_from(), "user1%test.com@jcl.test.com")
|
||||||
@@ -2555,11 +2553,10 @@ class JCLComponent_handle_presence_unsubscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unsubscribe(Presence(\
|
presence_sent = self.comp.handle_presence_unsubscribe(Presence(\
|
||||||
stanza_type="unsubscribe",
|
stanza_type="unsubscribe",
|
||||||
from_jid="unknown@test.com",
|
from_jid="unknown@test.com",
|
||||||
to_jid="account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
self.assertEquals(account.get_all_accounts_count(),
|
self.assertEquals(account.get_all_accounts_count(),
|
||||||
@@ -2581,11 +2578,10 @@ class JCLComponent_handle_presence_unsubscribe_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_presence_unsubscribe(Presence(\
|
presence_sent = self.comp.handle_presence_unsubscribe(Presence(\
|
||||||
stanza_type="unsubscribe",
|
stanza_type="unsubscribe",
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="unknown@jcl.test.com"))
|
to_jid="unknown@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
self.assertEquals(account.get_all_accounts_count(),
|
self.assertEquals(account.get_all_accounts_count(),
|
||||||
@@ -2596,11 +2592,10 @@ class JCLComponent_handle_presence_unsubscribed_TestCase(JCLComponent_TestCase):
|
|||||||
def test_handle_presence_unsubscribed(self):
|
def test_handle_presence_unsubscribed(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.handle_presence_unsubscribed(Presence(\
|
presence_sent = self.comp.handle_presence_unsubscribed(Presence(\
|
||||||
stanza_type = "unsubscribed", \
|
stanza_type = "unsubscribed", \
|
||||||
from_jid = "user1@test.com",\
|
from_jid = "user1@test.com",\
|
||||||
to_jid = "jcl.test.com"))
|
to_jid = "jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 1)
|
self.assertEqual(len(presence_sent), 1)
|
||||||
self.assertEqual(presence_sent[0].get_to(), "user1@test.com")
|
self.assertEqual(presence_sent[0].get_to(), "user1@test.com")
|
||||||
self.assertEqual(presence_sent[0].get_from(), "jcl.test.com")
|
self.assertEqual(presence_sent[0].get_from(), "jcl.test.com")
|
||||||
@@ -2611,11 +2606,10 @@ class JCLComponent_handle_presence_unsubscribed_TestCase(JCLComponent_TestCase):
|
|||||||
def test_handle_presence_unsubscribed_to_registered_handler(self):
|
def test_handle_presence_unsubscribed_to_registered_handler(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.handle_presence_unsubscribed(Presence(\
|
presence_sent = self.comp.handle_presence_unsubscribed(Presence(\
|
||||||
stanza_type = "unsubscribed", \
|
stanza_type = "unsubscribed", \
|
||||||
from_jid = "user1@test.com",\
|
from_jid = "user1@test.com",\
|
||||||
to_jid = "user1%test.com@jcl.test.com"))
|
to_jid = "user1%test.com@jcl.test.com"))
|
||||||
presence_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(presence_sent), 1)
|
self.assertEqual(len(presence_sent), 1)
|
||||||
self.assertEqual(presence_sent[0].get_to(), "user1@test.com")
|
self.assertEqual(presence_sent[0].get_to(), "user1@test.com")
|
||||||
self.assertEqual(presence_sent[0].get_from(), "user1%test.com@jcl.test.com")
|
self.assertEqual(presence_sent[0].get_from(), "user1%test.com@jcl.test.com")
|
||||||
@@ -2641,12 +2635,11 @@ class JCLComponent_handle_message_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_message(Message(\
|
messages_sent = self.comp.handle_message(Message(\
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="account11@jcl.test.com",
|
to_jid="account11@jcl.test.com",
|
||||||
subject="[PASSWORD]",
|
subject="[PASSWORD]",
|
||||||
body="secret"))
|
body="secret"))
|
||||||
messages_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(messages_sent), 0)
|
self.assertEqual(len(messages_sent), 0)
|
||||||
|
|
||||||
def test_handle_message_password_complex(self):
|
def test_handle_message_password_complex(self):
|
||||||
@@ -2666,12 +2659,11 @@ class JCLComponent_handle_message_TestCase(JCLComponent_TestCase):
|
|||||||
name="account2",
|
name="account2",
|
||||||
jid="account2@jcl.test.com")
|
jid="account2@jcl.test.com")
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
self.comp.handle_message(Message(\
|
messages_sent = self.comp.handle_message(Message(\
|
||||||
from_jid="user1@test.com",
|
from_jid="user1@test.com",
|
||||||
to_jid="account11@jcl.test.com",
|
to_jid="account11@jcl.test.com",
|
||||||
subject="[PASSWORD]",
|
subject="[PASSWORD]",
|
||||||
body="secret"))
|
body="secret"))
|
||||||
messages_sent = self.comp.stream.sent
|
|
||||||
self.assertEqual(len(messages_sent), 1)
|
self.assertEqual(len(messages_sent), 1)
|
||||||
self.assertEqual(messages_sent[0].get_to(), "user1@test.com")
|
self.assertEqual(messages_sent[0].get_to(), "user1@test.com")
|
||||||
self.assertEqual(messages_sent[0].get_from(), "account11@jcl.test.com")
|
self.assertEqual(messages_sent[0].get_from(), "account11@jcl.test.com")
|
||||||
@@ -2955,8 +2947,7 @@ class JCLComponent_handle_command_TestCase(JCLComponent_TestCase):
|
|||||||
"command")
|
"command")
|
||||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-disabled-users-num")
|
command_node.setProp("node", "http://jabber.org/protocol/admin#get-disabled-users-num")
|
||||||
command_node.setProp("action", "execute")
|
command_node.setProp("action", "execute")
|
||||||
self.comp.handle_command(info_query)
|
result = self.comp.handle_command(info_query)
|
||||||
result = self.comp.stream.sent
|
|
||||||
self.assertNotEquals(result, None)
|
self.assertNotEquals(result, None)
|
||||||
self.assertEquals(len(result), 1)
|
self.assertEquals(len(result), 1)
|
||||||
command_result = result[0].xpath_eval("c:command",
|
command_result = result[0].xpath_eval("c:command",
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class SetRegisterHandler_TestCase(JCLTestCase):
|
|||||||
error = result[0].get_error()
|
error = result[0].get_error()
|
||||||
self.assertEquals(error.get_condition().name, "not-acceptable")
|
self.assertEquals(error.get_condition().name, "not-acceptable")
|
||||||
self.assertEquals(error.get_text(), Lang.en.field_error \
|
self.assertEquals(error.get_text(), Lang.en.field_error \
|
||||||
% ("name", Lang.en.arobase_in_name_forbidden))
|
% ("name", Lang.en.forbidden_char_in_name))
|
||||||
|
|
||||||
def test_handle_invalid_name_with_whitespace(self):
|
def test_handle_invalid_name_with_whitespace(self):
|
||||||
"""Test with invalid supplied name"""
|
"""Test with invalid supplied name"""
|
||||||
@@ -88,7 +88,7 @@ class SetRegisterHandler_TestCase(JCLTestCase):
|
|||||||
error = result[0].get_error()
|
error = result[0].get_error()
|
||||||
self.assertEquals(error.get_condition().name, "not-acceptable")
|
self.assertEquals(error.get_condition().name, "not-acceptable")
|
||||||
self.assertEquals(error.get_text(), Lang.en.field_error \
|
self.assertEquals(error.get_text(), Lang.en.field_error \
|
||||||
% ("name", Lang.en.arobase_in_name_forbidden))
|
% ("name", Lang.en.forbidden_char_in_name))
|
||||||
|
|
||||||
def test_handle_invalid_empty_name(self):
|
def test_handle_invalid_empty_name(self):
|
||||||
"""Test with empty supplied name"""
|
"""Test with empty supplied name"""
|
||||||
|
|||||||
@@ -92,7 +92,8 @@ class Lang:
|
|||||||
field_error = u"Error with '%s' field: %s"
|
field_error = u"Error with '%s' field: %s"
|
||||||
mandatory_field = u"required field"
|
mandatory_field = u"required field"
|
||||||
not_well_formed_field = u"not well formed field"
|
not_well_formed_field = u"not well formed field"
|
||||||
arobase_in_name_forbidden = u"'@' is not allowed in account's name"
|
forbidden_char_in_name = u"Account's name contains an invalid character"
|
||||||
|
not_a_number = u"field must be a number"
|
||||||
|
|
||||||
field_chat_action = u"Action when state is 'Free For Chat'"
|
field_chat_action = u"Action when state is 'Free For Chat'"
|
||||||
field_online_action = u"Action when state is 'Online'"
|
field_online_action = u"Action when state is 'Online'"
|
||||||
@@ -270,7 +271,8 @@ class Lang:
|
|||||||
field_error = u"Erreur dans le champs '%s': %s"
|
field_error = u"Erreur dans le champs '%s': %s"
|
||||||
mandatory_field = u"%s est requis"
|
mandatory_field = u"%s est requis"
|
||||||
not_well_formed_field = u"Le champs %s n'est pas acceptable"
|
not_well_formed_field = u"Le champs %s n'est pas acceptable"
|
||||||
arobase_in_name_forbidden = u"Le nom du compte ne peux contenir le charactère '@'"
|
forbidden_char_in_name = u"Le nom du compte contient un charactère invalide"
|
||||||
|
not_a_number = u"Le champs doit être un nombre"
|
||||||
|
|
||||||
field_chat_action = u"Action lorsque l'état est 'Free For Chat'"
|
field_chat_action = u"Action lorsque l'état est 'Free For Chat'"
|
||||||
field_online_action = u"Action lorsque l'état est 'Online'"
|
field_online_action = u"Action lorsque l'état est 'Online'"
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ __revision__ = "$Id: account.py,v 1.3 2005/09/18 20:24:07 dax Exp $"
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
|
import exceptions
|
||||||
|
|
||||||
from sqlobject.inheritance import InheritableSQLObject
|
from sqlobject.inheritance import InheritableSQLObject
|
||||||
from sqlobject.col import StringCol, IntCol, BoolCol, ForeignKey, DateTimeCol
|
from sqlobject.col import StringCol, IntCol, BoolCol, ForeignKey, DateTimeCol
|
||||||
@@ -64,7 +65,10 @@ def int_post_func(field_value, default_func, bare_from_jid):
|
|||||||
"""Return an integer from integer field value"""
|
"""Return an integer from integer field value"""
|
||||||
if field_value is None or str(field_value) == "":
|
if field_value is None or str(field_value) == "":
|
||||||
return int(default_func(bare_from_jid))
|
return int(default_func(bare_from_jid))
|
||||||
|
try:
|
||||||
return int(field_value)
|
return int(field_value)
|
||||||
|
except exceptions.ValueError:
|
||||||
|
raise FieldError("TODO", message_property="not_a_number")
|
||||||
|
|
||||||
def mandatory_field(field_name, field_value):
|
def mandatory_field(field_name, field_value):
|
||||||
"""Used as default function for field that must be specified
|
"""Used as default function for field that must be specified
|
||||||
|
|||||||
@@ -182,11 +182,16 @@ class AccountModule_TestCase(JCLTestCase):
|
|||||||
"user1@jcl.test.com")
|
"user1@jcl.test.com")
|
||||||
self.assertEquals(result, 42)
|
self.assertEquals(result, 42)
|
||||||
|
|
||||||
def test_int_post_func_default_value(self):
|
def test_int_post_func_default_value2(self):
|
||||||
result = account.int_post_func(None, lambda bare_from_jid: 42, \
|
result = account.int_post_func(None, lambda bare_from_jid: 42, \
|
||||||
"user1@jcl.test.com")
|
"user1@jcl.test.com")
|
||||||
self.assertEquals(result, 42)
|
self.assertEquals(result, 42)
|
||||||
|
|
||||||
|
def test_int_post_func_invalid_value(self):
|
||||||
|
self.assertRaises(FieldError,
|
||||||
|
account.int_post_func,
|
||||||
|
"notanint", None, "user1@jcl.test.com")
|
||||||
|
|
||||||
def test_mandatory_field_empty(self):
|
def test_mandatory_field_empty(self):
|
||||||
self.assertRaises(FieldError,
|
self.assertRaises(FieldError,
|
||||||
account.mandatory_field,
|
account.mandatory_field,
|
||||||
|
|||||||
@@ -94,7 +94,8 @@ class Language_TestCase(unittest.TestCase):
|
|||||||
self.assertNotEquals(self.lang_class.field_error % ("", ""), None)
|
self.assertNotEquals(self.lang_class.field_error % ("", ""), None)
|
||||||
self.assertNotEquals(self.lang_class.mandatory_field, None)
|
self.assertNotEquals(self.lang_class.mandatory_field, None)
|
||||||
self.assertNotEquals(self.lang_class.not_well_formed_field, None)
|
self.assertNotEquals(self.lang_class.not_well_formed_field, None)
|
||||||
self.assertNotEquals(self.lang_class.arobase_in_name_forbidden, None)
|
self.assertNotEquals(self.lang_class.forbidden_char_in_name, None)
|
||||||
|
self.assertNotEquals(self.lang_class.not_a_number, None)
|
||||||
|
|
||||||
self.assertNotEquals(self.lang_class.field_chat_action, None)
|
self.assertNotEquals(self.lang_class.field_chat_action, None)
|
||||||
self.assertNotEquals(self.lang_class.field_online_action, None)
|
self.assertNotEquals(self.lang_class.field_online_action, None)
|
||||||
|
|||||||
Reference in New Issue
Block a user