fix tests with python2.6
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.coverage
|
||||
*flymake.py
|
||||
.ropeproject
|
||||
*.pyc
|
||||
|
||||
@@ -61,7 +61,9 @@ class IMAPAccountDiscoGetInfoHandler(AccountDiscoGetInfoHandler):
|
||||
lang_class,
|
||||
node, disco_obj,
|
||||
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_len = len(splitted_node)
|
||||
if splitted_node_len > 1 and \
|
||||
@@ -125,4 +127,3 @@ class IMAPAccountDiscoGetItemsHandler(DiscoHandler):
|
||||
subdir)
|
||||
return [disco_items]
|
||||
return []
|
||||
|
||||
|
||||
@@ -105,8 +105,8 @@ class MailFeeder(Feeder):
|
||||
_account.default_lang_class))
|
||||
return result
|
||||
self.__logger.debug("Checking " + _account.name)
|
||||
self.__logger.debug("\t" + _account.login \
|
||||
+ "@" + _account.host)
|
||||
self.__logger.debug("\t" + str(_account.login) \
|
||||
+ "@" + str(_account.host))
|
||||
_account.connect()
|
||||
mail_list = _account.get_new_mail_list()
|
||||
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",
|
||||
None, None)
|
||||
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():
|
||||
suite = unittest.TestSuite()
|
||||
|
||||
@@ -52,6 +52,14 @@ def _get_default_status_msg(self, lang_class):
|
||||
return self.get_type() + "://" + self.login + "@" + self.host + ":" + \
|
||||
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):
|
||||
""" Wrapper to mail connection and action.
|
||||
Abstract class, do not represent real mail connection type.
|
||||
@@ -92,19 +100,13 @@ class MailAccount(PresenceAccount):
|
||||
"""
|
||||
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:
|
||||
real_class = cls
|
||||
return PresenceAccount.get_register_fields(real_class) + \
|
||||
[("login", "text-single", None,
|
||||
lambda field_value, default_func, bare_from_jid: \
|
||||
account.mandatory_field("login", field_value),
|
||||
validate_login,
|
||||
lambda bare_from_jid: ""),
|
||||
("password", "text-private", None, password_post_func,
|
||||
("password", "text-private", None, validate_password,
|
||||
lambda bare_from_jid: ""),
|
||||
("host", "text-single", None,
|
||||
lambda field_value, default_func, bare_from_jid: \
|
||||
@@ -310,8 +312,8 @@ class IMAPAccount(MailAccount):
|
||||
|
||||
def connect(self):
|
||||
self.__logger.debug("Connecting to IMAP server "
|
||||
+ self.login + "@" + self.host + ":" + str(self.port)
|
||||
+ " (" + self.mailbox + "). SSL="
|
||||
+ str(self.login) + "@" + str(self.host) + ":" + str(self.port)
|
||||
+ " (" + str(self.mailbox) + "). SSL="
|
||||
+ str(self.ssl))
|
||||
if self.ssl:
|
||||
self.connection = imaplib.IMAP4_SSL(self.host, self.port)
|
||||
|
||||
@@ -26,7 +26,9 @@ import thread
|
||||
|
||||
from jcl.tests import JCLTestCase
|
||||
import jcl.model as model
|
||||
from jcl.error import FieldError
|
||||
from jcl.model.account import Account, PresenceAccount, User
|
||||
import jmc.model.account
|
||||
from jmc.model.account import MailAccount, POP3Account, IMAPAccount, \
|
||||
GlobalSMTPAccount, AbstractSMTPAccount, SMTPAccount
|
||||
from jmc.lang import Lang
|
||||
@@ -36,6 +38,11 @@ from jcl.model.tests.account import Account_TestCase, \
|
||||
ExampleAccount
|
||||
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):
|
||||
def setUp(self):
|
||||
PresenceAccount_TestCase.setUp(self, tables=[MailAccount])
|
||||
@@ -409,13 +416,13 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||
self.server = server.DummyServer("localhost", 1143)
|
||||
thread.start_new_thread(self.server.serve, ())
|
||||
self.server.responses = ["* OK [CAPABILITY IMAP4 LOGIN-REFERRALS " + \
|
||||
"AUTH=PLAIN]\n", \
|
||||
"AUTH=PLAIN]\r\n", \
|
||||
lambda data: "* CAPABILITY IMAP4 " + \
|
||||
"LOGIN-REFERRALS AUTH=PLAIN\n" + \
|
||||
"LOGIN-REFERRALS AUTH=PLAIN\r\n" + \
|
||||
data.split()[0] + \
|
||||
" OK CAPABILITY completed\n", \
|
||||
" OK CAPABILITY completed\r\n", \
|
||||
lambda data: data.split()[0] + \
|
||||
" OK LOGIN completed\n"]
|
||||
" OK LOGIN completed\r\n"]
|
||||
if responses:
|
||||
self.server.responses += responses
|
||||
self.server.queries = ["^[^ ]* CAPABILITY", \
|
||||
@@ -506,13 +513,13 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||
|
||||
def test_get_new_mail_list(self):
|
||||
test_func = self.make_test(\
|
||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
||||
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||
data.split()[0] + \
|
||||
" OK [READ-WRITE] SELECT completed\n",
|
||||
lambda data: "* SEARCH 9 10 \n" + \
|
||||
data.split()[0] + " OK SEARCH completed\n"],
|
||||
" OK [READ-WRITE] SELECT completed\r\n",
|
||||
lambda data: "* SEARCH 9 10\r\n" + \
|
||||
data.split()[0] + " OK SEARCH completed\r\n"],
|
||||
["^[^ ]* SELECT INBOX",
|
||||
"^[^ ]* SEARCH RECENT"],
|
||||
lambda self: \
|
||||
@@ -531,11 +538,11 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||
return
|
||||
self.fail("No exception raised when selecting non existing mailbox")
|
||||
test_func = self.make_test(\
|
||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
||||
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||
data.split()[0] + \
|
||||
" NO Mailbox does not exist \n"],
|
||||
" NO Mailbox does not exist\r\n"],
|
||||
["^[^ ]* " + (readonly and "EXAMINE" or "SELECT") + " INBOX"],
|
||||
check_func)
|
||||
test_func()
|
||||
@@ -548,13 +555,13 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||
self.imap_account.mailbox = "INBOX/dir1/subdir2"
|
||||
self.imap_account.delimiter = "."
|
||||
test_func = self.make_test( \
|
||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
||||
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||
data.split()[0] + \
|
||||
" OK [READ-WRITE] SELECT completed\n",
|
||||
lambda data: "* SEARCH 9 10 \n" + \
|
||||
data.split()[0] + " OK SEARCH completed\n"],
|
||||
" OK [READ-WRITE] SELECT completed\r\n",
|
||||
lambda data: "* SEARCH 9 10\r\n" + \
|
||||
data.split()[0] + " OK SEARCH completed\r\n"],
|
||||
["^[^ ]* SELECT \"?INBOX\.dir1\.subdir2\"?",
|
||||
"^[^ ]* SEARCH RECENT"],
|
||||
lambda self: \
|
||||
@@ -566,13 +573,13 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||
self.imap_account.mailbox = "INBOX/dir1/subdir2"
|
||||
self.imap_account.delimiter = "/"
|
||||
test_func = self.make_test( \
|
||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
||||
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||
data.split()[0] + \
|
||||
" OK [READ-WRITE] SELECT completed\n",
|
||||
lambda data: "* SEARCH 9 10 \n" + \
|
||||
data.split()[0] + " OK SEARCH completed\n"],
|
||||
" OK [READ-WRITE] SELECT completed\r\n",
|
||||
lambda data: "* SEARCH 9 10\r\n" + \
|
||||
data.split()[0] + " OK SEARCH completed\r\n"],
|
||||
["^[^ ]* SELECT \"?INBOX/dir1/subdir2\"?",
|
||||
"^[^ ]* SEARCH RECENT"],
|
||||
lambda self: \
|
||||
@@ -612,11 +619,11 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||
return
|
||||
self.fail("No exception raised when selecting non existing mailbox")
|
||||
test_func = self.make_test(\
|
||||
[lambda data: "* 42 EXISTS\n* 1 RECENT\n* OK" + \
|
||||
" [UNSEEN 9]\n* FLAGS (\Deleted \Seen\*)\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\n" + \
|
||||
[lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" + \
|
||||
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" + \
|
||||
" OK [PERMANENTFLAGS (\Deleted \Seen\*)\r\n" + \
|
||||
data.split()[0] + \
|
||||
" NO Mailbox does not exist \n"],
|
||||
" NO Mailbox does not exist\r\n"],
|
||||
["^[^ ]* SELECT INBOX"],
|
||||
check_func)
|
||||
test_func()
|
||||
@@ -1109,6 +1116,7 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(unittest.makeSuite(AccountModule_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(MailAccount_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(POP3Account_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(IMAPAccount_TestCase, 'test'))
|
||||
|
||||
Reference in New Issue
Block a user