Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dax/jmc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rousselie <david.rousselie@happycoders.org>2010-06-04 09:35:24 +0400
committerDavid Rousselie <david.rousselie@happycoders.org>2010-06-04 09:35:24 +0400
commita26290d9c4bee14ae6a5f76b95196fe7aaa03cb2 (patch)
treeafa86764faca78814c6c9ed46b64436708dc653e
parent76adc75d9f7385d4d69cc453c54696f898f61605 (diff)
fix tests with python2.6
-rw-r--r--.gitignore1
-rw-r--r--src/jmc/jabber/disco.py11
-rw-r--r--src/jmc/jabber/feeder.py4
-rw-r--r--src/jmc/jabber/tests/disco.py2
-rw-r--r--src/jmc/model/account.py22
-rw-r--r--src/jmc/model/tests/account.py68
6 files changed, 60 insertions, 48 deletions
diff --git a/.gitignore b/.gitignore
index 2b0a5c7..e6a85b5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
.coverage
*flymake.py
.ropeproject
+*.pyc
diff --git a/src/jmc/jabber/disco.py b/src/jmc/jabber/disco.py
index b97c301..6735960 100644
--- a/src/jmc/jabber/disco.py
+++ b/src/jmc/jabber/disco.py
@@ -3,18 +3,18 @@
## Login : David Rousselie <dax@happycoders.org>
## Started on Sun Jul 8 20:55:46 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
@@ -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 []
-
diff --git a/src/jmc/jabber/feeder.py b/src/jmc/jabber/feeder.py
index 6e5ada0..f271af3 100644
--- a/src/jmc/jabber/feeder.py
+++ b/src/jmc/jabber/feeder.py
@@ -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
diff --git a/src/jmc/jabber/tests/disco.py b/src/jmc/jabber/tests/disco.py
index fc8ba54..5fb305c 100644
--- a/src/jmc/jabber/tests/disco.py
+++ b/src/jmc/jabber/tests/disco.py
@@ -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()
diff --git a/src/jmc/model/account.py b/src/jmc/model/account.py
index 9d79695..d67cee5 100644
--- a/src/jmc/model/account.py
+++ b/src/jmc/model/account.py
@@ -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)
diff --git a/src/jmc/model/tests/account.py b/src/jmc/model/tests/account.py
index fb2ec33..1fde245 100644
--- a/src/jmc/model/tests/account.py
+++ b/src/jmc/model/tests/account.py
@@ -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'))