Add MailCommandManager as default CommandManager with MailComponent

darcs-hash:20071030065654-86b55-f9a304b8dc5d26c94ffe466d70baa2cbc32b0436.gz
This commit is contained in:
David Rousselie
2007-10-30 07:56:54 +01:00
parent 204b03ea90
commit 16b78d407b
5 changed files with 34 additions and 11 deletions

View File

@@ -48,6 +48,7 @@ from jmc.jabber.presence import MailSubscribeHandler, \
from jmc.model.account import MailAccount, IMAPAccount, POP3Account, \
SMTPAccount
from jmc.lang import Lang
from jmc.jabber.command import MailCommandManager
class MailAccountManager(AccountManager):
def account_get_register(self, info_query,
@@ -109,7 +110,8 @@ class MailComponent(FeederComponent):
config,
config_file,
lang=Lang(),
account_manager_class=MailAccountManager):
account_manager_class=MailAccountManager,
command_manager_class=MailCommandManager):
"""Use FeederComponent behavior and setup feeder and sender
attributes.
"""
@@ -121,7 +123,8 @@ class MailComponent(FeederComponent):
config,
config_file,
lang=lang,
account_manager_class=account_manager_class)
account_manager_class=account_manager_class,
command_manager_class=command_manager_class)
self.handler = MailFeederHandler(MailFeeder(self), MailSender(self))
self.account_manager.account_classes = (IMAPAccount,
POP3Account,
@@ -142,10 +145,6 @@ class MailComponent(FeederComponent):
jabber.replace_handlers(self.disco_get_info_handlers,
AccountDiscoGetInfoHandler,
IMAPAccountDiscoGetInfoHandler(self))
# for hg in self.disco_get_items_handlers:
# print "----"
# for h in hg:
# print str(h)
class MailFeeder(Feeder):
"""Email check"""

View File

@@ -30,6 +30,7 @@ from jcl.model import account
from jcl.jabber.command import CommandRootDiscoGetInfoHandler
from jcl.jabber.disco import AccountTypeDiscoGetInfoHandler, \
AccountDiscoGetInfoHandler, DiscoHandler
import jcl.jabber.command as command
from jmc.model.account import IMAPAccount
@@ -60,6 +61,7 @@ class IMAPAccountDiscoGetInfoHandler(AccountDiscoGetInfoHandler):
lang_class,
node, disco_obj,
data)
disco_infos[0].add_feature(command.COMMAND_NS)
splitted_node = node.split("/")
splitted_node_len = len(splitted_node)
if splitted_node_len > 1 and \

View File

@@ -3,12 +3,13 @@ __revision__ = ""
import unittest
from jmc.jabber.tests import component, disco
from jmc.jabber.tests import component, disco, command
def suite():
suite = unittest.TestSuite()
suite.addTest(component.suite())
suite.addTest(disco.suite())
suite.addTest(command.suite())
return suite
if __name__ == '__main__':

View File

@@ -153,6 +153,10 @@ class MockIMAPAccount(MockMailAccount, IMAPAccount):
return ["subdir1", "subdir2"]
return []
def get_mail_with_attachment_list(self):
return [("1", "mail 1"),
("2", "mail 2")]
class MockPOP3Account(MockMailAccount, POP3Account):
def _init(self, *args, **kw):
POP3Account._init(self, *args, **kw)

View File

@@ -3,18 +3,18 @@
## Login : David Rousselie <dax@happycoders.org>
## Started on Sun Jul 8 20:59:32 2007 David Rousselie
## $Id$
##
##
## Copyright (C) 2007 David Rousselie
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -22,7 +22,9 @@
import unittest
from jmc.jabber.disco import MailRootDiscoGetInfoHandler
from jmc.jabber.disco import MailRootDiscoGetInfoHandler, \
IMAPAccountDiscoGetInfoHandler
from jmc.lang import Lang
class MockDiscoIndentity(object):
def __init__(self):
@@ -57,9 +59,24 @@ class MailRootDiscoGetInfoHandler_TestCase(unittest.TestCase):
self.assertTrue(disco_infos[0].identity_is("gateway", "smtp"))
self.assertTrue(disco_infos[0].identity_is("headline", "newmail"))
class IMAPAccountDiscoGetInfoHandler_TestCase(unittest.TestCase):
def test_handle_not_imap(self):
component = MockComponent()
component.name = "Mock component"
component.disco_identity.category = "gateway"
component.disco_identity.type = "smtp"
component.account_manager.has_multiple_account_type = True
handler = IMAPAccountDiscoGetInfoHandler(component)
# stanza, lang_class, node, disco_obj, data
disco_infos = handler.handle(None, Lang.en, "account@jmc.test.com/POP3",
None, None)
self.assertTrue(disco_infos[0].has_feature("jabber:iq:register"))
self.assertTrue(disco_infos[0].has_feature("http://jabber.org/protocol/commands"))
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(MailRootDiscoGetInfoHandler_TestCase, 'test'))
suite.addTest(unittest.makeSuite(IMAPAccountDiscoGetInfoHandler_TestCase, 'test'))
return suite
if __name__ == '__main__':