Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92196481
webmessage_regression_tests.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 18, 05:27
Size
13 KB
Mime Type
text/x-python
Expires
Wed, Nov 20, 05:27 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
22391720
Attached To
R3600 invenio-infoscience
webmessage_regression_tests.py
View Options
# -*- 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_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
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
)
Event Timeline
Log In to Comment