Separate message send from message creation

darcs-hash:20070619160816-86b55-e9c4bf58036e00438f4af470c24c1fda806aed36.gz
This commit is contained in:
David Rousselie
2007-06-19 18:08:16 +02:00
parent c6bf50a607
commit cb4b3829e6
3 changed files with 34 additions and 25 deletions

View File

@@ -332,10 +332,10 @@ class JCLComponent(Component, object):
lambda name, from_jid, account_type, lang_class: \
self.account_manager.account_type_disco_get_info(),
lambda name, from_jid, account_type, lang_class: \
self.account_manager.root_disco_get_info(
self.name,
self.disco_identity.category,
self.disco_identity.type))
self.account_manager.root_disco_get_info(\
self.name,
self.disco_identity.category,
self.disco_identity.type))
def disco_get_items(self, node, info_query):
"""Discovery get nested nodes handler

View File

@@ -92,23 +92,32 @@ class Sender(object):
class MessageSender(Sender):
"""Send data as Jabber Message"""
def send(self, to_account, subject, body):
"""Implement abstract method from Sender class and send data as Jabber message"""
self.component.stream.send(Message(from_jid=to_account.jid,
to_jid=to_account.user_jid,
subject=subject,
body=body))
def create_message(self, to_account, data):
"""Create message to send"""
subject, body = data
return Message(from_jid=to_account.jid,
to_jid=to_account.user_jid,
subject=subject,
body=body)
class HeadlineSender(Sender):
def send(self, to_account, data):
"""Implement abstract method from Sender class and send
data as Jabber message.
"""
self.component.stream.send(self.create_message(to_account,
data))
class HeadlineSender(MessageSender):
"""Send data as Jabber Headline"""
def send(self, to_account, subject, body):
"""Implement abstract method from Sender class and send data as Jabber headline"""
self.component.stream.send(Message(from_jid=to_account.jid,
to_jid=to_account.user_jid,
subject=subject,
stanza_type="headline",
body=body))
def create_message(self, to_account, data):
"""Create headline to send"""
subject, body = data
return Message(from_jid=to_account.jid,
to_jid=to_account.user_jid,
subject=subject,
stanza_type="headline",
body=body)
class FeederHandler(Handler):
"""Filter (nothing by default) and call sender for each message from
@@ -133,7 +142,7 @@ class FeederHandler(Handler):
Do nothing by default.
"""
for _account in accounts:
for subject, body in self.feeder.feed(_account):
self.sender.send(_account, subject, body)
for data in self.feeder.feed(_account):
self.sender.send(_account, data)
return []

View File

@@ -55,8 +55,8 @@ class SenderMock(object):
def __init__(self):
self.sent = []
def send(self, _account, subject, body):
self.sent.append((_account, subject, body))
def send(self, _account, data):
self.sent.append((_account, data))
class FeederComponent_TestCase(JCLComponent_TestCase):
def setUp(self):
@@ -214,7 +214,7 @@ class MessageSender_TestCase(unittest.TestCase):
account11 = Account(user_jid = "user1@test.com", \
name = "account11", \
jid = "account11@jcl.test.com")
self.sender.send(account11, "subject", "Body message")
self.sender.send(account11, ("subject", "Body message"))
self.assertEquals(len(self.comp.stream.sent), 1)
message = self.comp.stream.sent[0]
self.assertEquals(message.get_from(), account11.jid)
@@ -277,8 +277,8 @@ class FeederHandler_TestCase(unittest.TestCase):
accounts = self.handler.handle(None, None, [account11, account12])
sent = self.handler.sender.sent
self.assertEquals(len(sent), 2)
self.assertEquals(sent[0], (account11, "subject", "body"))
self.assertEquals(sent[1], (account12, "subject", "body"))
self.assertEquals(sent[0], (account11, ("subject", "body")))
self.assertEquals(sent[1], (account12, ("subject", "body")))
del account.hub.threadConnection
def suite():