More tests
darcs-hash:20061018174930-86b55-29433ceb46b2c1f7decade7ff062d670a119400d.gz
This commit is contained in:
@@ -50,8 +50,8 @@ 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_tick'))
|
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_get_version'))
|
||||||
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_presence_unavailable_to_account'))
|
# 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,
|
||||||
|
|||||||
@@ -434,19 +434,25 @@ class JCLComponent(Component):
|
|||||||
## from_jid = stanza.get_from()
|
## from_jid = stanza.get_from()
|
||||||
## base_from_jid = unicode(from_jid.bare())
|
## base_from_jid = unicode(from_jid.bare())
|
||||||
# TODO : send presence available to subscribed user
|
# TODO : send presence available to subscribed user
|
||||||
|
# is it necessary to send available presence ?
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
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")
|
||||||
## name = stanza.get_to().node
|
name = stanza.get_to().node
|
||||||
from_jid = stanza.get_from()
|
from_jid = stanza.get_from()
|
||||||
## base_from_jid = unicode(from_jid.bare())
|
base_from_jid = unicode(from_jid.bare())
|
||||||
# TODO : delete from account base
|
|
||||||
presence = Presence(from_jid = stanza.get_to(), to_jid = from_jid, \
|
presence = Presence(from_jid = stanza.get_to(), to_jid = from_jid, \
|
||||||
stanza_type = "unsubscribe")
|
stanza_type = "unsubscribe")
|
||||||
self.stream.send(presence)
|
self.stream.send(presence)
|
||||||
|
self.db_connect()
|
||||||
|
for _account in self.account_class.select(\
|
||||||
|
self.account_class.q.user_jid == base_from_jid \
|
||||||
|
and self.account_class.q.name == name):
|
||||||
|
_account.destroySelf()
|
||||||
|
self.db_disconnect()
|
||||||
presence = stanza.make_accept_response()
|
presence = stanza.make_accept_response()
|
||||||
self.stream.send(presence)
|
self.stream.send(presence)
|
||||||
return 1
|
return 1
|
||||||
@@ -463,16 +469,20 @@ class JCLComponent(Component):
|
|||||||
|
|
||||||
def handle_message(self, message):
|
def handle_message(self, message):
|
||||||
"""Handle new message
|
"""Handle new message
|
||||||
|
Handle password response message
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("MESSAGE: " + message.get_body())
|
self.__logger.debug("MESSAGE: " + message.get_body())
|
||||||
lang_class = self.__lang.get_lang_class_from_node(message.get_node())
|
lang_class = self.__lang.get_lang_class_from_node(message.get_node())
|
||||||
## name = message.get_to().node
|
name = message.get_to().node
|
||||||
## base_from_jid = unicode(message.get_from().bare())
|
base_from_jid = unicode(message.get_from().bare())
|
||||||
|
self.db_connect()
|
||||||
|
accounts = self.account_class.select(\
|
||||||
|
self.account_class.q.user_jid == base_from_jid \
|
||||||
|
and self.account_class.q.name == name)
|
||||||
if re.compile("\[PASSWORD\]").search(message.get_subject()) \
|
if re.compile("\[PASSWORD\]").search(message.get_subject()) \
|
||||||
is not None:
|
is not None \
|
||||||
## TODO and self.__storage.has_key((base_from_jid, name)):
|
and accounts.count() == 1:
|
||||||
## account = self.__storage[(base_from_jid, name)]
|
account = list(accounts)[0]
|
||||||
account = Account()
|
|
||||||
account.password = message.get_body()
|
account.password = message.get_body()
|
||||||
account.waiting_password_reply = False
|
account.waiting_password_reply = False
|
||||||
msg = Message(from_jid = account.jid, \
|
msg = Message(from_jid = account.jid, \
|
||||||
@@ -481,42 +491,44 @@ class JCLComponent(Component):
|
|||||||
subject = lang_class.password_saved_for_session, \
|
subject = lang_class.password_saved_for_session, \
|
||||||
body = lang_class.password_saved_for_session)
|
body = lang_class.password_saved_for_session)
|
||||||
self.stream.send(msg)
|
self.stream.send(msg)
|
||||||
|
self.db_disconnect()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Utils
|
# Utils
|
||||||
###########################################################################
|
###########################################################################
|
||||||
def _send_presence_available(self, account, show, lang_class):
|
def _send_presence_available(self, _account, show, lang_class):
|
||||||
"""Send available presence to account's user and ask for password
|
"""Send available presence to account's user and ask for password
|
||||||
if necessary"""
|
if necessary"""
|
||||||
account.default_lang_class = lang_class
|
_account.default_lang_class = lang_class
|
||||||
old_status = account.status
|
old_status = _account.status
|
||||||
if show is None:
|
if show is None:
|
||||||
account.status = account.ONLINE # TODO get real status = (not show)
|
_account.status = account.ONLINE # TODO get real status = (not show)
|
||||||
else:
|
else:
|
||||||
account.status = show
|
_account.status = show
|
||||||
p = Presence(from_jid = account.jid, \
|
p = Presence(from_jid = _account.jid, \
|
||||||
to_jid = account.user_jid, \
|
to_jid = _account.user_jid, \
|
||||||
status = account.status_msg, \
|
status = _account.status_msg, \
|
||||||
show = show, \
|
show = show, \
|
||||||
stanza_type = "available")
|
stanza_type = "available")
|
||||||
self.stream.send(p)
|
self.stream.send(p)
|
||||||
if account.store_password == False \
|
if _account.store_password == False \
|
||||||
and old_status == account.OFFLINE:
|
and old_status == account.OFFLINE \
|
||||||
self._ask_password(account, lang_class)
|
and _account.password == None :
|
||||||
|
self._ask_password(_account, lang_class)
|
||||||
|
|
||||||
def _ask_password(self, account, lang_class):
|
def _ask_password(self, _account, lang_class):
|
||||||
"""Send a Jabber message to ask for account password
|
"""Send a Jabber message to ask for account password
|
||||||
"""
|
"""
|
||||||
if not account.waiting_password_reply \
|
if not _account.waiting_password_reply \
|
||||||
and account.status != "offline":
|
and _account.status != account.OFFLINE:
|
||||||
account.waiting_password_reply = True
|
_account.waiting_password_reply = True
|
||||||
msg = Message(from_jid = account.jid, \
|
msg = Message(from_jid = _account.jid, \
|
||||||
to_jid = account.user_jid, \
|
to_jid = _account.user_jid, \
|
||||||
stanza_type = "normal", \
|
stanza_type = "normal", \
|
||||||
subject = u"[PASSWORD] " + \
|
subject = u"[PASSWORD] " + \
|
||||||
lang_class.ask_password_subject, \
|
lang_class.ask_password_subject)#, \
|
||||||
body = lang_class.ask_password_body)# % \
|
## body = lang_class.ask_password_body)# % \
|
||||||
## (account.host, account.login))
|
## (account.host, account.login))
|
||||||
self.stream.send(msg)
|
self.stream.send(msg)
|
||||||
|
|
||||||
|
|||||||
@@ -46,14 +46,13 @@ class Account(SQLObject):
|
|||||||
name = StringCol()
|
name = StringCol()
|
||||||
jid = StringCol()
|
jid = StringCol()
|
||||||
login = StringCol(default = "")
|
login = StringCol(default = "")
|
||||||
__password = StringCol(default = "")
|
password = StringCol(default = None)
|
||||||
__store_password = BoolCol(default = True)
|
store_password = BoolCol(default = True)
|
||||||
|
|
||||||
default_lang_class = Lang.en
|
default_lang_class = Lang.en
|
||||||
first_check = True
|
first_check = True
|
||||||
__status = OFFLINE
|
__status = OFFLINE
|
||||||
waiting_password_reply = False
|
waiting_password_reply = False
|
||||||
__volatile_password = ""
|
|
||||||
|
|
||||||
def get_long_name(self):
|
def get_long_name(self):
|
||||||
"""Return Human readable account name"""
|
"""Return Human readable account name"""
|
||||||
@@ -83,28 +82,3 @@ class Account(SQLObject):
|
|||||||
|
|
||||||
status = property(get_status, set_status)
|
status = property(get_status, set_status)
|
||||||
|
|
||||||
def set_password(self, password):
|
|
||||||
"""Set password associated to account"""
|
|
||||||
self.__password = password
|
|
||||||
|
|
||||||
def get_password(self):
|
|
||||||
"""Return password associated to account"""
|
|
||||||
return self.__password
|
|
||||||
|
|
||||||
password = property(get_password, set_password)
|
|
||||||
|
|
||||||
def set_store_password(self, store_password):
|
|
||||||
"""Set store_password attribut
|
|
||||||
determine if password is persitent or not"""
|
|
||||||
if store_password:
|
|
||||||
self.password = property(get_password, set_password)
|
|
||||||
else:
|
|
||||||
self.password = property(get_volatile_password, \
|
|
||||||
set_volatile_password)
|
|
||||||
self.__store_password = store_password
|
|
||||||
|
|
||||||
def get_store_password(self):
|
|
||||||
"""Return store_password boolean"""
|
|
||||||
return self.__store_password
|
|
||||||
|
|
||||||
store_password = property(get_store_password, set_store_password)
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ from sqlobject.dbconnection import TheURIOpener
|
|||||||
from pyxmpp.iq import Iq
|
from pyxmpp.iq import Iq
|
||||||
from pyxmpp.stanza import Stanza
|
from pyxmpp.stanza import Stanza
|
||||||
from pyxmpp.presence import Presence
|
from pyxmpp.presence import Presence
|
||||||
|
from pyxmpp.message import Message
|
||||||
|
|
||||||
from jcl.jabber.component import JCLComponent
|
from jcl.jabber.component import JCLComponent
|
||||||
from jcl.model import account
|
from jcl.model import account
|
||||||
@@ -399,6 +400,50 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.assertEqual(presence_sent[0].get_from(), "account11@jcl.test.com")
|
self.assertEqual(presence_sent[0].get_from(), "account11@jcl.test.com")
|
||||||
self.assertEqual(presence_sent[0].get_show(), "online")
|
self.assertEqual(presence_sent[0].get_show(), "online")
|
||||||
|
|
||||||
|
def test_handle_presence_available_to_account_live_password(self):
|
||||||
|
self.comp.stream = MockStream()
|
||||||
|
self.comp.stream_class = MockStream
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
account11 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account11", \
|
||||||
|
jid = "account11@jcl.test.com")
|
||||||
|
account11.store_password = False
|
||||||
|
account12 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account12", \
|
||||||
|
jid = "account12@jcl.test.com")
|
||||||
|
account2 = Account(user_jid = "user2@test.com", \
|
||||||
|
name = "account2", \
|
||||||
|
jid = "account2@jcl.test.com")
|
||||||
|
del account.hub.threadConnection
|
||||||
|
## TODO: "online" exist ?
|
||||||
|
self.comp.handle_presence_available(Presence(\
|
||||||
|
stanza_type = "available", \
|
||||||
|
show = "online", \
|
||||||
|
from_jid = "user1@test.com",\
|
||||||
|
to_jid = "account11@jcl.test.com"))
|
||||||
|
messages_sent = self.comp.stream.sent
|
||||||
|
self.assertEqual(len(messages_sent), 2)
|
||||||
|
password_message = None
|
||||||
|
presence = None
|
||||||
|
for message in messages_sent:
|
||||||
|
if isinstance(message, Message):
|
||||||
|
password_message = message
|
||||||
|
elif isinstance(message, Presence):
|
||||||
|
presence = message
|
||||||
|
self.assertTrue(password_message is not None)
|
||||||
|
self.assertTrue(presence is not None)
|
||||||
|
self.assertEqual(presence.get_show(), "online")
|
||||||
|
self.assertEqual(presence.get_from_jid(), "account11@jcl.test.com")
|
||||||
|
self.assertEqual(presence.get_to_jid(), "user1@test.com")
|
||||||
|
|
||||||
|
self.assertEqual(unicode(password_message.get_from_jid()), \
|
||||||
|
"account11@jcl.test.com")
|
||||||
|
self.assertEqual(unicode(password_message.get_to_jid()), \
|
||||||
|
"user1@test.com")
|
||||||
|
self.assertEqual(password_message.get_subject(), \
|
||||||
|
"[PASSWORD] Password request")
|
||||||
|
self.assertEqual(password_message.get_body(), None)
|
||||||
|
|
||||||
def test_handle_presence_unavailable_to_component(self):
|
def test_handle_presence_unavailable_to_component(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
@@ -475,20 +520,132 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
presence_sent[0].xpath_eval("@type")[0].get_content(), \
|
presence_sent[0].xpath_eval("@type")[0].get_content(), \
|
||||||
"unavailable")
|
"unavailable")
|
||||||
|
|
||||||
def test_handle_presence_subscribe(self):
|
def test_handle_presence_subscribe_to_component(self):
|
||||||
pass
|
self.comp.stream = MockStream()
|
||||||
|
self.comp.stream_class = MockStream
|
||||||
|
self.comp.handle_presence_subscribe(Presence(\
|
||||||
|
stanza_type = "subscribe", \
|
||||||
|
from_jid = "user1@test.com",\
|
||||||
|
to_jid = "jcl.test.com"))
|
||||||
|
presence_sent = self.comp.stream.sent
|
||||||
|
self.assertEqual(len(presence_sent), 1)
|
||||||
|
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].xpath_eval("@type")[0].get_content(), \
|
||||||
|
"subscribed")
|
||||||
|
|
||||||
|
def test_handle_presence_subscribe_to_account(self):
|
||||||
|
self.comp.stream = MockStream()
|
||||||
|
self.comp.stream_class = MockStream
|
||||||
|
self.comp.handle_presence_subscribe(Presence(\
|
||||||
|
stanza_type = "subscribe", \
|
||||||
|
from_jid = "user1@test.com",\
|
||||||
|
to_jid = "account11@jcl.test.com"))
|
||||||
|
presence_sent = self.comp.stream.sent
|
||||||
|
self.assertEqual(len(presence_sent), 1)
|
||||||
|
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].xpath_eval("@type")[0].get_content(), \
|
||||||
|
"subscribed")
|
||||||
|
|
||||||
def test_handle_presence_subscribed(self):
|
def test_handle_presence_subscribed(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_handle_presence_unsubscribe(self):
|
def test_handle_presence_unsubscribe(self):
|
||||||
pass
|
self.comp.stream = MockStream()
|
||||||
|
self.comp.stream_class = MockStream
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
account11 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account11", \
|
||||||
|
jid = "account11@jcl.test.com")
|
||||||
|
account12 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account12", \
|
||||||
|
jid = "account12@jcl.test.com")
|
||||||
|
account2 = Account(user_jid = "user2@test.com", \
|
||||||
|
name = "account2", \
|
||||||
|
jid = "account2@jcl.test.com")
|
||||||
|
del account.hub.threadConnection
|
||||||
|
self.comp.handle_presence_unsubscribe(Presence(\
|
||||||
|
stanza_type = "unsubscribe", \
|
||||||
|
from_jid = "user1@test.com",\
|
||||||
|
to_jid = "account11@jcl.test.com"))
|
||||||
|
presence_sent = self.comp.stream.sent
|
||||||
|
self.assertEqual(len(presence_sent), 2)
|
||||||
|
self.assertEqual(len([presence \
|
||||||
|
for presence in presence_sent \
|
||||||
|
if presence.get_to_jid() == "user1@test.com"]), \
|
||||||
|
2)
|
||||||
|
self.assertEqual(\
|
||||||
|
len([presence \
|
||||||
|
for presence in presence_sent \
|
||||||
|
if presence.get_from_jid() == \
|
||||||
|
"account11@jcl.test.com" \
|
||||||
|
and presence.xpath_eval("@type")[0].get_content() \
|
||||||
|
== "unsubscribe"]), \
|
||||||
|
1)
|
||||||
|
self.assertEqual(\
|
||||||
|
len([presence \
|
||||||
|
for presence in presence_sent \
|
||||||
|
if presence.get_from_jid() == \
|
||||||
|
"account11@jcl.test.com" \
|
||||||
|
and presence.xpath_eval("@type")[0].get_content() \
|
||||||
|
== "unsubscribed"]), \
|
||||||
|
1)
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
self.assertEquals(self.comp.account_class.select(\
|
||||||
|
self.comp.account_class.q.user_jid == "user1@test.com" \
|
||||||
|
and self.comp.account_class.q.name == "account11").count(), \
|
||||||
|
0)
|
||||||
|
del account.hub.threadConnection
|
||||||
|
|
||||||
def test_handle_presence_unsubscribed(self):
|
def test_handle_presence_unsubscribed(self):
|
||||||
pass
|
self.comp.stream = MockStream()
|
||||||
|
self.comp.stream_class = MockStream
|
||||||
|
self.comp.handle_presence_unsubscribed(Presence(\
|
||||||
|
stanza_type = "unsubscribed", \
|
||||||
|
from_jid = "user1@test.com",\
|
||||||
|
to_jid = "jcl.test.com"))
|
||||||
|
presence_sent = self.comp.stream.sent
|
||||||
|
self.assertEqual(len(presence_sent), 1)
|
||||||
|
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].xpath_eval("@type")[0].get_content(), \
|
||||||
|
"unavailable")
|
||||||
|
|
||||||
def test_handle_message(self):
|
|
||||||
pass
|
def test_handle_message_password(self):
|
||||||
|
self.comp.stream = MockStream()
|
||||||
|
self.comp.stream_class = MockStream
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
account11 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account11", \
|
||||||
|
jid = "account11@jcl.test.com")
|
||||||
|
account11.waiting_password_reply = True
|
||||||
|
account12 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account12", \
|
||||||
|
jid = "account12@jcl.test.com")
|
||||||
|
account2 = Account(user_jid = "user2@test.com", \
|
||||||
|
name = "account2", \
|
||||||
|
jid = "account2@jcl.test.com")
|
||||||
|
del account.hub.threadConnection
|
||||||
|
self.comp.handle_message(Message(\
|
||||||
|
from_jid = "user1@test.com", \
|
||||||
|
to_jid = "account11@jcl.test.com", \
|
||||||
|
subject = "[PASSWORD]", \
|
||||||
|
body = "secret"))
|
||||||
|
messages_sent = self.comp.stream.sent
|
||||||
|
self.assertEqual(len(messages_sent), 1)
|
||||||
|
self.assertEqual(messages_sent[0].get_to(), "user1@test.com")
|
||||||
|
self.assertEqual(messages_sent[0].get_from(), "account11@jcl.test.com")
|
||||||
|
self.assertEqual(account11.password, "secret")
|
||||||
|
self.assertEqual(account11.waiting_password_reply, False)
|
||||||
|
self.assertEqual(messages_sent[0].get_subject(), \
|
||||||
|
"Password will be kept during your Jabber session")
|
||||||
|
self.assertEqual(messages_sent[0].get_body(), \
|
||||||
|
"Password will be kept during your Jabber session")
|
||||||
|
|
||||||
def test_handle_tick(self):
|
def test_handle_tick(self):
|
||||||
self.assertRaises(NotImplementedError, self.comp.handle_tick)
|
self.assertRaises(NotImplementedError, self.comp.handle_tick)
|
||||||
|
|||||||
Reference in New Issue
Block a user