unavailable presence test when going offline
darcs-hash:20061102183026-86b55-bab3df0fcb8ea516fcba7aec18e824d4f2a393a4.gz
This commit is contained in:
12
run_tests.py
12
run_tests.py
@@ -50,14 +50,14 @@ if __name__ == '__main__':
|
|||||||
feeder_suite = unittest.makeSuite(Feeder_TestCase, "test")
|
feeder_suite = unittest.makeSuite(Feeder_TestCase, "test")
|
||||||
sender_suite = unittest.makeSuite(Sender_TestCase, "test")
|
sender_suite = unittest.makeSuite(Sender_TestCase, "test")
|
||||||
jcl_suite = unittest.TestSuite()
|
jcl_suite = unittest.TestSuite()
|
||||||
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_get_register_exist_complex'))
|
jcl_suite.addTest(FeederComponent_TestCase('test_handle_get_register_exist'))
|
||||||
# jcl_suite.addTest(FeederComponent_TestCase('test_constructor'))
|
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_presence_available_to_account_live_password'))
|
||||||
# jcl_suite = unittest.TestSuite((feeder_component_suite))
|
# jcl_suite = unittest.TestSuite((feeder_component_suite))
|
||||||
# jcl_suite = unittest.TestSuite((component_suite))
|
# jcl_suite = unittest.TestSuite((component_suite))
|
||||||
jcl_suite = unittest.TestSuite((component_suite,
|
# jcl_suite = unittest.TestSuite((component_suite,
|
||||||
feeder_component_suite,
|
# feeder_component_suite,
|
||||||
feeder_suite,
|
# feeder_suite,
|
||||||
sender_suite))
|
# sender_suite))
|
||||||
test_support.run_suite(jcl_suite)
|
test_support.run_suite(jcl_suite)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -143,19 +143,23 @@ class JCLComponent(Component, object):
|
|||||||
self.queue.put(e)
|
self.queue.put(e)
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
if self.stream:
|
if self.stream and not self.stream.eof \
|
||||||
# TODO : send unavailble from transport and all account to users
|
and self.stream.socket is not None:
|
||||||
pass
|
current_user_jid = None
|
||||||
# for jid in self.__storage.keys(()):
|
self.db_connect()
|
||||||
# p = Presence(from_jid = unicode(self.jid), to_jid = jid, \
|
for _account in \
|
||||||
# stanza_type = "unavailable")
|
self.account_class.select(orderBy = "user_jid"):
|
||||||
# self.stream.send(p)
|
if current_user_jid != _account.user_jid:
|
||||||
# for jid, name in self.__storage.keys():
|
current_user_jid = _account.user_jid
|
||||||
# if self.__storage[(jid, name)].status != "offline":
|
self.stream.send(Presence(\
|
||||||
# p = Presence(from_jid = name + "@" + unicode(self.jid),\
|
from_jid = unicode(self.jid), \
|
||||||
# to_jid = jid, \
|
to_jid = _account.user_jid, \
|
||||||
# stanza_type = "unavailable")
|
stanza_type = "unavailable"))
|
||||||
# self.stream.send(p)
|
self.stream.send(Presence(\
|
||||||
|
from_jid = self.get_jid(_account), \
|
||||||
|
to_jid = _account.user_jid, \
|
||||||
|
stanza_type = "unavailable"))
|
||||||
|
self.db_disconnect()
|
||||||
# threads = threading.enumerate()
|
# threads = threading.enumerate()
|
||||||
timer_thread.join(JCLComponent.timeout)
|
timer_thread.join(JCLComponent.timeout)
|
||||||
# for _thread in threads:
|
# for _thread in threads:
|
||||||
|
|||||||
@@ -189,8 +189,55 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
NotImplementedError))
|
NotImplementedError))
|
||||||
|
|
||||||
def test_run_go_offline(self):
|
def test_run_go_offline(self):
|
||||||
## TODO : verify offline stanza are sent
|
self.comp.stream = MockStream()
|
||||||
pass
|
self.comp.stream_class = MockStream
|
||||||
|
self.comp.time_unit = 1
|
||||||
|
self.max_tick_count = 1
|
||||||
|
self.comp.handle_tick = self.__handle_tick_test_time_handler
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
account11 = Account(user_jid = "test1@test.com", \
|
||||||
|
name = "account11", \
|
||||||
|
jid = "account11@jcl.test.com")
|
||||||
|
account12 = Account(user_jid = "test1@test.com", \
|
||||||
|
name = "account12", \
|
||||||
|
jid = "account12@jcl.test.com")
|
||||||
|
account2 = Account(user_jid = "test2@test.com", \
|
||||||
|
name = "account2", \
|
||||||
|
jid = "account2@jcl.test.com")
|
||||||
|
del account.hub.threadConnection
|
||||||
|
self.comp.run()
|
||||||
|
self.assertTrue(self.comp.stream.connection_started)
|
||||||
|
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)
|
||||||
|
self.assertEquals(len(self.comp.stream.sent), 5)
|
||||||
|
presence = self.comp.stream.sent[0]
|
||||||
|
self.assertTrue(isinstance(presence, Presence))
|
||||||
|
self.assertEquals(presence.get_from(), "jcl.test.com")
|
||||||
|
self.assertEquals(presence.get_to(), "test1@test.com")
|
||||||
|
self.assertEquals(presence.get_node().prop("type"), "unavailable")
|
||||||
|
presence = self.comp.stream.sent[1]
|
||||||
|
self.assertTrue(isinstance(presence, Presence))
|
||||||
|
self.assertEquals(presence.get_from(), "account11@jcl.test.com")
|
||||||
|
self.assertEquals(presence.get_to(), "test1@test.com")
|
||||||
|
self.assertEquals(presence.get_node().prop("type"), "unavailable")
|
||||||
|
presence = self.comp.stream.sent[2]
|
||||||
|
self.assertTrue(isinstance(presence, Presence))
|
||||||
|
self.assertEquals(presence.get_from(), "account12@jcl.test.com")
|
||||||
|
self.assertEquals(presence.get_to(), "test1@test.com")
|
||||||
|
self.assertEquals(presence.get_node().prop("type"), "unavailable")
|
||||||
|
presence = self.comp.stream.sent[3]
|
||||||
|
self.assertTrue(isinstance(presence, Presence))
|
||||||
|
self.assertEquals(presence.get_from(), "jcl.test.com")
|
||||||
|
self.assertEquals(presence.get_to(), "test2@test.com")
|
||||||
|
self.assertEquals(presence.get_node().prop("type"), "unavailable")
|
||||||
|
presence = self.comp.stream.sent[4]
|
||||||
|
self.assertTrue(isinstance(presence, Presence))
|
||||||
|
self.assertEquals(presence.get_from(), "account2@jcl.test.com")
|
||||||
|
self.assertEquals(presence.get_to(), "test2@test.com")
|
||||||
|
self.assertEquals(presence.get_node().prop("type"), "unavailable")
|
||||||
|
|
||||||
def __handle_tick_test_time_handler(self):
|
def __handle_tick_test_time_handler(self):
|
||||||
self.max_tick_count -= 1
|
self.max_tick_count -= 1
|
||||||
@@ -215,13 +262,13 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
def test_authenticated_send_probe(self):
|
def test_authenticated_send_probe(self):
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
account11 = Account(user_jid = "test1@test.com", \
|
account11 = Account(user_jid = "test1@test.com", \
|
||||||
name = "test11", \
|
name = "account11", \
|
||||||
jid = "account11@jcl.test.com")
|
jid = "account11@jcl.test.com")
|
||||||
account12 = Account(user_jid = "test1@test.com", \
|
account12 = Account(user_jid = "test1@test.com", \
|
||||||
name = "test12", \
|
name = "account12", \
|
||||||
jid = "account12@jcl.test.com")
|
jid = "account12@jcl.test.com")
|
||||||
account2 = Account(user_jid = "test2@test.com", \
|
account2 = Account(user_jid = "test2@test.com", \
|
||||||
name = "test2", \
|
name = "account2", \
|
||||||
jid = "account2@jcl.test.com")
|
jid = "account2@jcl.test.com")
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
self.comp.stream = stream = MockStream()
|
self.comp.stream = stream = MockStream()
|
||||||
|
|||||||
Reference in New Issue
Block a user