fix tests with python2.6
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.coverage
|
.coverage
|
||||||
*flymake.py
|
*flymake.py
|
||||||
.ropeproject
|
.ropeproject
|
||||||
|
*.pyc
|
||||||
|
|||||||
@@ -3,18 +3,18 @@
|
|||||||
## Login : David Rousselie <dax@happycoders.org>
|
## Login : David Rousselie <dax@happycoders.org>
|
||||||
## Started on Sun Jul 8 20:55:46 2007 David Rousselie
|
## Started on Sun Jul 8 20:55:46 2007 David Rousselie
|
||||||
## $Id$
|
## $Id$
|
||||||
##
|
##
|
||||||
## Copyright (C) 2007 David Rousselie
|
## Copyright (C) 2007 David Rousselie
|
||||||
## This program is free software; you can redistribute it and/or modify
|
## 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
|
## it under the terms of the GNU General Public License as published by
|
||||||
## the Free Software Foundation; either version 2 of the License, or
|
## the Free Software Foundation; either version 2 of the License, or
|
||||||
## (at your option) any later version.
|
## (at your option) any later version.
|
||||||
##
|
##
|
||||||
## This program is distributed in the hope that it will be useful,
|
## This program is distributed in the hope that it will be useful,
|
||||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
## GNU General Public License for more details.
|
## GNU General Public License for more details.
|
||||||
##
|
##
|
||||||
## You should have received a copy of the GNU General Public License
|
## You should have received a copy of the GNU General Public License
|
||||||
## along with this program; if not, write to the Free Software
|
## along with this program; if not, write to the Free Software
|
||||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
@@ -61,7 +61,9 @@ class IMAPAccountDiscoGetInfoHandler(AccountDiscoGetInfoHandler):
|
|||||||
lang_class,
|
lang_class,
|
||||||
node, disco_obj,
|
node, disco_obj,
|
||||||
data)
|
data)
|
||||||
disco_infos[0].add_feature(command.COMMAND_NS)
|
# TODO disco_infos[0].add_feature(command.COMMAND_NS)
|
||||||
|
if node is None:
|
||||||
|
return disco_infos
|
||||||
splitted_node = node.split("/")
|
splitted_node = node.split("/")
|
||||||
splitted_node_len = len(splitted_node)
|
splitted_node_len = len(splitted_node)
|
||||||
if splitted_node_len > 1 and \
|
if splitted_node_len > 1 and \
|
||||||
@@ -125,4 +127,3 @@ class IMAPAccountDiscoGetItemsHandler(DiscoHandler):
|
|||||||
subdir)
|
subdir)
|
||||||
return [disco_items]
|
return [disco_items]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ class MailFeeder(Feeder):
|
|||||||
_account.default_lang_class))
|
_account.default_lang_class))
|
||||||
return result
|
return result
|
||||||
self.__logger.debug("Checking " + _account.name)
|
self.__logger.debug("Checking " + _account.name)
|
||||||
self.__logger.debug("\t" + _account.login \
|
self.__logger.debug("\t" + str(_account.login) \
|
||||||
+ "@" + _account.host)
|
+ "@" + str(_account.host))
|
||||||
_account.connect()
|
_account.connect()
|
||||||
mail_list = _account.get_new_mail_list()
|
mail_list = _account.get_new_mail_list()
|
||||||
default_lang_class = _account.default_lang_class
|
default_lang_class = _account.default_lang_class
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class IMAPAccountDiscoGetInfoHandler_TestCase(unittest.TestCase):
|
|||||||
disco_infos = handler.handle(None, Lang.en, "account@jmc.test.com/POP3",
|
disco_infos = handler.handle(None, Lang.en, "account@jmc.test.com/POP3",
|
||||||
None, None)
|
None, None)
|
||||||
self.assertTrue(disco_infos[0].has_feature("jabber:iq:register"))
|
self.assertTrue(disco_infos[0].has_feature("jabber:iq:register"))
|
||||||
self.assertTrue(disco_infos[0].has_feature("http://jabber.org/protocol/commands"))
|
self.assertFalse(disco_infos[0].has_feature("http://jabber.org/protocol/commands"))
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|||||||
@@ -52,6 +52,14 @@ def _get_default_status_msg(self, lang_class):
|
|||||||
return self.get_type() + "://" + self.login + "@" + self.host + ":" + \
|
return self.get_type() + "://" + self.login + "@" + self.host + ":" + \
|
||||||
unicode(self.port)
|
unicode(self.port)
|
||||||
|
|
||||||
|
def validate_password(password, default_func, bare_from_jid):
|
||||||
|
if password is None or password == "":
|
||||||
|
return None
|
||||||
|
return password
|
||||||
|
|
||||||
|
def validate_login(login, default_func, bare_from_jid):
|
||||||
|
return account.mandatory_field("login", login)
|
||||||
|
|
||||||
class MailAccount(PresenceAccount):
|
class MailAccount(PresenceAccount):
|
||||||
""" Wrapper to mail connection and action.
|
""" Wrapper to mail connection and action.
|
||||||
Abstract class, do not represent real mail connection type.
|
Abstract class, do not represent real mail connection type.
|
||||||
@@ -92,19 +100,13 @@ class MailAccount(PresenceAccount):
|
|||||||
"""
|
"""
|
||||||
See Account._get_register_fields
|
See Account._get_register_fields
|
||||||
"""
|
"""
|
||||||
def password_post_func(password, default_func, bare_from_jid):
|
|
||||||
if password is None or password == "":
|
|
||||||
return None
|
|
||||||
return password
|
|
||||||
|
|
||||||
if real_class is None:
|
if real_class is None:
|
||||||
real_class = cls
|
real_class = cls
|
||||||
return PresenceAccount.get_register_fields(real_class) + \
|
return PresenceAccount.get_register_fields(real_class) + \
|
||||||
[("login", "text-single", None,
|
[("login", "text-single", None,
|
||||||
lambda field_value, default_func, bare_from_jid: \
|
validate_login,
|
||||||
account.mandatory_field("login", field_value),
|
|
||||||
lambda bare_from_jid: ""),
|
lambda bare_from_jid: ""),
|
||||||
("password", "text-private", None, password_post_func,
|
("password", "text-private", None, validate_password,
|
||||||
lambda bare_from_jid: ""),
|
lambda bare_from_jid: ""),
|
||||||
("host", "text-single", None,
|
("host", "text-single", None,
|
||||||
lambda field_value, default_func, bare_from_jid: \
|
lambda field_value, default_func, bare_from_jid: \
|
||||||
@@ -310,8 +312,8 @@ class IMAPAccount(MailAccount):
|
|||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.__logger.debug("Connecting to IMAP server "
|
self.__logger.debug("Connecting to IMAP server "
|
||||||
+ self.login + "@" + self.host + ":" + str(self.port)
|
+ str(self.login) + "@" + str(self.host) + ":" + str(self.port)
|
||||||
+ " (" + self.mailbox + "). SSL="
|
+ " (" + str(self.mailbox) + "). SSL="
|
||||||
+ str(self.ssl))
|
+ str(self.ssl))
|
||||||
if self.ssl:
|
if self.ssl:
|
||||||
self.connection = imaplib.IMAP4_SSL(self.host, self.port)
|
self.connection = imaplib.IMAP4_SSL(self.host, self.port)
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ import thread
|
|||||||
|
|
||||||
from jcl.tests import JCLTestCase
|
from jcl.tests import JCLTestCase
|
||||||
import jcl.model as model
|
import jcl.model as model
|
||||||
|
from jcl.error import FieldError
|
||||||
from jcl.model.account import Account, PresenceAccount, User
|
from jcl.model.account import Account, PresenceAccount, User
|
||||||
|
import jmc.model.account
|
||||||
from jmc.model.account import MailAccount, POP3Account, IMAPAccount, \
|
from jmc.model.account import MailAccount, POP3Account, IMAPAccount, \
|
||||||
GlobalSMTPAccount, AbstractSMTPAccount, SMTPAccount
|
GlobalSMTPAccount, AbstractSMTPAccount, SMTPAccount
|
||||||
from jmc.lang import Lang
|
from jmc.lang import Lang
|
||||||
@@ -36,6 +38,11 @@ from jcl.model.tests.account import Account_TestCase, \
|
|||||||
ExampleAccount
|
ExampleAccount
|
||||||
from jmc.model.tests import email_generator, server
|
from jmc.model.tests import email_generator, server
|
||||||
|
|
||||||
|
class AccountModule_TestCase(unittest.TestCase):
|
||||||
|
def test_validate_login_with_empty_login(self):
|
||||||
|
self.assertRaises(FieldError, jmc.model.account.validate_login,
|
||||||
|
None, None, None)
|
||||||
|
|
||||||
class MailAccount_TestCase(PresenceAccount_TestCase):
|
class MailAccount_TestCase(PresenceAccount_TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
PresenceAccount_TestCase.setUp(self, tables=[MailAccount])
|
PresenceAccount_TestCase.setUp(self, tables=[MailAccount])
|
||||||
@@ -409,13 +416,13 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
self.server = server.DummyServer("localhost", 1143)
|
self.server = server.DummyServer("localhost", 1143)
|
||||||
thread.start_new_thread(self.server.serve, ())
|
thread.start_new_thread(self.server.serve, ())
|
||||||
self.server.responses = ["* OK [CAPABILITY IMAP4 LOGIN-REFERRALS " + \
|
self.server.responses = ["* OK [CAPABILITY IMAP4 LOGIN-REFERRALS " + \
|
||||||
"AUTH=PLAIN]\n", \
|
"AUTH=PLAIN]\r\n", \
|
||||||
lambda data: "* CAPABILITY IMAP4 " + \
|
lambda data: "* CAPABILITY IMAP4 " + \
|
||||||
"LOGIN-REFERRALS AUTH=PLAIN\n" + \
|
"LOGIN-REFERRALS AUTH=PLAIN\r\n" + \
|
||||||
data.split()[0] + \
|
data.split()[0] + \
|
||||||
" OK CAPABILITY completed\n", \
|
" OK CAPABILITY completed\r\n", \
|
||||||
lambda data: data.split()[0] + \
|
lambda data: data.split()[0] + \
|
||||||
" OK LOGIN completed\n"]
|
" OK LOGIN completed\r\n"]
|
||||||
if responses:
|
if responses:
|
||||||
self.server.responses += responses
|
self.server.responses += responses
|
||||||
self.server.queries = ["^[^ ]* CAPABILITY", \
|
self.server.queries = ["^[^ ]* CAPABILITY", \
|
||||||
@@ -506,13 +513,13 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
|
|
||||||
def test_get_new_mail_list(self):
|
def test_get_new_mail_list(self):
|
||||||
test_func = self.make_test(\
|
test_func = self.make_test(\
|
||||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||||
data.split()[0] + \
|
data.split()[0] + \
|
||||||
" OK [READ-WRITE] SELECT completed\n",
|
" OK [READ-WRITE] SELECT completed\r\n",
|
||||||
lambda data: "* SEARCH 9 10 \n" + \
|
lambda data: "* SEARCH 9 10\r\n" + \
|
||||||
data.split()[0] + " OK SEARCH completed\n"],
|
data.split()[0] + " OK SEARCH completed\r\n"],
|
||||||
["^[^ ]* SELECT INBOX",
|
["^[^ ]* SELECT INBOX",
|
||||||
"^[^ ]* SEARCH RECENT"],
|
"^[^ ]* SEARCH RECENT"],
|
||||||
lambda self: \
|
lambda self: \
|
||||||
@@ -531,11 +538,11 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
return
|
return
|
||||||
self.fail("No exception raised when selecting non existing mailbox")
|
self.fail("No exception raised when selecting non existing mailbox")
|
||||||
test_func = self.make_test(\
|
test_func = self.make_test(\
|
||||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||||
data.split()[0] + \
|
data.split()[0] + \
|
||||||
" NO Mailbox does not exist \n"],
|
" NO Mailbox does not exist\r\n"],
|
||||||
["^[^ ]* " + (readonly and "EXAMINE" or "SELECT") + " INBOX"],
|
["^[^ ]* " + (readonly and "EXAMINE" or "SELECT") + " INBOX"],
|
||||||
check_func)
|
check_func)
|
||||||
test_func()
|
test_func()
|
||||||
@@ -548,13 +555,13 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
self.imap_account.mailbox = "INBOX/dir1/subdir2"
|
self.imap_account.mailbox = "INBOX/dir1/subdir2"
|
||||||
self.imap_account.delimiter = "."
|
self.imap_account.delimiter = "."
|
||||||
test_func = self.make_test( \
|
test_func = self.make_test( \
|
||||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||||
data.split()[0] + \
|
data.split()[0] + \
|
||||||
" OK [READ-WRITE] SELECT completed\n",
|
" OK [READ-WRITE] SELECT completed\r\n",
|
||||||
lambda data: "* SEARCH 9 10 \n" + \
|
lambda data: "* SEARCH 9 10\r\n" + \
|
||||||
data.split()[0] + " OK SEARCH completed\n"],
|
data.split()[0] + " OK SEARCH completed\r\n"],
|
||||||
["^[^ ]* SELECT \"?INBOX\.dir1\.subdir2\"?",
|
["^[^ ]* SELECT \"?INBOX\.dir1\.subdir2\"?",
|
||||||
"^[^ ]* SEARCH RECENT"],
|
"^[^ ]* SEARCH RECENT"],
|
||||||
lambda self: \
|
lambda self: \
|
||||||
@@ -566,13 +573,13 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
self.imap_account.mailbox = "INBOX/dir1/subdir2"
|
self.imap_account.mailbox = "INBOX/dir1/subdir2"
|
||||||
self.imap_account.delimiter = "/"
|
self.imap_account.delimiter = "/"
|
||||||
test_func = self.make_test( \
|
test_func = self.make_test( \
|
||||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||||
data.split()[0] + \
|
data.split()[0] + \
|
||||||
" OK [READ-WRITE] SELECT completed\n",
|
" OK [READ-WRITE] SELECT completed\r\n",
|
||||||
lambda data: "* SEARCH 9 10 \n" + \
|
lambda data: "* SEARCH 9 10\r\n" + \
|
||||||
data.split()[0] + " OK SEARCH completed\n"],
|
data.split()[0] + " OK SEARCH completed\r\n"],
|
||||||
["^[^ ]* SELECT \"?INBOX/dir1/subdir2\"?",
|
["^[^ ]* SELECT \"?INBOX/dir1/subdir2\"?",
|
||||||
"^[^ ]* SEARCH RECENT"],
|
"^[^ ]* SEARCH RECENT"],
|
||||||
lambda self: \
|
lambda self: \
|
||||||
@@ -612,11 +619,11 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
return
|
return
|
||||||
self.fail("No exception raised when selecting non existing mailbox")
|
self.fail("No exception raised when selecting non existing mailbox")
|
||||||
test_func = self.make_test(\
|
test_func = self.make_test(\
|
||||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||||
data.split()[0] + \
|
data.split()[0] + \
|
||||||
" NO Mailbox does not exist \n"],
|
" NO Mailbox does not exist\r\n"],
|
||||||
["^[^ ]* SELECT INBOX"],
|
["^[^ ]* SELECT INBOX"],
|
||||||
check_func)
|
check_func)
|
||||||
test_func()
|
test_func()
|
||||||
@@ -1109,6 +1116,7 @@ class SMTPAccount_TestCase(Account_TestCase):
|
|||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
suite.addTest(unittest.makeSuite(AccountModule_TestCase, 'test'))
|
||||||
suite.addTest(unittest.makeSuite(MailAccount_TestCase, 'test'))
|
suite.addTest(unittest.makeSuite(MailAccount_TestCase, 'test'))
|
||||||
suite.addTest(unittest.makeSuite(POP3Account_TestCase, 'test'))
|
suite.addTest(unittest.makeSuite(POP3Account_TestCase, 'test'))
|
||||||
suite.addTest(unittest.makeSuite(IMAPAccount_TestCase, 'test'))
|
suite.addTest(unittest.makeSuite(IMAPAccount_TestCase, 'test'))
|
||||||
|
|||||||
Reference in New Issue
Block a user