diff --git a/src/jmc/jabber/tests/command.py b/src/jmc/jabber/tests/command.py index 1cff3b7..aff299f 100644 --- a/src/jmc/jabber/tests/command.py +++ b/src/jmc/jabber/tests/command.py @@ -36,6 +36,7 @@ from jcl.jabber.feeder import Feeder from jcl.model.account import User, Account, PresenceAccount from jcl.jabber.tests.command import JCLCommandManagerTestCase import jcl.jabber.command as command +import jcl.jabber.tests.command from jmc.model.account import POP3Account, IMAPAccount, SMTPAccount, \ MailAccount @@ -174,7 +175,7 @@ class MailCommandManagerForceCheckCommand_TestCase(MailCommandManagerTestCase): ["test1@test.com"]) # Second step - info_query = self.prepare_submit(\ + info_query = jcl.jabber.tests.command.prepare_submit(\ node="jmc#force-check", session_id=session_id, from_jid="test1@test.com", @@ -224,7 +225,10 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase): "from" + str(email_index) + "@test.com") self.account11.__dict__["get_mail"] = get_email - def check_step_1 (self, result): + def check_step_1(self, result, options="" \ + + ""): """ Check first step result of get-email ad-hoc command """ @@ -242,10 +246,7 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase): + "" + "" - + "" - + "" + + options + "" + "", @@ -254,6 +255,23 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase): self.assertNotEquals(session_id, None) return session_id + def check_email_message(self, result_iq, index): + """ """ + self.assertTrue(jcl.tests.is_xml_equal(\ + u"" + + "" + Lang.en.mail_subject \ + % ("from" + str(index) + "@test.com") + + "" + + "mail body " + str(index) + "" + + "" + + "
" + + "" + + "", + result_iq, True, test_sibling=False)) + def test_execute_get_email(self): """ Test single email retrieval @@ -267,7 +285,7 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase): session_id = self.check_step_1(result) # Second step - info_query = self.prepare_submit(\ + info_query = jcl.jabber.tests.command.prepare_submit(\ node="jmc#get-email", session_id=session_id, from_jid="test1@test.com", @@ -298,18 +316,7 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase): + "", result_iq, True, test_sibling=False)) result_iq = result[1].xmlnode - self.assertTrue(jcl.tests.is_xml_equal(\ - u"" - + "" + Lang.en.mail_subject % ("from1@test.com") - + "" - + "mail body 1" - + "" - + "
" - + "" - + "", - result_iq, True, test_sibling=False)) + self.check_email_message(result_iq, 1) def test_execute_get_emails(self): """ @@ -324,7 +331,7 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase): session_id = self.check_step_1(result) # Second step - info_query = self.prepare_submit(\ + info_query = jcl.jabber.tests.command.prepare_submit(\ node="jmc#get-email", session_id=session_id, from_jid="test1@test.com", @@ -355,31 +362,83 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase): + "", result_iq, True, test_sibling=False)) result_iq = result[1].xmlnode - self.assertTrue(jcl.tests.is_xml_equal(\ - u"" - + "" + Lang.en.mail_subject % ("from1@test.com") - + "" - + "mail body 1" - + "" - + "
" - + "" - + "", - result_iq, True, test_sibling=False)) + self.check_email_message(result_iq, 1) 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="" \ + + "") + + # 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(\ - u"" - + "" + Lang.en.mail_subject % ("from2@test.com") - + "" - + "mail body 2" - + "" - + "
" - + "" - + "", + u"" + + "" + + "" + + "" + Lang.en.command_get_email + "" + + "" + Lang.en.command_get_email_2_description + % (4) + "" + + "", 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(): test_suite = unittest.TestSuite() diff --git a/src/jmc/jabber/tests/component.py b/src/jmc/jabber/tests/component.py index 564b75d..cfaa61a 100644 --- a/src/jmc/jabber/tests/component.py +++ b/src/jmc/jabber/tests/component.py @@ -141,6 +141,7 @@ class MockIMAPAccount(MockMailAccount, IMAPAccount): def _init(self, *args, **kw): IMAPAccount._init(self, *args, **kw) MockMailAccount._init(self) + self.get_mail_list_summary_called = False def ls_dir(self, imap_dir): if imap_dir == "": @@ -152,12 +153,17 @@ class MockIMAPAccount(MockMailAccount, IMAPAccount): return [] def get_mail_with_attachment_list(self): - return [("1", "mail 1"), - ("2", "mail 2")] + return [("1", "mail 1"), + ("2", "mail 2")] def get_mail_list_summary(self): - return [("1", "mail 1"), - ("2", "mail 2")] + if self.get_mail_list_summary_called: + 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): diff --git a/src/jmc/lang.py b/src/jmc/lang.py index 35851f0..1944e24 100644 --- a/src/jmc/lang.py +++ b/src/jmc/lang.py @@ -90,7 +90,7 @@ class Lang(jcl.lang.Lang): command_get_email = "Fetch emails" 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_select_more_emails = u"Select more emails to fetch" 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_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_select_more_emails = u"Séléctionner plus d'emails à récupérer" mail_subject = u"Email de %s"