diff options
author | David Rousselie <dax@happycoders.org> | 2008-03-06 19:55:14 +0300 |
---|---|---|
committer | David Rousselie <dax@happycoders.org> | 2008-03-06 19:55:14 +0300 |
commit | 392169732f1d50e3be968f1d2038b5411f7590b5 (patch) | |
tree | 0abdd6a6eefb0260894a1dc82ac3eb355d257202 | |
parent | 20ddfe0db3ac246b6a27c924551dab4f7b253dfd (diff) |
Multi-pages support when selecting email to fetch in get-email ad-hoc command
darcs-hash:20080306165514-86b55-9c737d38047aef3a716974f343fd192a259c7f9f.gz
-rw-r--r-- | src/jmc/jabber/tests/command.py | 143 | ||||
-rw-r--r-- | src/jmc/jabber/tests/component.py | 14 | ||||
-rw-r--r-- | src/jmc/lang.py | 4 |
3 files changed, 113 insertions, 48 deletions
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="<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 """ @@ -242,10 +246,7 @@ class MailCommandManagerGetEmailCommand_TestCase(MailCommandManagerTestCase): + "</instructions>" + "<field var='emails' type='list-multi' label='" + Lang.en.field_email_subject + "'>" - + "<option label=\"mail 1\">" - + "<value>1</value></option>" - + "<option label=\"mail 2\">" - + "<value>2</value></option>" + + options + "</field><field var='fetch_more' type='boolean' label='" + Lang.en.field_select_more_emails + "'>" + "</field></x></command></iq>", @@ -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"<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): """ 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): + "</x></command></iq>", result_iq, True, test_sibling=False)) result_iq = result[1].xmlnode - 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 % ("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)) + 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): + "</x></command></iq>", result_iq, True, test_sibling=False)) result_iq = result[1].xmlnode - 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 % ("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)) + 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="<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(\ - u"<message from='account11@" + unicode(self.comp.jid) - + "' to='test1@test.com' " - + "xmlns='http://pyxmpp.jabberstudio.org/xmlns/common'>" - + "<subject>" + Lang.en.mail_subject % ("from2@test.com") - + "</subject>" - + "<body>mail body 2</body>" - + "<addresses xmlns='http://jabber.org/protocol/address'>" - + "<address type='replyto' jid='from2%test.com@jmc.test.com'/>" - + "</addresses>" - + "</message>", + u"<iq from='account11@" + unicode(self.comp.jid) + + "' to='test1@test.com' type='result'>" + + "<command xmlns='http://jabber.org/protocol/commands' " + + "status='completed'>" + + "<x xmlns='jabber:x:data' type='form'>" + + "<title>" + Lang.en.command_get_email + "</title>" + + "<instructions>" + Lang.en.command_get_email_2_description + % (4) + "</instructions>" + + "</x></command></iq>", 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" |