Multi-pages support when selecting email to fetch in get-email ad-hoc command
darcs-hash:20080306165514-86b55-9c737d38047aef3a716974f343fd192a259c7f9f.gz
This commit is contained in:
@@ -36,6 +36,7 @@ from jcl.jabber.feeder import Feeder
|
|||||||
from jcl.model.account import User, Account, PresenceAccount
|
from jcl.model.account import User, Account, PresenceAccount
|
||||||
from jcl.jabber.tests.command import JCLCommandManagerTestCase
|
from jcl.jabber.tests.command import JCLCommandManagerTestCase
|
||||||
import jcl.jabber.command as command
|
import jcl.jabber.command as command
|
||||||
|
import jcl.jabber.tests.command
|
||||||
|
|
||||||
from jmc.model.account import POP3Account, IMAPAccount, SMTPAccount, \
|
from jmc.model.account import POP3Account, IMAPAccount, SMTPAccount, \
|
||||||
MailAccount
|
MailAccount
|
||||||
@@ -174,7 +175,7 @@ class MailCommandManagerForceCheckCommand_TestCase(MailCommandManagerTestCase):
|
|||||||
["test1@test.com"])
|
["test1@test.com"])
|
||||||
|
|
||||||
# Second step
|
# Second step
|
||||||
info_query = self.prepare_submit(\
|
info_query = jcl.jabber.tests.command.prepare_submit(\
|
||||||
node="jmc#force-check",
|
node="jmc#force-check",
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
from_jid="test1@test.com",
|
from_jid="test1@test.com",
|
||||||
@@ -224,7 +225,10 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase):
|
|||||||
"from" + str(email_index) + "@test.com")
|
"from" + str(email_index) + "@test.com")
|
||||||
self.account11.__dict__["get_mail"] = get_email
|
self.account11.__dict__["get_mail"] = get_email
|
||||||
|
|
||||||
def check_step_1 (self, result):
|
def check_step_1(self, result, options="<option label=\"mail 1\">" \
|
||||||
|
+ "<value>1</value></option>" \
|
||||||
|
+ "<option label=\"mail 2\">" \
|
||||||
|
+ "<value>2</value></option>"):
|
||||||
"""
|
"""
|
||||||
Check first step result of get-email ad-hoc command
|
Check first step result of get-email ad-hoc command
|
||||||
"""
|
"""
|
||||||
@@ -242,10 +246,7 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase):
|
|||||||
+ "</instructions>"
|
+ "</instructions>"
|
||||||
+ "<field var='emails' type='list-multi' label='"
|
+ "<field var='emails' type='list-multi' label='"
|
||||||
+ Lang.en.field_email_subject + "'>"
|
+ Lang.en.field_email_subject + "'>"
|
||||||
+ "<option label=\"mail 1\">"
|
+ options
|
||||||
+ "<value>1</value></option>"
|
|
||||||
+ "<option label=\"mail 2\">"
|
|
||||||
+ "<value>2</value></option>"
|
|
||||||
+ "</field><field var='fetch_more' type='boolean' label='"
|
+ "</field><field var='fetch_more' type='boolean' label='"
|
||||||
+ Lang.en.field_select_more_emails + "'>"
|
+ Lang.en.field_select_more_emails + "'>"
|
||||||
+ "</field></x></command></iq>",
|
+ "</field></x></command></iq>",
|
||||||
@@ -254,6 +255,23 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase):
|
|||||||
self.assertNotEquals(session_id, None)
|
self.assertNotEquals(session_id, None)
|
||||||
return session_id
|
return session_id
|
||||||
|
|
||||||
|
def check_email_message(self, result_iq, index):
|
||||||
|
""" """
|
||||||
|
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||||
|
u"<message from='account11@" + unicode(self.comp.jid)
|
||||||
|
+ "' to='test1@test.com' "
|
||||||
|
+ "xmlns='http://pyxmpp.jabberstudio.org/xmlns/common'>"
|
||||||
|
+ "<subject>" + Lang.en.mail_subject \
|
||||||
|
% ("from" + str(index) + "@test.com")
|
||||||
|
+ "</subject>"
|
||||||
|
+ "<body>mail body " + str(index) + "</body>"
|
||||||
|
+ "<addresses xmlns='http://jabber.org/protocol/address'>"
|
||||||
|
+ "<address type='replyto' jid='from" + str(index)
|
||||||
|
+ "%test.com@jmc.test.com'/>"
|
||||||
|
+ "</addresses>"
|
||||||
|
+ "</message>",
|
||||||
|
result_iq, True, test_sibling=False))
|
||||||
|
|
||||||
def test_execute_get_email(self):
|
def test_execute_get_email(self):
|
||||||
"""
|
"""
|
||||||
Test single email retrieval
|
Test single email retrieval
|
||||||
@@ -267,7 +285,7 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase):
|
|||||||
session_id = self.check_step_1(result)
|
session_id = self.check_step_1(result)
|
||||||
|
|
||||||
# Second step
|
# Second step
|
||||||
info_query = self.prepare_submit(\
|
info_query = jcl.jabber.tests.command.prepare_submit(\
|
||||||
node="jmc#get-email",
|
node="jmc#get-email",
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
from_jid="test1@test.com",
|
from_jid="test1@test.com",
|
||||||
@@ -298,18 +316,7 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase):
|
|||||||
+ "</x></command></iq>",
|
+ "</x></command></iq>",
|
||||||
result_iq, True, test_sibling=False))
|
result_iq, True, test_sibling=False))
|
||||||
result_iq = result[1].xmlnode
|
result_iq = result[1].xmlnode
|
||||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
self.check_email_message(result_iq, 1)
|
||||||
u"<message from='account11@" + unicode(self.comp.jid)
|
|
||||||
+ "' to='test1@test.com' "
|
|
||||||
+ "xmlns='http://pyxmpp.jabberstudio.org/xmlns/common'>"
|
|
||||||
+ "<subject>" + Lang.en.mail_subject % ("from1@test.com")
|
|
||||||
+ "</subject>"
|
|
||||||
+ "<body>mail body 1</body>"
|
|
||||||
+ "<addresses xmlns='http://jabber.org/protocol/address'>"
|
|
||||||
+ "<address type='replyto' jid='from1%test.com@jmc.test.com'/>"
|
|
||||||
+ "</addresses>"
|
|
||||||
+ "</message>",
|
|
||||||
result_iq, True, test_sibling=False))
|
|
||||||
|
|
||||||
def test_execute_get_emails(self):
|
def test_execute_get_emails(self):
|
||||||
"""
|
"""
|
||||||
@@ -324,7 +331,7 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase):
|
|||||||
session_id = self.check_step_1(result)
|
session_id = self.check_step_1(result)
|
||||||
|
|
||||||
# Second step
|
# Second step
|
||||||
info_query = self.prepare_submit(\
|
info_query = jcl.jabber.tests.command.prepare_submit(\
|
||||||
node="jmc#get-email",
|
node="jmc#get-email",
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
from_jid="test1@test.com",
|
from_jid="test1@test.com",
|
||||||
@@ -355,31 +362,83 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase):
|
|||||||
+ "</x></command></iq>",
|
+ "</x></command></iq>",
|
||||||
result_iq, True, test_sibling=False))
|
result_iq, True, test_sibling=False))
|
||||||
result_iq = result[1].xmlnode
|
result_iq = result[1].xmlnode
|
||||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
self.check_email_message(result_iq, 1)
|
||||||
u"<message from='account11@" + unicode(self.comp.jid)
|
|
||||||
+ "' to='test1@test.com' "
|
|
||||||
+ "xmlns='http://pyxmpp.jabberstudio.org/xmlns/common'>"
|
|
||||||
+ "<subject>" + Lang.en.mail_subject % ("from1@test.com")
|
|
||||||
+ "</subject>"
|
|
||||||
+ "<body>mail body 1</body>"
|
|
||||||
+ "<addresses xmlns='http://jabber.org/protocol/address'>"
|
|
||||||
+ "<address type='replyto' jid='from1%test.com@jmc.test.com'/>"
|
|
||||||
+ "</addresses>"
|
|
||||||
+ "</message>",
|
|
||||||
result_iq, True, test_sibling=False))
|
|
||||||
result_iq = result[2].xmlnode
|
result_iq = result[2].xmlnode
|
||||||
|
self.check_email_message(result_iq, 2)
|
||||||
|
|
||||||
|
def test_execute_get_emails_multi_pages(self):
|
||||||
|
"""
|
||||||
|
Test multiple emails retrieval
|
||||||
|
"""
|
||||||
|
self.info_query.set_from("test1@test.com")
|
||||||
|
self.info_query.set_to("account11@" + unicode(self.comp.jid))
|
||||||
|
result = self.command_manager.apply_command_action(\
|
||||||
|
self.info_query,
|
||||||
|
"jmc#get-email",
|
||||||
|
"execute")
|
||||||
|
session_id = self.check_step_1(result)
|
||||||
|
|
||||||
|
# Second step
|
||||||
|
info_query = jcl.jabber.tests.command.prepare_submit(\
|
||||||
|
node="jmc#get-email",
|
||||||
|
session_id=session_id,
|
||||||
|
from_jid="test1@test.com",
|
||||||
|
to_jid="account11@jmc.test.com",
|
||||||
|
fields=[Field(field_type="list-multi",
|
||||||
|
name="emails",
|
||||||
|
values=["1", "2"]),
|
||||||
|
Field(field_type="boolean",
|
||||||
|
name="fetch_more",
|
||||||
|
value=True)],
|
||||||
|
action="complete")
|
||||||
|
result = self.command_manager.apply_command_action(\
|
||||||
|
info_query,
|
||||||
|
"jmc#get-email",
|
||||||
|
"execute")
|
||||||
|
self.check_step_1(result, options="<option label=\"mail 3\">" \
|
||||||
|
+ "<value>3</value></option>" \
|
||||||
|
+ "<option label=\"mail 4\">" \
|
||||||
|
+ "<value>4</value></option>")
|
||||||
|
|
||||||
|
# Third step
|
||||||
|
info_query = jcl.jabber.tests.command.prepare_submit(\
|
||||||
|
node="jmc#get-email",
|
||||||
|
session_id=session_id,
|
||||||
|
from_jid="test1@test.com",
|
||||||
|
to_jid="account11@jmc.test.com",
|
||||||
|
fields=[Field(field_type="list-multi",
|
||||||
|
name="emails",
|
||||||
|
values=["3", "4"]),
|
||||||
|
Field(field_type="boolean",
|
||||||
|
name="fetch_more",
|
||||||
|
value=False)],
|
||||||
|
action="complete")
|
||||||
|
result = self.command_manager.apply_command_action(\
|
||||||
|
info_query,
|
||||||
|
"jmc#get-email",
|
||||||
|
"execute")
|
||||||
|
self.assertEquals(len(result), 5)
|
||||||
|
result_iq = result[0].xmlnode
|
||||||
|
result_iq.setNs(None)
|
||||||
self.assertTrue(jcl.tests.is_xml_equal(\
|
self.assertTrue(jcl.tests.is_xml_equal(\
|
||||||
u"<message from='account11@" + unicode(self.comp.jid)
|
u"<iq from='account11@" + unicode(self.comp.jid)
|
||||||
+ "' to='test1@test.com' "
|
+ "' to='test1@test.com' type='result'>"
|
||||||
+ "xmlns='http://pyxmpp.jabberstudio.org/xmlns/common'>"
|
+ "<command xmlns='http://jabber.org/protocol/commands' "
|
||||||
+ "<subject>" + Lang.en.mail_subject % ("from2@test.com")
|
+ "status='completed'>"
|
||||||
+ "</subject>"
|
+ "<x xmlns='jabber:x:data' type='form'>"
|
||||||
+ "<body>mail body 2</body>"
|
+ "<title>" + Lang.en.command_get_email + "</title>"
|
||||||
+ "<addresses xmlns='http://jabber.org/protocol/address'>"
|
+ "<instructions>" + Lang.en.command_get_email_2_description
|
||||||
+ "<address type='replyto' jid='from2%test.com@jmc.test.com'/>"
|
% (4) + "</instructions>"
|
||||||
+ "</addresses>"
|
+ "</x></command></iq>",
|
||||||
+ "</message>",
|
|
||||||
result_iq, True, test_sibling=False))
|
result_iq, True, test_sibling=False))
|
||||||
|
result_iq = result[1].xmlnode
|
||||||
|
self.check_email_message(result_iq, 1)
|
||||||
|
result_iq = result[2].xmlnode
|
||||||
|
self.check_email_message(result_iq, 2)
|
||||||
|
result_iq = result[3].xmlnode
|
||||||
|
self.check_email_message(result_iq, 3)
|
||||||
|
result_iq = result[4].xmlnode
|
||||||
|
self.check_email_message(result_iq, 4)
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
test_suite = unittest.TestSuite()
|
test_suite = unittest.TestSuite()
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ class MockIMAPAccount(MockMailAccount, IMAPAccount):
|
|||||||
def _init(self, *args, **kw):
|
def _init(self, *args, **kw):
|
||||||
IMAPAccount._init(self, *args, **kw)
|
IMAPAccount._init(self, *args, **kw)
|
||||||
MockMailAccount._init(self)
|
MockMailAccount._init(self)
|
||||||
|
self.get_mail_list_summary_called = False
|
||||||
|
|
||||||
def ls_dir(self, imap_dir):
|
def ls_dir(self, imap_dir):
|
||||||
if imap_dir == "":
|
if imap_dir == "":
|
||||||
@@ -152,12 +153,17 @@ class MockIMAPAccount(MockMailAccount, IMAPAccount):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def get_mail_with_attachment_list(self):
|
def get_mail_with_attachment_list(self):
|
||||||
return [("1", "mail 1"),
|
return [("1", "mail 1"),
|
||||||
("2", "mail 2")]
|
("2", "mail 2")]
|
||||||
|
|
||||||
def get_mail_list_summary(self):
|
def get_mail_list_summary(self):
|
||||||
return [("1", "mail 1"),
|
if self.get_mail_list_summary_called:
|
||||||
("2", "mail 2")]
|
return [("3", "mail 3"),
|
||||||
|
("4", "mail 4")]
|
||||||
|
else:
|
||||||
|
self.get_mail_list_summary_called = True
|
||||||
|
return [("1", "mail 1"),
|
||||||
|
("2", "mail 2")]
|
||||||
|
|
||||||
|
|
||||||
class MockPOP3Account(MockMailAccount, POP3Account):
|
class MockPOP3Account(MockMailAccount, POP3Account):
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class Lang(jcl.lang.Lang):
|
|||||||
|
|
||||||
command_get_email = "Fetch emails"
|
command_get_email = "Fetch emails"
|
||||||
command_get_email_1_description = "Select email(s) to fetch"
|
command_get_email_1_description = "Select email(s) to fetch"
|
||||||
command_get_email_2_description = "% emails have been sent"
|
command_get_email_2_description = "%i emails have been sent"
|
||||||
field_email_subject = u"Email Subject"
|
field_email_subject = u"Email Subject"
|
||||||
field_select_more_emails = u"Select more emails to fetch"
|
field_select_more_emails = u"Select more emails to fetch"
|
||||||
mail_subject = u"Email from %s"
|
mail_subject = u"Email from %s"
|
||||||
@@ -164,7 +164,7 @@ class Lang(jcl.lang.Lang):
|
|||||||
|
|
||||||
command_get_email = "Récupérer des emails"
|
command_get_email = "Récupérer des emails"
|
||||||
command_get_email_1_description = "Séléctionner le(s) email(s) à récupérer"
|
command_get_email_1_description = "Séléctionner le(s) email(s) à récupérer"
|
||||||
command_get_email_2_description = "% emails ont été envoyés"
|
command_get_email_2_description = "%i emails ont été envoyés"
|
||||||
field_email_subject = u"Objet des emails"
|
field_email_subject = u"Objet des emails"
|
||||||
field_select_more_emails = u"Séléctionner plus d'emails à récupérer"
|
field_select_more_emails = u"Séléctionner plus d'emails à récupérer"
|
||||||
mail_subject = u"Email de %s"
|
mail_subject = u"Email de %s"
|
||||||
|
|||||||
Reference in New Issue
Block a user