Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91835224
external_authentication_cern_unit_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
Thu, Nov 14, 23:47
Size
2 KB
Mime Type
text/x-python
Expires
Sat, Nov 16, 23:47 (2 d)
Engine
blob
Format
Raw Data
Handle
22330720
Attached To
R3600 invenio-infoscience
external_authentication_cern_unit_tests.py
View Options
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2007, 2008, 2010, 2011 CERN.
##
## 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.
##
## 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""Unit tests for the user handling library."""
__revision__
=
"$Id$"
import
unittest
from
invenio.config
import
CFG_CERN_SITE
from
invenio.testutils
import
make_test_suite
,
run_test_suite
class
ExternalAuthenticationCernTest
(
unittest
.
TestCase
):
"""Test functions related to the CERN authentication."""
def
setUp
(
self
):
# pylint: disable=C0103
"""setting up helper variables for tests"""
from
invenio
import
external_authentication_cern
as
cern
self
.
username
,
self
.
userpwd
,
self
.
useremail
=
\
open
(
'demopwd.cfg'
,
'r'
)
.
readline
()
.
strip
()
.
split
(
':'
,
2
)
self
.
cern
=
cern
.
ExternalAuthCern
()
def
test_auth_user_ok
(
self
):
"""external authentication CERN - authorizing user through CERN system: should pass"""
self
.
assertEqual
(
self
.
cern
.
auth_user
(
self
.
username
,
self
.
userpwd
),
\
self
.
useremail
)
def
test_auth_user_fail
(
self
):
"""external authentication CERN - authorizing user through CERN system: should fail"""
self
.
assertEqual
(
self
.
cern
.
auth_user
(
'patata'
,
'patata'
),
None
)
def
test_fetch_user_groups_membership
(
self
):
"""external authentication CERN - fetching user group membership at CERN"""
self
.
assertNotEqual
(
self
.
cern
.
fetch_user_groups_membership
(
self
.
useremail
,
self
.
userpwd
),
0
)
self
.
assertEqual
(
self
.
cern
.
fetch_user_groups_membership
(
'patata'
,
'patata'
),
{})
def
test_fetch_user_preferences
(
self
):
"""external authentication CERN - fetching user setting from CERN"""
self
.
assertEqual
(
self
.
cern
.
fetch_user_preferences
(
self
.
username
,
self
.
userpwd
)[
'email'
],
self
.
useremail
)
#self.assertRaises(KeyError, self.cern.fetch_user_preferences('patata', 'patata')['email'])
if
CFG_CERN_SITE
:
TEST_SUITE
=
make_test_suite
(
ExternalAuthenticationCernTest
,)
else
:
TEST_SUITE
=
make_test_suite
()
if
__name__
==
"__main__"
:
run_test_suite
(
TEST_SUITE
)
Event Timeline
Log In to Comment