Add default status message to SMTPAccount
darcs-hash:20080509162547-86b55-5704b15905df146b6195487a37412ffe78a03610.gz
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
@@ -1023,6 +1066,34 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user