update JMC after JCL refactoring
darcs-hash:20070819134452-86b55-500fe3139f8cb4901bc2f283340b5a1768125d8d.gz
This commit is contained in:
@@ -4,7 +4,7 @@ __revision__ = ""
|
||||
import re
|
||||
|
||||
from jcl.jabber import Handler
|
||||
from jcl.model.account import Account
|
||||
import jcl.model.account as account
|
||||
|
||||
from jmc.model.account import NoAccountError, SMTPAccount
|
||||
|
||||
@@ -20,7 +20,7 @@ class MailHandler(Handler):
|
||||
node = stanza.get_to().node
|
||||
if node is not None and self.dest_jid_regexp.match(node):
|
||||
bare_from_jid = unicode(stanza.get_from().bare())
|
||||
accounts = Account.select(Account.q.user_jid == bare_from_jid)
|
||||
accounts = account.get_accounts(bare_from_jid, SMTPAccount)
|
||||
if accounts.count() == 0:
|
||||
raise NoAccountError()
|
||||
else:
|
||||
|
||||
@@ -26,6 +26,7 @@ import logging
|
||||
from pyxmpp.jid import JID
|
||||
|
||||
import jcl.jabber as jabber
|
||||
from jcl.model import account
|
||||
from jcl.model.account import PresenceAccount
|
||||
from jcl.jabber.disco import RootDiscoGetInfoHandler
|
||||
from jcl.jabber.feeder import FeederComponent, Feeder, MessageSender, \
|
||||
@@ -48,6 +49,8 @@ class MailComponent(FeederComponent):
|
||||
secret,
|
||||
server,
|
||||
port,
|
||||
config,
|
||||
config_file,
|
||||
lang=Lang()):
|
||||
"""Use FeederComponent behavior and setup feeder and sender
|
||||
attributes.
|
||||
@@ -57,6 +60,8 @@ class MailComponent(FeederComponent):
|
||||
secret,
|
||||
server,
|
||||
port,
|
||||
config,
|
||||
config_file,
|
||||
lang=lang)
|
||||
self.handler = MailFeederHandler(MailFeeder(self), MailSender(self))
|
||||
self.account_manager.account_classes = (IMAPAccount,
|
||||
@@ -213,5 +218,5 @@ class MailFeederHandler(FeederHandler):
|
||||
def filter(self, stanza, lang_class):
|
||||
"""Return only email account type to check mail from
|
||||
"""
|
||||
accounts = MailAccount.select(orderBy="user_jid")
|
||||
accounts = account.get_all_accounts(account_class=MailAccount)
|
||||
return accounts
|
||||
|
||||
@@ -23,10 +23,9 @@
|
||||
import logging
|
||||
import re
|
||||
|
||||
from sqlobject.sqlbuilder import AND
|
||||
|
||||
from pyxmpp.message import Message
|
||||
|
||||
from jcl.model import account
|
||||
from jmc.jabber import MailHandler
|
||||
from jmc.model.account import SMTPAccount
|
||||
|
||||
@@ -64,17 +63,17 @@ class RootSendMailMessageHandler(SendMailMessageHandler):
|
||||
"jmc.jabber.component.RootSendMailMessageHandler")
|
||||
|
||||
def filter(self, stanza, lang_class):
|
||||
name = stanza.get_to().node
|
||||
bare_from_jid = unicode(stanza.get_from().bare())
|
||||
accounts = SMTPAccount.select(\
|
||||
AND(SMTPAccount.q.default_account == True,
|
||||
SMTPAccount.q.user_jid == bare_from_jid))
|
||||
accounts = account.get_accounts(\
|
||||
bare_from_jid,
|
||||
account_class=SMTPAccount,
|
||||
filter=(SMTPAccount.q.default_account == True))
|
||||
if accounts.count() != 1:
|
||||
self.__logger.error("No default account found for user " +
|
||||
str(bare_from_jid))
|
||||
if accounts.count() == 0:
|
||||
accounts = SMTPAccount.select(\
|
||||
SMTPAccount.q.user_jid == bare_from_jid)
|
||||
accounts = account.get_accounts(bare_from_jid,
|
||||
SMTPAccount)
|
||||
return accounts
|
||||
|
||||
def handle(self, stanza, lang_class, data):
|
||||
|
||||
@@ -32,9 +32,10 @@ from sqlobject.dbconnection import TheURIOpener
|
||||
from pyxmpp.presence import Presence
|
||||
from pyxmpp.message import Message
|
||||
|
||||
from jcl.tests import JCLTestCase
|
||||
import jcl.model as model
|
||||
from jcl.model import account
|
||||
from jcl.model.account import Account, PresenceAccount, LegacyJID
|
||||
from jcl.model.account import Account, PresenceAccount, LegacyJID, User
|
||||
from jcl.jabber.tests.presence import DefaultSubscribeHandler_TestCase, \
|
||||
DefaultUnsubscribeHandler_TestCase
|
||||
from jcl.jabber.tests.feeder import FeederMock, SenderMock
|
||||
@@ -150,6 +151,7 @@ class MockPOP3Account(MockMailAccount, POP3Account):
|
||||
class MockSMTPAccount(object):
|
||||
def __init__(self):
|
||||
self.default_from = "user1@test.com"
|
||||
self.email = None
|
||||
|
||||
def create_email(self, from_email, to_email, subject, body):
|
||||
return (from_email, to_email, subject, body)
|
||||
@@ -157,50 +159,27 @@ class MockSMTPAccount(object):
|
||||
def send_email(self, email):
|
||||
self.email = email
|
||||
|
||||
class MailComponent_TestCase(unittest.TestCase):
|
||||
class MailComponent_TestCase(JCLTestCase):
|
||||
def setUp(self):
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
|
||||
MailAccount, IMAPAccount, POP3Account,
|
||||
SMTPAccount, MockIMAPAccount,
|
||||
MockPOP3Account])
|
||||
self.comp = MailComponent("jmc.test.com",
|
||||
"password",
|
||||
"localhost",
|
||||
"5347")
|
||||
"5347",
|
||||
None,
|
||||
None)
|
||||
self.comp.stream = MockStream()
|
||||
self.comp.stream_class = MockStream
|
||||
model.db_connection_str = 'sqlite://' + DB_URL
|
||||
model.db_connect()
|
||||
Account.createTable(ifNotExists=True)
|
||||
PresenceAccount.createTable(ifNotExists=True)
|
||||
MailAccount.createTable(ifNotExists=True)
|
||||
IMAPAccount.createTable(ifNotExists=True)
|
||||
POP3Account.createTable(ifNotExists=True)
|
||||
SMTPAccount.createTable(ifNotExists=True)
|
||||
MockIMAPAccount.createTable(ifNotExists=True)
|
||||
MockPOP3Account.createTable(ifNotExists=True)
|
||||
model.db_disconnect()
|
||||
|
||||
def tearDown(self):
|
||||
model.db_connect()
|
||||
MockPOP3Account.dropTable(ifExists=True)
|
||||
MockIMAPAccount.dropTable(ifExists=True)
|
||||
SMTPAccount.dropTable(ifExists=True)
|
||||
POP3Account.dropTable(ifExists=True)
|
||||
IMAPAccount.dropTable(ifExists=True)
|
||||
MailAccount.dropTable(ifExists=True)
|
||||
PresenceAccount.dropTable(ifExists=True)
|
||||
Account.dropTable(ifExists=True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
||||
model.hub.threadConnection.close()
|
||||
model.db_disconnect()
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
|
||||
###########################################################################
|
||||
# 'feed' test methods
|
||||
###########################################################################
|
||||
def test_feed_live_email_init_no_password(self):
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11.status = account.ONLINE
|
||||
@@ -225,7 +204,7 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
|
||||
def test_feed_live_email_init_no_password2(self):
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11.status = account.ONLINE
|
||||
@@ -247,7 +226,7 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
|
||||
def test_feed_interval_no_check(self):
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11._action = PresenceAccount.DO_NOTHING
|
||||
@@ -261,7 +240,7 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
|
||||
def test_feed_interval_check(self):
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11._action = PresenceAccount.DO_NOTHING
|
||||
@@ -275,7 +254,7 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
|
||||
def test_feed_no_password(self):
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11._action = MailAccount.RETRIEVE
|
||||
@@ -299,7 +278,7 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
|
||||
def test_feed_unknown_action(self):
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11._action = 42 # Unknown action
|
||||
@@ -323,7 +302,7 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
|
||||
def test_feed_retrieve_no_mail(self):
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11._action = MailAccount.RETRIEVE
|
||||
@@ -347,7 +326,7 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
return [("body1", "from1@test.com"),
|
||||
("body2", "from2@test.com")][index]
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11._action = MailAccount.RETRIEVE
|
||||
@@ -381,7 +360,7 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
|
||||
def test_feed_digest_no_mail(self):
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11._action = MailAccount.DIGEST
|
||||
@@ -405,7 +384,7 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
return [("body1", "from1@test.com"),
|
||||
("body2", "from2@test.com")][index]
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid="test1@test.com",
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11._action = MailAccount.DIGEST
|
||||
@@ -435,8 +414,8 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
###########################################################################
|
||||
def test_initialize_live_email(self):
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid = "test1@test.com", \
|
||||
name = "account11", \
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11.status = account.ONLINE
|
||||
self.assertTrue(account11.first_check)
|
||||
@@ -457,8 +436,8 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
def raiser():
|
||||
raise Exception
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid = "test1@test.com", \
|
||||
name = "account11", \
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11.connect = raiser
|
||||
account11.status = account.ONLINE
|
||||
@@ -484,8 +463,8 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
def raiser():
|
||||
raise Exception
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid = "test1@test.com", \
|
||||
name = "account11", \
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11.mark_all_as_read = raiser
|
||||
account11.status = account.ONLINE
|
||||
@@ -511,8 +490,8 @@ class MailComponent_TestCase(unittest.TestCase):
|
||||
def raiser():
|
||||
raise Exception
|
||||
model.db_connect()
|
||||
account11 = MockIMAPAccount(user_jid = "test1@test.com", \
|
||||
name = "account11", \
|
||||
account11 = MockIMAPAccount(user=User(jid="test1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11.disconnect = raiser
|
||||
account11.status = account.ONLINE
|
||||
@@ -558,34 +537,19 @@ class SendMailMessageHandler_TestCase(unittest.TestCase):
|
||||
self.assertEquals(result[0].get_body(),
|
||||
Lang.en.send_mail_ok_body % ("user@test.com"))
|
||||
|
||||
class RootSendMailMessageHandler_TestCase(unittest.TestCase):
|
||||
class RootSendMailMessageHandler_TestCase(JCLTestCase):
|
||||
def setUp(self):
|
||||
JCLTestCase.setUp(self, tables=[Account, SMTPAccount, User])
|
||||
self.handler = RootSendMailMessageHandler(None)
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
model.db_connection_str = 'sqlite://' + DB_URL
|
||||
model.db_connect()
|
||||
Account.createTable(ifNotExists=True)
|
||||
SMTPAccount.createTable(ifNotExists=True)
|
||||
model.db_disconnect()
|
||||
|
||||
def tearDown(self):
|
||||
model.db_connect()
|
||||
SMTPAccount.dropTable(ifExists=True)
|
||||
Account.dropTable(ifExists=True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
||||
model.hub.threadConnection.close()
|
||||
model.db_disconnect()
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
|
||||
def test_filter(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account11.default_account = True
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid="user1@test.com",
|
||||
@@ -597,10 +561,11 @@ class RootSendMailMessageHandler_TestCase(unittest.TestCase):
|
||||
|
||||
def test_filter_no_default_account(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid="user1@test.com",
|
||||
@@ -613,10 +578,11 @@ class RootSendMailMessageHandler_TestCase(unittest.TestCase):
|
||||
|
||||
def test_filter_wrong_dest(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid="user1@test.com",
|
||||
@@ -628,10 +594,11 @@ class RootSendMailMessageHandler_TestCase(unittest.TestCase):
|
||||
|
||||
def test_filter_wrong_user(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid="user2@test.com",
|
||||
@@ -678,36 +645,16 @@ class RootSendMailMessageHandler_TestCase(unittest.TestCase):
|
||||
self.assertEquals(result[0].get_body(),
|
||||
Lang.en.send_mail_error_no_to_header_body)
|
||||
|
||||
class MailSender_TestCase(unittest.TestCase):
|
||||
class MailSender_TestCase(JCLTestCase):
|
||||
def setUp(self):
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
model.db_connection_str = 'sqlite://' + DB_URL
|
||||
model.db_connect()
|
||||
Account.createTable(ifNotExists=True)
|
||||
PresenceAccount.createTable(ifNotExists=True)
|
||||
MailAccount.createTable(ifNotExists=True)
|
||||
IMAPAccount.createTable(ifNotExists=True)
|
||||
POP3Account.createTable(ifNotExists=True)
|
||||
model.db_disconnect()
|
||||
|
||||
def tearDown(self):
|
||||
model.db_connect()
|
||||
POP3Account.dropTable(ifExists=True)
|
||||
IMAPAccount.dropTable(ifExists=True)
|
||||
MailAccount.dropTable(ifExists=True)
|
||||
PresenceAccount.dropTable(ifExists=True)
|
||||
Account.dropTable(ifExists=True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
||||
model.hub.threadConnection.close()
|
||||
model.db_disconnect()
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, MailAccount,
|
||||
IMAPAccount, POP3Account, User])
|
||||
|
||||
def test_create_message(self):
|
||||
mail_sender = MailSender()
|
||||
model.db_connect()
|
||||
account11 = IMAPAccount(user_jid="test1@test.com",
|
||||
user1 = User(jid="test1@test.com")
|
||||
account11 = IMAPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11.online_action = MailAccount.RETRIEVE
|
||||
@@ -715,7 +662,7 @@ class MailSender_TestCase(unittest.TestCase):
|
||||
message = mail_sender.create_message(account11, ("from@test.com",
|
||||
"subject",
|
||||
"message body"))
|
||||
self.assertEquals(message.get_to(), account11.user_jid)
|
||||
self.assertEquals(message.get_to(), user1.jid)
|
||||
model.db_disconnect()
|
||||
self.assertEquals(message.get_subject(), "subject")
|
||||
self.assertEquals(message.get_body(), "message body")
|
||||
@@ -730,7 +677,8 @@ class MailSender_TestCase(unittest.TestCase):
|
||||
def test_create_message_digest(self):
|
||||
mail_sender = MailSender()
|
||||
model.db_connect()
|
||||
account11 = IMAPAccount(user_jid="test1@test.com",
|
||||
user1 = User(jid="test1@test.com")
|
||||
account11 = IMAPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account11.online_action = MailAccount.DIGEST
|
||||
@@ -738,40 +686,25 @@ class MailSender_TestCase(unittest.TestCase):
|
||||
message = mail_sender.create_message(account11, ("from@test.com",
|
||||
"subject",
|
||||
"message body"))
|
||||
self.assertEquals(message.get_to(), account11.user_jid)
|
||||
self.assertEquals(message.get_to(), user1.jid)
|
||||
model.db_disconnect()
|
||||
self.assertEquals(message.get_subject(), "subject")
|
||||
self.assertEquals(message.get_body(), "message body")
|
||||
self.assertEquals(message.get_type(), "headline")
|
||||
|
||||
class MailHandler_TestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
class MailHandler_TestCase(JCLTestCase):
|
||||
def setUp(self, tables=[]):
|
||||
self.handler = MailHandler(None)
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
model.db_connection_str = 'sqlite://' + DB_URL
|
||||
model.db_connect()
|
||||
Account.createTable(ifNotExists=True)
|
||||
SMTPAccount.createTable(ifNotExists=True)
|
||||
model.db_disconnect()
|
||||
|
||||
def tearDown(self):
|
||||
model.db_connect()
|
||||
SMTPAccount.dropTable(ifExists=True)
|
||||
Account.dropTable(ifExists=True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
||||
model.hub.threadConnection.close()
|
||||
model.db_disconnect()
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
JCLTestCase.setUp(self, tables=[Account, SMTPAccount, User] + tables)
|
||||
|
||||
def test_filter(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account11.default_account = True
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid="user1@test.com",
|
||||
@@ -779,17 +712,22 @@ class MailHandler_TestCase(unittest.TestCase):
|
||||
body="message")
|
||||
accounts = self.handler.filter(message, None)
|
||||
self.assertNotEquals(accounts, None)
|
||||
self.assertEquals(accounts.count(), 1)
|
||||
self.assertEquals(accounts[0].name, "account11")
|
||||
i = 0
|
||||
for _account in accounts:
|
||||
i += 1
|
||||
if i == 1:
|
||||
self.assertEquals(_account.name, "account11")
|
||||
self.assertEquals(i, 1)
|
||||
model.db_disconnect()
|
||||
|
||||
def test_filter_root(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account11.default_account = True
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid="user1@test.com",
|
||||
@@ -801,31 +739,39 @@ class MailHandler_TestCase(unittest.TestCase):
|
||||
|
||||
def test_filter_no_default(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid = "user1@test.com", \
|
||||
name = "account11", \
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account12 = SMTPAccount(user_jid = "user1@test.com", \
|
||||
name = "account12", \
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid = "user1@test.com", \
|
||||
to_jid = "user2%test.com@jcl.test.com", \
|
||||
message = Message(from_jid="user1@test.com",
|
||||
to_jid="user2%test.com@jcl.test.com",
|
||||
body="message")
|
||||
accounts = self.handler.filter(message, None)
|
||||
self.assertNotEquals(accounts, None)
|
||||
self.assertEquals(accounts.count(), 2)
|
||||
self.assertEquals(accounts[0].name, "account11")
|
||||
i = 0
|
||||
for _account in accounts:
|
||||
i += 1
|
||||
if i == 1:
|
||||
self.assertEquals(_account.name, "account11")
|
||||
else:
|
||||
self.assertEquals(_account.name, "account12")
|
||||
self.assertEquals(i, 2)
|
||||
model.db_disconnect()
|
||||
|
||||
def test_filter_wrong_dest(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid = "user1@test.com", \
|
||||
name = "account11", \
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account12 = SMTPAccount(user_jid = "user1@test.com", \
|
||||
name = "account12", \
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid = "user1@test.com", \
|
||||
to_jid = "user2test.com@jcl.test.com", \
|
||||
message = Message(from_jid="user1@test.com",
|
||||
to_jid="user2test.com@jcl.test.com",
|
||||
body="message")
|
||||
accounts = self.handler.filter(message, None)
|
||||
self.assertEquals(accounts, None)
|
||||
@@ -833,10 +779,11 @@ class MailHandler_TestCase(unittest.TestCase):
|
||||
|
||||
def test_filter_wrong_account(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid="user3@test.com",
|
||||
@@ -878,15 +825,12 @@ class MailPresenceHandler_TestCase(unittest.TestCase):
|
||||
|
||||
class MailSubscribeHandler_TestCase(DefaultSubscribeHandler_TestCase, MailHandler_TestCase):
|
||||
def setUp(self):
|
||||
MailHandler_TestCase.setUp(self)
|
||||
MailHandler_TestCase.setUp(self, tables=[LegacyJID])
|
||||
self.handler = MailSubscribeHandler(None)
|
||||
model.db_connect()
|
||||
LegacyJID.createTable(ifNotExists=True)
|
||||
model.db_disconnect()
|
||||
|
||||
def test_handle(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
account11 = SMTPAccount(user=User(jid="user1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
presence = Presence(from_jid="user1@test.com",
|
||||
@@ -899,21 +843,19 @@ class MailSubscribeHandler_TestCase(DefaultSubscribeHandler_TestCase, MailHandle
|
||||
|
||||
class MailUnsubscribeHandler_TestCase(DefaultUnsubscribeHandler_TestCase, MailHandler_TestCase):
|
||||
def setUp(self):
|
||||
MailHandler_TestCase.setUp(self)
|
||||
MailHandler_TestCase.setUp(self, tables=[LegacyJID])
|
||||
self.handler = MailUnsubscribeHandler(None)
|
||||
model.db_connect()
|
||||
LegacyJID.createTable(ifNotExists=True)
|
||||
model.db_disconnect()
|
||||
|
||||
def test_handle(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
account2 = SMTPAccount(user_jid="user2@test.com",
|
||||
account2 = SMTPAccount(user=User(jid="user2@test.com"),
|
||||
name="account2",
|
||||
jid="account2@jcl.test.com")
|
||||
presence = Presence(from_jid="user1@test.com",
|
||||
@@ -942,66 +884,48 @@ class MailUnsubscribeHandler_TestCase(DefaultUnsubscribeHandler_TestCase, MailHa
|
||||
self.assertEquals(removed_legacy_jid.count(), 0)
|
||||
model.db_disconnect()
|
||||
|
||||
class MailFeederHandler_TestCase(unittest.TestCase):
|
||||
class MailFeederHandler_TestCase(JCLTestCase):
|
||||
def setUp(self):
|
||||
self.handler = MailFeederHandler(FeederMock(), SenderMock())
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
model.db_connection_str = 'sqlite://' + DB_URL
|
||||
model.db_connect()
|
||||
Account.createTable(ifNotExists=True)
|
||||
PresenceAccount.createTable(ifNotExists=True)
|
||||
MailAccount.createTable(ifNotExists=True)
|
||||
IMAPAccount.createTable(ifNotExists=True)
|
||||
POP3Account.createTable(ifNotExists=True)
|
||||
SMTPAccount.createTable(ifNotExists=True)
|
||||
model.db_disconnect()
|
||||
|
||||
def tearDown(self):
|
||||
self.handler = None
|
||||
model.db_connect()
|
||||
SMTPAccount.dropTable(ifExists=True)
|
||||
IMAPAccount.dropTable(ifExists=True)
|
||||
POP3Account.dropTable(ifExists=True)
|
||||
MailAccount.dropTable(ifExists=True)
|
||||
PresenceAccount.dropTable(ifExists=True)
|
||||
Account.dropTable(ifExists=True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
||||
model.hub.threadConnection.close()
|
||||
model.db_disconnect()
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, MailAccount,
|
||||
IMAPAccount, POP3Account, SMTPAccount,
|
||||
User])
|
||||
|
||||
def test_filter(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
account11 = SMTPAccount(user=User(jid="user1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account13 = IMAPAccount(user_jid="user3@test.com",
|
||||
account13 = IMAPAccount(user=User(jid="user3@test.com"),
|
||||
name="account13",
|
||||
jid="account13@jcl.test.com")
|
||||
account12 = POP3Account(user_jid="user2@test.com",
|
||||
account12 = POP3Account(user=User(jid="user2@test.com"),
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
accounts = self.handler.filter(None, None)
|
||||
i = 0
|
||||
# SQLObject > 0.8 is needed
|
||||
self.assertEquals(accounts.count(), 2)
|
||||
self.assertEquals(accounts[0].name, "account12")
|
||||
self.assertEquals(accounts[1].name, "account13")
|
||||
for _account in accounts:
|
||||
i += 1
|
||||
if i == 1:
|
||||
self.assertEquals(_account.name, "account13")
|
||||
else:
|
||||
self.assertEquals(_account.name, "account12")
|
||||
self.assertEquals(i, 2)
|
||||
model.db_disconnect()
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(unittest.makeSuite(MailComponent_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(SendMailMessageHandler_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(RootSendMailMessageHandler_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(MailSender_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(MailHandler_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(MailUnsubscribeHandler_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(MailSubscribeHandler_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(MailPresenceHandler_TestCase, 'test'))
|
||||
suite.addTest(unittest.makeSuite(MailFeederHandler_TestCase, 'test'))
|
||||
return suite
|
||||
test_suite = unittest.TestSuite()
|
||||
test_suite.addTest(unittest.makeSuite(MailComponent_TestCase, 'test'))
|
||||
test_suite.addTest(unittest.makeSuite(SendMailMessageHandler_TestCase, 'test'))
|
||||
test_suite.addTest(unittest.makeSuite(RootSendMailMessageHandler_TestCase, 'test'))
|
||||
test_suite.addTest(unittest.makeSuite(MailSender_TestCase, 'test'))
|
||||
test_suite.addTest(unittest.makeSuite(MailHandler_TestCase, 'test'))
|
||||
test_suite.addTest(unittest.makeSuite(MailUnsubscribeHandler_TestCase, 'test'))
|
||||
test_suite.addTest(unittest.makeSuite(MailSubscribeHandler_TestCase, 'test'))
|
||||
test_suite.addTest(unittest.makeSuite(MailPresenceHandler_TestCase, 'test'))
|
||||
test_suite.addTest(unittest.makeSuite(MailFeederHandler_TestCase, 'test'))
|
||||
return test_suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(defaultTest='suite')
|
||||
|
||||
@@ -30,7 +30,6 @@ class Lang(jcl.lang.Lang):
|
||||
component_name = u"Jabber Mail Component"
|
||||
|
||||
field_login = u"Login"
|
||||
field_password = u"Password"
|
||||
field_host = u"Host"
|
||||
field_port = u"Port"
|
||||
field_ssl = u"Secure connection (SSL)"
|
||||
@@ -79,7 +78,6 @@ class Lang(jcl.lang.Lang):
|
||||
u"serveur email."
|
||||
|
||||
field_login = u"Nom d'utilisateur"
|
||||
field_password = u"Mot de passe"
|
||||
field_host = u"Adresse du serveur email"
|
||||
field_port = u"Port du serveur email"
|
||||
field_ssl = u"Connexion sécurisé (SSL)"
|
||||
|
||||
@@ -578,18 +578,16 @@ class SMTPAccount(Account):
|
||||
return password
|
||||
|
||||
def default_account_default_func(bare_from_jid):
|
||||
accounts = SMTPAccount.select(\
|
||||
AND(SMTPAccount.q.default_account == True,
|
||||
SMTPAccount.q.user_jid == bare_from_jid))
|
||||
accounts = account.get_accounts(bare_from_jid, SMTPAccount,
|
||||
(SMTPAccount.q.default_account == True))
|
||||
if accounts.count() == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def default_account_post_func(value, default_func, bare_from_jid):
|
||||
accounts = SMTPAccount.select(\
|
||||
AND(SMTPAccount.q.default_account == True,
|
||||
SMTPAccount.q.user_jid == bare_from_jid))
|
||||
accounts = account.get_accounts(bare_from_jid, SMTPAccount,
|
||||
(SMTPAccount.q.default_account == True))
|
||||
already_default_account = (accounts.count() != 0)
|
||||
if isinstance(value, str):
|
||||
value = value.lower()
|
||||
|
||||
@@ -22,16 +22,11 @@
|
||||
##
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import thread
|
||||
import sys
|
||||
|
||||
from sqlobject import *
|
||||
from sqlobject.dbconnection import TheURIOpener
|
||||
|
||||
from jcl.tests import JCLTestCase
|
||||
import jcl.model as model
|
||||
from jcl.model import account
|
||||
from jcl.model.account import Account, PresenceAccount
|
||||
from jcl.model.account import Account, PresenceAccount, User
|
||||
from jmc.model.account import MailAccount, POP3Account, IMAPAccount, SMTPAccount
|
||||
|
||||
from jcl.model.tests.account import Account_TestCase, \
|
||||
@@ -39,39 +34,14 @@ from jcl.model.tests.account import Account_TestCase, \
|
||||
ExampleAccount
|
||||
from jmc.model.tests import email_generator, server
|
||||
|
||||
if sys.platform == "win32":
|
||||
DB_PATH = "/c|/temp/test.db"
|
||||
else:
|
||||
DB_PATH = "/tmp/test.db"
|
||||
DB_URL = DB_PATH # + "?debug=1&debugThreading=1"
|
||||
|
||||
class MailAccount_TestCase(PresenceAccount_TestCase):
|
||||
def setUp(self):
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
self.db_url = DB_URL
|
||||
model.db_connection_str = 'sqlite://' + self.db_url
|
||||
model.db_connect()
|
||||
Account.createTable(ifNotExists=True)
|
||||
PresenceAccount.createTable(ifNotExists=True)
|
||||
MailAccount.createTable(ifNotExists=True)
|
||||
self.account = MailAccount(user_jid="user1@test.com",
|
||||
PresenceAccount_TestCase.setUp(self, tables=[MailAccount])
|
||||
self.account = MailAccount(user=User(jid="user1@test.com"),
|
||||
name="account1",
|
||||
jid="account1@jmc.test.com")
|
||||
model.db_disconnect()
|
||||
self.account_class = MailAccount
|
||||
|
||||
def tearDown(self):
|
||||
model.db_connect()
|
||||
MailAccount.dropTable(ifExists=True)
|
||||
PresenceAccount.dropTable(ifExists=True)
|
||||
Account.dropTable(ifExists = True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + self.db_url]
|
||||
model.hub.threadConnection.close()
|
||||
model.db_disconnect()
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
|
||||
def make_test(email_type, tested_func, expected_res):
|
||||
def inner(self):
|
||||
encoded, multipart, header = email_type
|
||||
@@ -152,16 +122,9 @@ class MailAccount_TestCase(PresenceAccount_TestCase):
|
||||
|
||||
class POP3Account_TestCase(InheritableAccount_TestCase):
|
||||
def setUp(self):
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
self.db_url = DB_URL
|
||||
model.db_connection_str = 'sqlite://' + self.db_url
|
||||
model.db_connect()
|
||||
Account.createTable(ifNotExists=True)
|
||||
PresenceAccount.createTable(ifNotExists=True)
|
||||
MailAccount.createTable(ifNotExists=True)
|
||||
POP3Account.createTable(ifNotExists=True)
|
||||
self.pop3_account = POP3Account(user_jid="user1@test.com",
|
||||
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
|
||||
MailAccount, POP3Account])
|
||||
self.pop3_account = POP3Account(user=User(jid="user1@test.com"),
|
||||
name="account1",
|
||||
jid="account1@jmc.test.com",
|
||||
login="login")
|
||||
@@ -172,20 +135,6 @@ class POP3Account_TestCase(InheritableAccount_TestCase):
|
||||
model.db_disconnect()
|
||||
self.account_class = POP3Account
|
||||
|
||||
def tearDown(self):
|
||||
model.db_connect()
|
||||
POP3Account.dropTable(ifExists=True)
|
||||
MailAccount.dropTable(ifExists=True)
|
||||
PresenceAccount.dropTable(ifExists=True)
|
||||
Account.dropTable(ifExists=True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + self.db_url]
|
||||
model.hub.threadConnection.close()
|
||||
model.db_disconnect()
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
self.server = None
|
||||
self.pop3_account = None
|
||||
|
||||
def make_test(responses=None, queries=None, core=None):
|
||||
def inner(self):
|
||||
self.server = server.DummyServer("localhost", 1110)
|
||||
@@ -281,16 +230,9 @@ class POP3Account_TestCase(InheritableAccount_TestCase):
|
||||
|
||||
class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||
def setUp(self):
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
self.db_url = DB_URL
|
||||
model.db_connection_str = 'sqlite://' + self.db_url
|
||||
model.db_connect()
|
||||
Account.createTable(ifNotExists=True)
|
||||
PresenceAccount.createTable(ifNotExists=True)
|
||||
MailAccount.createTable(ifNotExists=True)
|
||||
IMAPAccount.createTable(ifNotExists=True)
|
||||
self.imap_account = IMAPAccount(user_jid="user1@test.com",
|
||||
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
|
||||
MailAccount, IMAPAccount])
|
||||
self.imap_account = IMAPAccount(user=User(jid="user1@test.com"),
|
||||
name="account1",
|
||||
jid="account1@jmc.test.com",
|
||||
login="login")
|
||||
@@ -298,23 +240,8 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||
self.imap_account.host = "localhost"
|
||||
self.imap_account.port = 1143
|
||||
self.imap_account.ssl = False
|
||||
model.db_disconnect()
|
||||
self.account_class = IMAPAccount
|
||||
|
||||
def tearDown(self):
|
||||
model.db_connect()
|
||||
IMAPAccount.dropTable(ifExists=True)
|
||||
MailAccount.dropTable(ifExists=True)
|
||||
PresenceAccount.dropTable(ifExists=True)
|
||||
Account.dropTable(ifExists=True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + self.db_url]
|
||||
model.hub.threadConnection.close()
|
||||
model.db_disconnect()
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
self.server = None
|
||||
self.imap_account = None
|
||||
|
||||
def make_test(responses=None, queries=None, core=None):
|
||||
def inner(self):
|
||||
self.server = server.DummyServer("localhost", 1143)
|
||||
@@ -389,34 +316,17 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||
|
||||
class SMTPAccount_TestCase(Account_TestCase):
|
||||
def setUp(self):
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
self.db_url = DB_URL
|
||||
model.db_connection_str = 'sqlite://' + self.db_url
|
||||
model.db_connect()
|
||||
Account.createTable(ifNotExists=True)
|
||||
ExampleAccount.createTable(ifNotExists=True)
|
||||
SMTPAccount.createTable(ifNotExists=True)
|
||||
model.db_disconnect()
|
||||
JCLTestCase.setUp(self, tables=[Account, ExampleAccount, User,
|
||||
SMTPAccount])
|
||||
self.account_class = SMTPAccount
|
||||
|
||||
def tearDown(self):
|
||||
model.db_connect()
|
||||
SMTPAccount.dropTable(ifExists=True)
|
||||
ExampleAccount.dropTable(ifExists=True)
|
||||
Account.dropTable(ifExists=True)
|
||||
del TheURIOpener.cachedURIs['sqlite://' + self.db_url]
|
||||
model.hub.threadConnection.close()
|
||||
model.db_disconnect()
|
||||
if os.path.exists(DB_PATH):
|
||||
os.unlink(DB_PATH)
|
||||
|
||||
def test_default_account_post_func_no_default_true(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jmc.test.com")
|
||||
(name, field_type, field_options, post_func, default_func) = \
|
||||
@@ -427,10 +337,11 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
|
||||
def test_default_account_post_func_no_default_false(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jmc.test.com")
|
||||
(name, field_type, field_options, post_func, default_func) = \
|
||||
@@ -441,10 +352,11 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
|
||||
def test_default_account_post_func_true(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jmc.test.com")
|
||||
account12.default_account = True
|
||||
@@ -457,10 +369,11 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
|
||||
def test_default_account_post_func_false(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = SMTPAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
account12 = SMTPAccount(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jmc.test.com")
|
||||
account12.default_account = True
|
||||
@@ -473,7 +386,7 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
|
||||
def test_create_email(self):
|
||||
model.db_connect()
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
account11 = SMTPAccount(user=User(jid="user1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
model.db_disconnect()
|
||||
@@ -507,7 +420,7 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
|
||||
def test_send_email_esmtp_no_auth(self):
|
||||
model.db_connect()
|
||||
smtp_account = SMTPAccount(user_jid="user1@test.com",
|
||||
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
smtp_account.host = "localhost"
|
||||
@@ -539,7 +452,7 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
|
||||
def test_send_email_no_auth(self):
|
||||
model.db_connect()
|
||||
smtp_account = SMTPAccount(user_jid="user1@test.com",
|
||||
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
smtp_account.host = "localhost"
|
||||
@@ -573,7 +486,7 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
|
||||
def test_send_email_esmtp_auth(self):
|
||||
model.db_connect()
|
||||
smtp_account = SMTPAccount(user_jid="user1@test.com",
|
||||
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
smtp_account.host = "localhost"
|
||||
@@ -612,7 +525,7 @@ class SMTPAccount_TestCase(Account_TestCase):
|
||||
|
||||
def test_send_email_esmtp_auth_method2(self):
|
||||
model.db_connect()
|
||||
smtp_account = SMTPAccount(user_jid="user1@test.com",
|
||||
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jmc.test.com")
|
||||
smtp_account.host = "localhost"
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
##
|
||||
|
||||
from jcl.runner import JCLRunner
|
||||
from jcl.model.account import LegacyJID
|
||||
|
||||
from jmc.model.account import MailAccount, IMAPAccount, POP3Account, SMTPAccount
|
||||
from jmc.jabber.component import MailComponent
|
||||
@@ -43,6 +42,7 @@ class JMCRunner(JCLRunner):
|
||||
self.service_jid = "jmc.localhost"
|
||||
self.db_url = "sqlite:///var/spool/jabber/jmc.db"
|
||||
self.pid_file = "/var/run/jabber/jmc.pid"
|
||||
self.config_file = "jmc.conf"
|
||||
|
||||
def setup_db(self):
|
||||
JCLRunner.setup_db(self)
|
||||
@@ -50,7 +50,6 @@ class JMCRunner(JCLRunner):
|
||||
IMAPAccount.createTable(ifNotExists=True)
|
||||
POP3Account.createTable(ifNotExists=True)
|
||||
SMTPAccount.createTable(ifNotExists=True)
|
||||
LegacyJID.createTable(ifNotExists=True)
|
||||
|
||||
def run(self):
|
||||
def run_func():
|
||||
|
||||
@@ -77,7 +77,6 @@ class Language_TestCase(jcl.tests.lang.Language_TestCase):
|
||||
jcl.tests.lang.Language_TestCase.test_strings(self)
|
||||
|
||||
self.assertNotEquals(self.lang_class.field_login, None)
|
||||
self.assertNotEquals(self.lang_class.field_password, None)
|
||||
self.assertNotEquals(self.lang_class.field_host, None)
|
||||
self.assertNotEquals(self.lang_class.field_port, None)
|
||||
self.assertNotEquals(self.lang_class.field_ssl, None)
|
||||
|
||||
@@ -24,13 +24,10 @@ import unittest
|
||||
import sys
|
||||
import os
|
||||
|
||||
from sqlobject import *
|
||||
|
||||
from jcl.tests.runner import JCLRunner_TestCase
|
||||
|
||||
import jcl.model as model
|
||||
from jcl.model import account
|
||||
from jcl.model.account import Account, PresenceAccount
|
||||
from jcl.model.account import Account, PresenceAccount, User, LegacyJID
|
||||
|
||||
import jmc
|
||||
from jmc.runner import JMCRunner
|
||||
@@ -52,7 +49,7 @@ class JMCRunner_TestCase(JCLRunner_TestCase):
|
||||
|
||||
def test_configure_default(self):
|
||||
self.runner.configure()
|
||||
self.assertEquals(self.runner.config_file, None)
|
||||
self.assertEquals(self.runner.config_file, "jmc.conf")
|
||||
self.assertEquals(self.runner.server, "localhost")
|
||||
self.assertEquals(self.runner.port, 5347)
|
||||
self.assertEquals(self.runner.secret, "secret")
|
||||
@@ -135,6 +132,8 @@ class JMCRunner_TestCase(JCLRunner_TestCase):
|
||||
# dropTable should succeed because tables should exist
|
||||
Account.dropTable()
|
||||
PresenceAccount.dropTable()
|
||||
User.dropTable()
|
||||
LegacyJID.dropTable()
|
||||
MailAccount.dropTable()
|
||||
IMAPAccount.dropTable()
|
||||
POP3Account.dropTable()
|
||||
@@ -144,9 +143,9 @@ class JMCRunner_TestCase(JCLRunner_TestCase):
|
||||
self.assertFalse(os.access("/tmp/jmc.pid", os.F_OK))
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(unittest.makeSuite(JMCRunner_TestCase, 'test'))
|
||||
return suite
|
||||
test_suite = unittest.TestSuite()
|
||||
test_suite.addTest(unittest.makeSuite(JMCRunner_TestCase, 'test'))
|
||||
return test_suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(defaultTest='suite')
|
||||
|
||||
Reference in New Issue
Block a user