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 <dax@happycoders.org>2008-05-09 20:25:47 +0400
committerDavid Rousselie <dax@happycoders.org>2008-05-09 20:25:47 +0400
commit885f08b93ecad0107e5069fe53117cda1f661a5e (patch)
tree74477578d0d374d19f7a26befb93b853e8c500c4
parent9f52f9ed7ead6c81cc56d5b19b40e7537d7e37be (diff)
Add default status message to SMTPAccount
darcs-hash:20080509162547-86b55-5704b15905df146b6195487a37412ffe78a03610.gz
-rw-r--r--src/jmc/model/account.py19
-rw-r--r--src/jmc/model/tests/account.py343
2 files changed, 222 insertions, 140 deletions
diff --git a/src/jmc/model/account.py b/src/jmc/model/account.py
index ce32b7a..29b2470 100644
--- a/src/jmc/model/account.py
+++ b/src/jmc/model/account.py
@@ -142,6 +142,10 @@ class MYPOP3_SSL(poplib.POP3_SSL):
self._debugging = 0
self.welcome = self._getresp()
+def _get_default_status_msg(self, lang_class):
+ return self.get_type() + "://" + self.login + "@" + self.host + ":" + \
+ unicode(self.port)
+
class MailAccount(PresenceAccount):
""" Wrapper to mail connection and action.
Abstract class, do not represent real mail connection type.
@@ -240,6 +244,8 @@ class MailAccount(PresenceAccount):
get_presence_actions_fields = classmethod(_get_presence_actions_fields)
+ get_default_status_msg = _get_default_status_msg
+
def set_status(self, status):
"""Set current Jabber status"""
@@ -323,10 +329,6 @@ class MailAccount(PresenceAccount):
def format_message_summary(self, email_msg):
return self.format_message(email_msg, False)
- def get_default_status_msg(self, lang_class):
- return self.get_type() + "://" + self.login + "@" + self.host + ":" + \
- unicode(self.port)
-
def connect(self):
raise NotImplementedError
@@ -782,6 +784,15 @@ class SMTPAccount(Account):
get_register_fields = classmethod(_get_register_fields)
+ get_default_status_msg = _get_default_status_msg
+
+ def get_type(self):
+ if self.tls:
+ return "smtps"
+ return "smtp"
+
+ type = property(get_type)
+
def create_email(self, from_email, to_email, subject, body, other_headers=None):
"""Create new email"""
_email = MIMEText(body)
diff --git a/src/jmc/model/tests/account.py b/src/jmc/model/tests/account.py
index 09d85ac..6c07237 100644
--- a/src/jmc/model/tests/account.py
+++ b/src/jmc/model/tests/account.py
@@ -28,6 +28,7 @@ from jcl.tests import JCLTestCase
import jcl.model as model
from jcl.model.account import Account, PresenceAccount, User
from jmc.model.account import MailAccount, POP3Account, IMAPAccount, SMTPAccount
+from jmc.lang import Lang
from jcl.model.tests.account import Account_TestCase, \
PresenceAccount_TestCase, InheritableAccount_TestCase, \
@@ -128,6 +129,18 @@ class MailAccount_TestCase(PresenceAccount_TestCase):
u"Encoded multipart3 with no charset (éàê)\n",
u"encoded from (éàê)"))
+ def test_get_default_status_msg(self):
+ """
+ Get default status message for MailAccount.
+ Should raise NotImplementedError because get_type() method
+ is not implemented
+ """
+ try:
+ self.account.get_default_status_msg(Lang.en)
+ except NotImplementedError:
+ return
+ fail("No NotImplementedError raised")
+
class POP3Account_TestCase(InheritableAccount_TestCase):
def setUp(self):
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
@@ -361,6 +374,21 @@ class POP3Account_TestCase(InheritableAccount_TestCase):
self.assertEquals(result, [5])
self.assertEquals(self.pop3_account.lastmail, 5)
+ def test_get_default_status_msg(self):
+ """
+ Get default status message for POP3Account.
+ """
+ status_msg = self.pop3_account.get_default_status_msg(Lang.en)
+ self.assertEquals(status_msg, "pop3://login@localhost:1110")
+
+ def test_get_default_status_msg_ssl(self):
+ """
+ Get default status message for SSL POP3Account.
+ """
+ self.pop3_account.ssl = True
+ status_msg = self.pop3_account.get_default_status_msg(Lang.en)
+ self.assertEquals(status_msg, "pop3s://login@localhost:1110")
+
class IMAPAccount_TestCase(InheritableAccount_TestCase):
def setUp(self):
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
@@ -752,6 +780,21 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
mail_list = [1, 2, 3, 4]
self.check_get_next_mail_index(mail_list)
+ def test_get_default_status_msg(self):
+ """
+ Get default status message for IMAPAccount.
+ """
+ status_msg = self.imap_account.get_default_status_msg(Lang.en)
+ self.assertEquals(status_msg, "imap://login@localhost:1143")
+
+ def test_get_default_status_msg_ssl(self):
+ """
+ Get default status message for SSL IMAPAccount.
+ """
+ self.imap_account.ssl = True
+ status_msg = self.imap_account.get_default_status_msg(Lang.en)
+ self.assertEquals(status_msg, "imaps://login@localhost:1143")
+
class SMTPAccount_TestCase(Account_TestCase):
def setUp(self):
JCLTestCase.setUp(self, tables=[Account, ExampleAccount, User,
@@ -876,153 +919,181 @@ class SMTPAccount_TestCase(Account_TestCase):
return inner
def test_send_email_esmtp_no_auth(self):
- model.db_connect()
- smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
- name="account11",
- jid="account11@jmc.test.com")
- smtp_account.host = "localhost"
- smtp_account.port = 1025
- model.db_disconnect()
- email = smtp_account.create_email("from@test.com",
- "to@test.com",
- "subject",
- "body")
- test_func = self.make_test(["220 localhost ESMTP\r\n",
- "250-localhost Hello 127.0.0.1\r\n"
- + "250-SIZE 52428800\r\n"
- + "250-PIPELINING\r\n"
- + "250 HELP\r\n",
- "250 OK\r\n",
- "250 Accepted\r\n",
- "354 Enter message\r\n",
- None, None, None, None,
- None, None, None, None,
- "250 OK\r\n"],
- ["ehlo \[127.0...1\]\r\n",
- "mail FROM:<" + str(email['From']) + ">.*",
- "rcpt TO:<" + str(email['To']) + ">\r\n",
- "data\r\n"] +
+ model.db_connect()
+ smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
+ name="account11",
+ jid="account11@jmc.test.com")
+ smtp_account.host = "localhost"
+ smtp_account.port = 1025
+ model.db_disconnect()
+ email = smtp_account.create_email("from@test.com",
+ "to@test.com",
+ "subject",
+ "body")
+ test_func = self.make_test(["220 localhost ESMTP\r\n",
+ "250-localhost Hello 127.0.0.1\r\n"
+ + "250-SIZE 52428800\r\n"
+ + "250-PIPELINING\r\n"
+ + "250 HELP\r\n",
+ "250 OK\r\n",
+ "250 Accepted\r\n",
+ "354 Enter message\r\n",
+ None, None, None, None,
+ None, None, None, None,
+ "250 OK\r\n"],
+ ["ehlo \[127.0...1\]\r\n",
+ "mail FROM:<" + str(email['From']) + ">.*",
+ "rcpt TO:<" + str(email['To']) + ">\r\n",
+ "data\r\n"] +
email.as_string().split("\n") + [".\r\n"],
- lambda self: \
- smtp_account.send_email(email))
- test_func()
+ lambda self: \
+ smtp_account.send_email(email))
+ test_func()
def test_send_email_no_auth(self):
- model.db_connect()
- smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
- name="account11",
- jid="account11@jmc.test.com")
- smtp_account.host = "localhost"
- smtp_account.port = 1025
- model.db_disconnect()
- email = smtp_account.create_email("from@test.com",
- "to@test.com",
- "subject",
- "body")
- test_func = self.make_test(["220 localhost SMTP\r\n",
- "504 ESMTP not supported\r\n",
- "250-localhost Hello 127.0.0.1\r\n"
- + "250-SIZE 52428800\r\n"
- + "250-PIPELINING\r\n"
- + "250 HELP\r\n",
- "250 OK\r\n",
- "250 Accepted\r\n",
- "354 Enter message\r\n",
- None, None, None, None,
- None, None, None, None,
- "250 OK\r\n"],
- ["ehlo \[127.0...1\]\r\n",
- "helo \[127.0...1\]\r\n",
- "mail FROM:<" + str(email['From']) + ">.*",
- "rcpt TO:<" + str(email['To']) + ">\r\n",
- "data\r\n"] +
+ model.db_connect()
+ smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
+ name="account11",
+ jid="account11@jmc.test.com")
+ smtp_account.host = "localhost"
+ smtp_account.port = 1025
+ model.db_disconnect()
+ email = smtp_account.create_email("from@test.com",
+ "to@test.com",
+ "subject",
+ "body")
+ test_func = self.make_test(["220 localhost SMTP\r\n",
+ "504 ESMTP not supported\r\n",
+ "250-localhost Hello 127.0.0.1\r\n"
+ + "250-SIZE 52428800\r\n"
+ + "250-PIPELINING\r\n"
+ + "250 HELP\r\n",
+ "250 OK\r\n",
+ "250 Accepted\r\n",
+ "354 Enter message\r\n",
+ None, None, None, None,
+ None, None, None, None,
+ "250 OK\r\n"],
+ ["ehlo \[127.0...1\]\r\n",
+ "helo \[127.0...1\]\r\n",
+ "mail FROM:<" + str(email['From']) + ">.*",
+ "rcpt TO:<" + str(email['To']) + ">\r\n",
+ "data\r\n"] +
email.as_string().split("\n") + [".\r\n"],
- lambda self: \
- smtp_account.send_email(email))
- test_func()
+ lambda self: \
+ smtp_account.send_email(email))
+ test_func()
def test_send_email_esmtp_auth(self):
- model.db_connect()
- smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
- name="account11",
- jid="account11@jmc.test.com")
- smtp_account.host = "localhost"
- smtp_account.port = 1025
- smtp_account.login = "user"
- smtp_account.password = "pass"
- model.db_disconnect()
- email = smtp_account.create_email("from@test.com",
- "to@test.com",
- "subject",
- "body")
- test_func = self.make_test(["220 localhost ESMTP\r\n",
- "250-localhost Hello 127.0.0.1\r\n"
- + "250-SIZE 52428800\r\n"
- + "250-AUTH PLAIN LOGIN CRAM-MD5\r\n"
- + "250-PIPELINING\r\n"
- + "250 HELP\r\n",
- "334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n",
- "235 Authentication succeeded\r\n",
- "250 OK\r\n",
- "250 Accepted\r\n",
- "354 Enter message\r\n",
- None, None, None, None,
- None, None, None, None,
- "250 OK\r\n"],
- ["ehlo \[127.0...1\]\r\n",
- "AUTH CRAM-MD5\r\n",
- ".*\r\n",
- "mail FROM:<" + str(email['From']) + ">.*",
- "rcpt TO:<" + str(email['To']) + ">\r\n",
- "data\r\n"] +
+ model.db_connect()
+ smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
+ name="account11",
+ jid="account11@jmc.test.com")
+ smtp_account.host = "localhost"
+ smtp_account.port = 1025
+ smtp_account.login = "user"
+ smtp_account.password = "pass"
+ model.db_disconnect()
+ email = smtp_account.create_email("from@test.com",
+ "to@test.com",
+ "subject",
+ "body")
+ test_func = self.make_test(["220 localhost ESMTP\r\n",
+ "250-localhost Hello 127.0.0.1\r\n"
+ + "250-SIZE 52428800\r\n"
+ + "250-AUTH PLAIN LOGIN CRAM-MD5\r\n"
+ + "250-PIPELINING\r\n"
+ + "250 HELP\r\n",
+ "334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n",
+ "235 Authentication succeeded\r\n",
+ "250 OK\r\n",
+ "250 Accepted\r\n",
+ "354 Enter message\r\n",
+ None, None, None, None,
+ None, None, None, None,
+ "250 OK\r\n"],
+ ["ehlo \[127.0...1\]\r\n",
+ "AUTH CRAM-MD5\r\n",
+ ".*\r\n",
+ "mail FROM:<" + str(email['From']) + ">.*",
+ "rcpt TO:<" + str(email['To']) + ">\r\n",
+ "data\r\n"] +
email.as_string().split("\n") + [".\r\n"],
- lambda self: \
- smtp_account.send_email(email))
- test_func()
+ lambda self: \
+ smtp_account.send_email(email))
+ test_func()
def test_send_email_esmtp_auth_method2(self):
- model.db_connect()
- smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
- name="account11",
- jid="account11@jmc.test.com")
- smtp_account.host = "localhost"
- smtp_account.port = 1025
- smtp_account.login = "user"
- smtp_account.password = "pass"
- model.db_disconnect()
- email = smtp_account.create_email("from@test.com",
- "to@test.com",
- "subject",
- "body")
- test_func = self.make_test(["220 localhost ESMTP\r\n",
- "250-localhost Hello 127.0.0.1\r\n"
- + "250-SIZE 52428800\r\n"
- + "250-AUTH PLAIN LOGIN CRAM-MD5\r\n"
- + "250-PIPELINING\r\n"
- + "250 HELP\r\n",
- "334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n",
- "535 Incorrect Authentication data\r\n",
- "334 asd235r4\r\n",
- "235 Authentication succeeded\r\n",
- "250 OK\r\n",
- "250 Accepted\r\n",
- "354 Enter message\r\n",
- None, None, None, None,
- None, None, None, None,
- "250 OK\r\n"],
- ["ehlo \[127.0...1\]\r\n",
- "AUTH CRAM-MD5\r\n",
- ".*\r\n",
- "AUTH LOGIN .*\r\n",
- ".*\r\n",
- "mail FROM:<" + str(email['From']) + ">.*",
- "rcpt TO:<" + str(email['To']) + ">\r\n",
- "data\r\n"] +
+ model.db_connect()
+ smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
+ name="account11",
+ jid="account11@jmc.test.com")
+ smtp_account.host = "localhost"
+ smtp_account.port = 1025
+ smtp_account.login = "user"
+ smtp_account.password = "pass"
+ model.db_disconnect()
+ email = smtp_account.create_email("from@test.com",
+ "to@test.com",
+ "subject",
+ "body")
+ test_func = self.make_test(["220 localhost ESMTP\r\n",
+ "250-localhost Hello 127.0.0.1\r\n"
+ + "250-SIZE 52428800\r\n"
+ + "250-AUTH PLAIN LOGIN CRAM-MD5\r\n"
+ + "250-PIPELINING\r\n"
+ + "250 HELP\r\n",
+ "334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n",
+ "535 Incorrect Authentication data\r\n",
+ "334 asd235r4\r\n",
+ "235 Authentication succeeded\r\n",
+ "250 OK\r\n",
+ "250 Accepted\r\n",
+ "354 Enter message\r\n",
+ None, None, None, None,
+ None, None, None, None,
+ "250 OK\r\n"],
+ ["ehlo \[127.0...1\]\r\n",
+ "AUTH CRAM-MD5\r\n",
+ ".*\r\n",
+ "AUTH LOGIN .*\r\n",
+ ".*\r\n",
+ "mail FROM:<" + str(email['From']) + ">.*",
+ "rcpt TO:<" + str(email['To']) + ">\r\n",
+ "data\r\n"] +
email.as_string().split("\n") + [".\r\n"],
- lambda self: \
- smtp_account.send_email(email))
- test_func()
+ lambda self: \
+ smtp_account.send_email(email))
+ test_func()
+ def test_get_default_status_msg(self):
+ """
+ Get default status message for IMAPAccount.
+ """
+ smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
+ name="account11",
+ jid="account11@jmc.test.com")
+ smtp_account.host = "localhost"
+ smtp_account.port = 1025
+ smtp_account.login = "user"
+ smtp_account.password = "pass"
+ status_msg = smtp_account.get_default_status_msg(Lang.en)
+ self.assertEquals(status_msg, "smtp://user@localhost:1025")
+
+ def test_get_default_status_msg_ssl(self):
+ """
+ Get default status message for SSL IMAPAccount.
+ """
+ smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
+ name="account11",
+ jid="account11@jmc.test.com")
+ smtp_account.host = "localhost"
+ smtp_account.port = 1025
+ smtp_account.login = "user"
+ smtp_account.password = "pass"
+ smtp_account.tls = True
+ status_msg = smtp_account.get_default_status_msg(Lang.en)
+ self.assertEquals(status_msg, "smtps://user@localhost:1025")
def suite():
suite = unittest.TestSuite()