diff --git a/modules/webmessage/lib/Makefile.am b/modules/webmessage/lib/Makefile.am index 5ad9e8fa5..3c0596c55 100644 --- a/modules/webmessage/lib/Makefile.am +++ b/modules/webmessage/lib/Makefile.am @@ -1,30 +1,31 @@ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. pylibdir = $(libdir)/python/invenio pylib_DATA = webmessage.py \ webmessage_templates.py \ webmessage_config.py \ webmessage_dblayer.py \ webmessage_mailutils.py \ webmessage_webinterface.py \ - webmessage_regression_tests.py + webmessage_regression_tests.py \ + webmessage_tests.py EXTRA_DIST = $(pylib_DATA) CLEANFILES = *~ *.tmp *.pyc diff --git a/modules/webmessage/lib/webmessage_regression_tests.py b/modules/webmessage/lib/webmessage_regression_tests.py index b8db3bb0b..1aedf82ad 100644 --- a/modules/webmessage/lib/webmessage_regression_tests.py +++ b/modules/webmessage/lib/webmessage_regression_tests.py @@ -1,51 +1,316 @@ # -*- coding: utf-8 -*- ## ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """WebMessage Regression Test Suite.""" __revision__ = "$Id$" import unittest from invenio.config import CFG_SITE_URL from invenio.testutils import make_test_suite, run_test_suite, \ test_web_page_content, merge_error_messages +from invenio import webmessage +from invenio.config import CFG_SITE_LANG +from invenio.webmessage_dblayer import CFG_WEBMESSAGE_STATUS_CODE, \ + check_quota, \ + count_nb_messages, \ + create_message, \ + datetext_default, \ + delete_all_messages, \ + delete_message_from_user_inbox, \ + get_all_messages_for_user, \ + get_gids_from_groupnames, \ + get_groupnames_like, \ + get_nb_new_messages_for_user, \ + get_groupnames_like, \ + get_nb_new_messages_for_user, \ + get_nb_readable_messages_for_user, \ + get_nicknames_like, \ + get_nicks_from_uids, \ + get_uids_from_emails, \ + get_uids_from_nicks, \ + get_uids_members_of_groups, \ + send_message, \ + set_message_status, \ + user_exists class WebMessageWebPagesAvailabilityTest(unittest.TestCase): """Check WebMessage web pages whether they are up or not.""" - def test_your_baskets_pages_availability(self): + def test_your_message_pages_availability(self): """webmessage - availability of Your Messages pages""" baseurl = CFG_SITE_URL + '/yourmessages/' _exports = ['', 'display', 'write', 'send', 'delete', 'delete_all', 'display_msg'] error_messages = [] for url in [baseurl + page for page in _exports]: error_messages.extend(test_web_page_content(url)) if error_messages: self.fail(merge_error_messages(error_messages)) return -TEST_SUITE = make_test_suite(WebMessageWebPagesAvailabilityTest) +class WebMessageSendingAndReceivingMessageTest(unittest.TestCase): + """Check sending and receiving message throught WebMessage""" + + def test_sending_message(self): + """webmessage - send and receive a message""" + # juliet writes the message to romeo + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + # it is verified that romeo received the message + result = get_all_messages_for_user(5) + self.assertEqual("Hi romeo", result[0][3]) + self.assertEqual("juliet", result[0][2]) + webmessage.perform_request_delete_msg(5, result[0][0], ln=CFG_SITE_LANG) + + def test_setting_message_status(self): + """webmessage - status from "new" to "read" """ + # juliet writes the message to romeo + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + msgid = get_all_messages_for_user(5)[0][0] + # status is changed + set_message_status(5, msgid, 'R') + msgstatus = get_all_messages_for_user(5)[0][5] + self.assertEqual(msgstatus, 'R') + webmessage.perform_request_delete_msg(5, msgid, ln=CFG_SITE_LANG) + + def test_getting_nb_new_msg(self): + """webmessage - count the nb of new message""" + delete_all_messages(5) + # juliet writes the message to romeo + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + self.assertEqual(get_nb_new_messages_for_user(5), 1) + + def test_getting_nb_readable_messages(self): + """webmessage - get the nb of readable messages""" + delete_all_messages(5) + # juliet writes the message to romeo + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + msgid = get_all_messages_for_user(5)[0][0] + # status is changed + set_message_status(5, msgid, 'R') + self.assertEqual(get_nb_readable_messages_for_user(5), 1) + webmessage.perform_request_delete_msg(5, msgid, ln=CFG_SITE_LANG) + + def test_getting_all_messages_for_user(self): + """webmessage - get all message for user""" + delete_all_messages(5) + # juliet writes 3 messages to romeo + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + self.assertEqual(len(get_all_messages_for_user(5)), 3) + delete_all_messages(5) + + def test_count_nb_message(self): + """webmessage - count the number of messages""" + delete_all_messages(5) + # juliet writes 3 messages to romeo + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + self.assertEqual(count_nb_messages(5), 3) + delete_all_messages(5) + self.assertEqual(count_nb_messages(5), 0) + + + def test_delete_message_from_user_inbox(self): + """webmessage - delete message from user inbox""" + delete_all_messages(5) + # juliet writes a message to romeo + webmessage.perform_request_send(6, + msg_to_user="romeo", + msg_to_group="", + msg_subject="Hi romeo", + msg_body="hello romeo how are you?", + ln=CFG_SITE_LANG) + msg_id = get_all_messages_for_user(5)[0][0] + delete_message_from_user_inbox(5, msg_id) + self.assertEqual(count_nb_messages(5), 0) + + def test_create_message(self): + """webmessage - create msg but do not send it""" + msgid = create_message(6, + users_to_str="romeo", + groups_to_str="montague-family", + msg_subject="hello", + msg_body="how are you", + msg_send_on_date=datetext_default) + send_message(5, msgid, status=CFG_WEBMESSAGE_STATUS_CODE['NEW']) + result = get_all_messages_for_user(5) + self.assertEqual(msgid, result[0][0] ) + delete_all_messages(2) + + def test_send_message(self): + """webmessage - sending message using uid msgid""" + #create a message to know the msgid + msgid = create_message(6, + users_to_str="romeo", + groups_to_str="montague-family", + msg_subject="hello", + msg_body="how are you", + msg_send_on_date=datetext_default) + send_message(5, msgid, status=CFG_WEBMESSAGE_STATUS_CODE['NEW']) + result = get_all_messages_for_user(5) + self.assertEqual("hello", result[0][3]) + webmessage.perform_request_delete_msg(5, result[0][0], ln=CFG_SITE_LANG) + + def test_check_quota(self): + """webmessage - you give a quota, it returns users over-quota""" + webmessage.perform_request_send(6, + msg_to_user="jekyll", + msg_to_group="", + msg_subject="Hi jekyll", + msg_body="hello how are you?", + ln=CFG_SITE_LANG) + webmessage.perform_request_send(6, + msg_to_user="jekyll", + msg_to_group="", + msg_subject="Hi jekyll", + msg_body="hello how are you?", + ln=CFG_SITE_LANG) + webmessage.perform_request_send(6, + msg_to_user="jekyll", + msg_to_group="", + msg_subject="Hi jekyll", + msg_body="hello how are you?", + ln=CFG_SITE_LANG) + webmessage.perform_request_send(6, + msg_to_user="jekyll", + msg_to_group="", + msg_subject="Hi jekyll", + msg_body="hello how are you?", + ln=CFG_SITE_LANG) + d = check_quota(3) + self.assertEqual(d.keys()[0], 2) + delete_all_messages(2) + + +class WebMessageGettingUidsGidsTest(unittest.TestCase): + """Many way to get uids or gids""" + + def test_get_uids_from_nicks(self): + """webmessage - get uid from nick""" + d = get_uids_from_nicks('juliet') + self.assertEqual(d.get('juliet'), 6) + + def test_get_nicks_from_uids(self): + """webmessage - get nick from uid""" + d = get_nicks_from_uids(6) + self.assertEqual(d.get(6), 'juliet') + + def test_get_uids_from_emails(self): + """webmessage - get uid from email""" + d = get_uids_from_emails('juliet.capulet@cds.cern.ch') + self.assertEqual(d.get('juliet.capulet@cds.cern.ch'), 6) + + def test_get_gids_from_groupnames(self): + """webmessage - get gid from groupname""" + d = get_gids_from_groupnames('montague-family') + self.assertEqual(d.get('montague-family'), 2) + + def test_get_uids_members_of_groups(self): + """webmessage - get uids members of group""" + uids = get_uids_members_of_groups(2) + self.assertEqual(uids[0], 5) + self.assertEqual(uids[1], 6) + self.assertEqual(uids[2], 7) + + def test_user_exists(self): + """webmessage - check if a user exist""" + self.assertEqual(user_exists(6), 1) + +class WebMessagePatternTest(unittest.TestCase): + """pattern""" + + def test_get_nicknames_like(self): + """webmessage - get nickname""" + result = get_nicknames_like('j.') + self.assertEqual(result[0], ('jekyll',)) + self.assertEqual(result[1], ('juliet',)) + result = get_nicknames_like('j+') + self.assertEqual(result[0], ('jekyll',)) + self.assertEqual(result[1], ('juliet',)) + + def test_get_groupnames_like(self): + """webmessage - get groupname""" + d = get_groupnames_like(5,'mont+') + self.assertEqual(d.keys()[0], 2L) + self.assertEqual(d.values()[0], 'montague-family') + +TEST_SUITE = make_test_suite(WebMessageWebPagesAvailabilityTest, + WebMessageSendingAndReceivingMessageTest, + WebMessageGettingUidsGidsTest, + WebMessagePatternTest) if __name__ == "__main__": run_test_suite(TEST_SUITE, warn_user=True) diff --git a/modules/webmessage/lib/webmessage_tests.py b/modules/webmessage/lib/webmessage_tests.py new file mode 100644 index 000000000..96e37eca0 --- /dev/null +++ b/modules/webmessage/lib/webmessage_tests.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +## +## This file is part of CDS Invenio. +## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. +## +## CDS Invenio is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation; either version 2 of the +## License, or (at your option) any later version. +## +## CDS Invenio is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., +## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + +"""Unit tests for WebMessage.""" + +__revision__ = \ + "$Id$" + +import unittest + +from invenio import webmessage_mailutils +from invenio.testutils import make_test_suite, run_test_suite + +class TestQuotingMessage(unittest.TestCase): + """Test for quoting messages.""" + + def test_simple_quoting(self): + """webmessage - test quoting simple message""" + text = """Dear romeo +I received your mail +>>Would you like to come with me to the restaurant? +Of course! +>>>>When could we get together? +Reply to my question please. + see you...""" + expected_text = """Dear romeo
+I received your mail
+
+\tWould you like to come with me to the restaurant?
+
+Of course!
+
+\t
+\t\tWhen could we get together?
+\t
+
+Reply to my question please.
+ see you...
+""" + res = webmessage_mailutils.email_quoted_txt2html(text, + tabs_before=0, + indent_txt='>>', + linebreak_txt="\n", + indent_html=('
', "
"), + linebreak_html='
') + self.assertEqual(res, expected_text) + + def test_quoting_message(self): + """webmessage - test quoting message""" + text = """C'est un lapin, lapin de bois. +>>Quoi? +Un cadeau. +>>What? +A present. +>>Oh, un cadeau""" + + expected_text = """>>C'est un lapin, lapin de bois. +>>>>Quoi? +>>Un cadeau. +>>>>What? +>>A present. +>>>>Oh, un cadeau +""" + + res = webmessage_mailutils.email_quote_txt(text, + indent_txt='>>', + linebreak_input="\n", + linebreak_output="\n") + self.assertEqual(res, expected_text) + + def test_indenting_rule_message(self): + """webmessage - return email-like indenting rule""" + text = """>>Brave Sir Robin ran away... +*No!* +>>bravely ran away away... +I didn't!* +>>When danger reared its ugly head, he bravely turned his tail and fled. +
*I never did!* +""" + expected_text = """>>Brave Sir Robin ran away... +<img src="malicious_script" />*No!* +>>bravely ran away away... +I didn't!*<script>malicious code</script> +>>When danger reared its ugly head, he bravely turned his tail and fled. +<form onload="malicious"></form>*I never did!* +""" + + res = webmessage_mailutils.escape_email_quoted_text(text, + indent_txt='>>', + linebreak_txt='\n') + self.assertEqual(res, expected_text) + + +TEST_SUITE = make_test_suite(TestQuotingMessage) + +if __name__ == "__main__": + run_test_suite(TEST_SUITE) diff --git a/modules/webmessage/web/Makefile.am b/modules/webmessage/web/Makefile.am index c27c79170..5c1a8b0f2 100644 --- a/modules/webmessage/web/Makefile.am +++ b/modules/webmessage/web/Makefile.am @@ -1,17 +1,27 @@ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. +## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +testdir = $(libdir)/webtest/invenio + +test_DATA = test_message_deleteall.html \ + test_message_send.html \ + test_message_sendlater.html \ + test_message_reply.html + +EXTRA_DIST = $(test_DATA) + +CLEANFILES = *~ *.tmp diff --git a/modules/webmessage/web/test_message_deleteall.html b/modules/webmessage/web/test_message_deleteall.html new file mode 100644 index 000000000..3191a5f77 --- /dev/null +++ b/modules/webmessage/web/test_message_deleteall.html @@ -0,0 +1,142 @@ + + + + + + +test_message_deleteall + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
test_message_deleteall
openhttp://localhost
clickAndWaitlink=login
typep_unromeo
typep_pwr123omeo
clickAndWaitaction
clickAndWaitlink=messages
clickAndWaitdel_all
typemsg_to_userjuliet
typemsg_subjectDear juliet
clickAndWaitsend_button
clickAndWaitdel_all
typemsg_to_userjuliet
typemsg_subjectDear juliet 2
clickAndWaitsend_button
clickAndWaitlink=logout
clickAndWaitlink=login here
typep_unjuliet
typep_pwj123uliet
clickAndWaitaction
clickAndWaitlink=messages
clickAndWait//input[@name='del_all' and @value='Delete All']
clickAndWait//input[@value='Yes']
verifyTextPresentNo messages
clickAndWaitlink=logout
+ + diff --git a/modules/webmessage/web/test_message_reply.html b/modules/webmessage/web/test_message_reply.html new file mode 100644 index 000000000..e741d68e1 --- /dev/null +++ b/modules/webmessage/web/test_message_reply.html @@ -0,0 +1,187 @@ + + + + + + +test_message_sendreply + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
test_message_sendreply
openhttp://localhost
clickAndWaitlink=login
typep_unromeo
typep_pwr123omeo
clickAndWaitaction
clickAndWaitlink=messages
clickAndWaitdel_all
typesearch_patternjuliet
clickAndWaitsearch_user
addSelectionnames_selectedlabel=juliet
clickAndWaitadd_user
verifyValuemsg_to_userjuliet
typemsg_subjectdear Juliet
typemsg_bodyI love you
clickAndWaitsend_button
clickAndWaitlink=logout
clickAndWaitlink=login
typep_unjuliet
typep_pwj123uliet
clickAndWaitaction
clickAndWaitlink=messages
clickAndWaitlink=Reply
typemsg_body>>I love you

me too
clickAndWaitsend_button
clickAndWaitlink=logout
clickAndWaitlink=login here
typep_unromeo
typep_pwr123omeo
clickAndWaitaction
clickAndWaitlink=messages
clickAndWaitlink=exact:Re: dear Juliet
clickAndWaitdelete
clickAndWaitlink=logout
+ + diff --git a/modules/webmessage/web/test_message_send.html b/modules/webmessage/web/test_message_send.html new file mode 100644 index 000000000..51f726610 --- /dev/null +++ b/modules/webmessage/web/test_message_send.html @@ -0,0 +1,141 @@ + + + + + + +test_message_send_ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
test_message_send
openhttp://localhost
clickAndWaitlink=login
typep_unromeo
typep_pwr123omeo
clickAndWaitaction
clickAndWaitlink=messages
clickAndWaitdel_all
typesearch_patternjuliet
clickAndWaitsearch_user
addSelectionnames_selectedlabel=juliet
clickAndWaitadd_user
verifyValuemsg_to_userjuliet
typemsg_subjectdear Juliet
typemsg_bodyI love you
clickAndWaitsend_button
clickAndWaitlink=logout
clickAndWaitlink=login
typep_unjuliet
typep_pwj123uliet
clickAndWaitaction
clickAndWaitlink=messages
clickAndWaitlink=dear Juliet
clickAndWaitdelete
clickAndWaitlink=logout
+ + diff --git a/modules/webmessage/web/test_message_sendlater.html b/modules/webmessage/web/test_message_sendlater.html new file mode 100644 index 000000000..aa5a3834f --- /dev/null +++ b/modules/webmessage/web/test_message_sendlater.html @@ -0,0 +1,112 @@ + + + + + + +test_message_sendlater + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
test_message_sendlater
openhttp://localhost
clickAndWaitlink=login
typep_unromeo
typep_pwr123omeo
clickAndWaitaction
clickAndWaitlink=messages
clickAndWaitdel_all
typemsg_to_userjuliet
typemsg_subjectdear juliet
typemsg_bodyi love you
selectmsg_send_daylabel=4
selectmsg_send_monthlabel=July
clickAndWaitsend_button
verifyTextPresentThe chosen date (0/7/4) is invalid.
selectmsg_send_yearlabel=2009
clickAndWaitsend_button
verifyTextPresentYour message has been sent.
clickAndWaitlink=logout
+ +